(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies []*Dependency)
| 186 | } |
| 187 | |
| 188 | func fromStructValueOrDependentStructValue(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies []*Dependency) bool { |
| 189 | if !isStructValue(v) { |
| 190 | // It's not just a static struct value. |
| 191 | return false |
| 192 | } |
| 193 | |
| 194 | if len(prevDependencies) == 0 || !dest.StructDependents { // As a non depedent struct. |
| 195 | // We must make this check so we can avoid the auto-filling of |
| 196 | // the dependencies from Iris builtin dependencies. |
| 197 | return fromStructValue(v, dest) |
| 198 | } |
| 199 | |
| 200 | // Check if it's a builtin dependency (e.g an MVC Application (see mvc.go#newApp)), |
| 201 | // if it's and registered without a Dependency wrapper, like the rest builtin dependencies, |
| 202 | // then do NOT try to resolve its fields. |
| 203 | // |
| 204 | // Although EnableStructDependents is false by default, we must check if it's a builtin dependency for any case. |
| 205 | if strings.HasPrefix(indirectType(v.Type()).PkgPath(), "github.com/kataras/iris/v12") { |
| 206 | return fromStructValue(v, dest) |
| 207 | } |
| 208 | |
| 209 | bindings := getBindingsForStruct(v, prevDependencies, false, disablePayloadAutoBinding, dest.StructDependents, DefaultDependencyMatcher, -1, nil) |
| 210 | if len(bindings) == 0 { |
| 211 | return fromStructValue(v, dest) // same as above. |
| 212 | } |
| 213 | |
| 214 | // As a depedent struct, however we may need to resolve its dependencies first |
| 215 | // so we can decide if it's really a depedent struct or not. |
| 216 | var ( |
| 217 | handler = func(*context.Context, *Input) (reflect.Value, error) { |
| 218 | return v, nil |
| 219 | } |
| 220 | isStatic = true |
| 221 | ) |
| 222 | |
| 223 | for _, binding := range bindings { |
| 224 | if !binding.Dependency.Static { |
| 225 | isStatic = false |
| 226 | break |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | handler = func(ctx *context.Context, _ *Input) (reflect.Value, error) { // Called once per dependency on build-time if the dependency is static. |
| 231 | elem := v |
| 232 | if elem.Kind() == reflect.Ptr { |
| 233 | elem = elem.Elem() |
| 234 | } |
| 235 | |
| 236 | for _, binding := range bindings { |
| 237 | field := elem.FieldByIndex(binding.Input.StructFieldIndex) |
| 238 | if !field.CanSet() || !field.IsZero() { |
| 239 | continue // already set. |
| 240 | } |
| 241 | // if !binding.Dependency.Match(field.Type()) { A check already happen in getBindingsForStruct. |
| 242 | // continue |
| 243 | // } |
| 244 | |
| 245 | input, err := binding.Dependency.Handle(ctx, binding.Input) |
no test coverage detected
searching dependent graphs…