(structPtr interface{}, c *Container, partyParamsCount int)
| 56 | } |
| 57 | |
| 58 | func makeStruct(structPtr interface{}, c *Container, partyParamsCount int) *Struct { |
| 59 | v := valueOf(structPtr) |
| 60 | typ := v.Type() |
| 61 | if typ.Kind() != reflect.Ptr || indirectType(typ).Kind() != reflect.Struct { |
| 62 | panic("binder: struct: should be a pointer to a struct value") |
| 63 | } |
| 64 | |
| 65 | isSingleton := isMarkedAsSingleton(structPtr) |
| 66 | |
| 67 | disablePayloadAutoBinding := c.DisablePayloadAutoBinding |
| 68 | enableStructDependents := c.EnableStructDependents |
| 69 | disableStructDynamicBindings := c.DisableStructDynamicBindings |
| 70 | if isSingleton { |
| 71 | disablePayloadAutoBinding = true |
| 72 | enableStructDependents = false |
| 73 | disableStructDynamicBindings = true |
| 74 | } |
| 75 | |
| 76 | // get struct's fields bindings. |
| 77 | bindings := getBindingsForStruct(v, c.Dependencies, c.MarkExportedFieldsAsRequired, disablePayloadAutoBinding, enableStructDependents, c.DependencyMatcher, partyParamsCount, c.Sorter) |
| 78 | |
| 79 | // length bindings of 0, means that it has no fields or all mapped deps are static. |
| 80 | // If static then Struct.Acquire will return the same "value" instance, otherwise it will create a new one. |
| 81 | singleton := true |
| 82 | elem := v.Elem() |
| 83 | |
| 84 | // fmt.Printf("Service: %s, Bindings(%d):\n", typ, len(bindings)) |
| 85 | for _, b := range bindings { |
| 86 | // fmt.Printf("* " + b.String() + "\n") |
| 87 | if b.Dependency.Static { |
| 88 | // Fill now. |
| 89 | input, err := b.Dependency.Handle(nil, b.Input) |
| 90 | if err != nil { |
| 91 | if err == ErrSeeOther { |
| 92 | continue |
| 93 | } |
| 94 | |
| 95 | panic(err) |
| 96 | } |
| 97 | |
| 98 | elem.FieldByIndex(b.Input.StructFieldIndex).Set(input) |
| 99 | } else if !b.Dependency.Static { |
| 100 | if disableStructDynamicBindings { |
| 101 | panic(fmt.Sprintf("binder: DisableStructDynamicBindings setting is set to true: dynamic binding found: %s", b.String())) |
| 102 | } |
| 103 | |
| 104 | singleton = false |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if isSingleton && !singleton { |
| 109 | panic(fmt.Sprintf("binder: Singleton setting is set to true but struct has dynamic bindings: %s", typ)) |
| 110 | } |
| 111 | |
| 112 | s := &Struct{ |
| 113 | ptrValue: v, |
| 114 | ptrType: typ, |
| 115 | elementType: elem.Type(), |
no test coverage detected
searching dependent graphs…