Documentation
¶
Index ¶
- type Container
- func (c *Container) Build() error
- func (c *Container) Get(t reflect.Type) (interface{}, error)
- func (c *Container) Invoke(invoker interface{}) error
- func (c *Container) Register(provider interface{}, lifetime Lifetime) error
- func (c *Container) Scoped() *Container
- func (c *Container) WithContext(key string, value interface{}) *Container
- type ContextParams
- type Lifetime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a DI container
func (*Container) Build ¶
Build checks dependency graph for cyclic dependencies, checks if all dependencies were registered and created singletons. Calling Build is required, otherwise Invoke and Get calls will return an error
func (*Container) Register ¶
Register teaches the container how to resolve dependencies: provider's out-parameter needs all of its inner parameters to be instantiated. If ContextParams type is passed as an argument, it will give access to container's context parameters.
func (*Container) WithContext ¶
WithContext returns container with added contextParams values without changing the original one. Context allows to change how dependencies are instantiated. Context values can be retrieved in provider functions:
err := c.Register(func(params di.ContextParams) *example { return newExample(params.GetValue("key").(string)) }, Transient)
type ContextParams ¶
type ContextParams map[string]interface{}
ContextParams represents container parameters
func (ContextParams) GetValue ¶
func (contextParams ContextParams) GetValue(key string) interface{}
GetValue returns value from context params