MCPcopy Create free account
hub / github.com/kataras/iris / Inject

Method Inject

hero/container.go:397–418  ·  view source on GitHub ↗

Inject SHOULD only be used outside of HTTP handlers (performance is not priority for this method) as it does not pre-calculate the available list of bindings for the "toPtr" and the registered dependencies. It sets a static-only matching dependency to the value of "toPtr". The parameter "toPtr" SHO

(toPtr interface{})

Source from the content-addressed store, hash-verified

395// var db Database
396// err := c.Inject(&db)
397func (c *Container) Inject(toPtr interface{}) error {
398 val := reflect.Indirect(valueOf(toPtr))
399 typ := val.Type()
400
401 for _, d := range c.Dependencies {
402 if d.Static && c.DependencyMatcher(d, typ) {
403 v, err := d.Handle(nil, &Input{Type: typ})
404 if err != nil {
405 if err == ErrSeeOther {
406 continue
407 }
408
409 return err
410 }
411
412 val.Set(v)
413 return nil
414 }
415 }
416
417 return ErrMissingDependency
418}

Callers 1

TestContainerInjectFunction · 0.80

Calls 4

TypeMethod · 0.80
valueOfFunction · 0.70
HandleMethod · 0.65
SetMethod · 0.65

Tested by 1

TestContainerInjectFunction · 0.64