Documentation ¶
Overview ¶
Package di is a thin wrapper around dig. See https://github.com/uber-go/dig
This package is not intended for direct usage. Only use it for libraries written for package core.
Index ¶
- func As(constructor interface{}, as interface{}) interface{}
- func Bind(from interface{}, to interface{}) interface{}
- func IntoPopulator(container *dig.Container) contract.DIPopulator
- func LocationForPC(constructor interface{}, pc uintptr) interface{}
- func Name(constructor interface{}, name string) interface{}
- type Deps
- type Factory
- type In
- type Modular
- type OptionalProvider
- type Out
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v0.10.0
func As(constructor interface{}, as interface{}) interface{}
As constructs the instance and bind it to another interface. As means to be used as an argument to graph.Provide. For example:
As(MyConstructor, new(MyAbstractInterface))
func Bind ¶ added in v0.9.0
func Bind(from interface{}, to interface{}) interface{}
Bind binds a type to another. Useful when binding implementation to interfaces. The arguments should be a ptr to the binding types, rather than the types themselves. For example:
Bind(new(MyConcreteStruct), new(MyAbstractInterface))
func IntoPopulator ¶ added in v0.9.0
func IntoPopulator(container *dig.Container) contract.DIPopulator
IntoPopulator converts a *dig.Container to contract.DIPopulator.
func LocationForPC ¶ added in v0.10.0
func LocationForPC(constructor interface{}, pc uintptr) interface{}
LocationForPC sets the constructor pointer to a specified location. Use this Options to reduce vague debug message when constructor are made by reflect.makeFunc. For example:
LocationForPC(reflect.makeFunc(...), reflect.ValueOf(realConstructor).Pointer())
Types ¶
type Deps ¶ added in v0.2.0
type Deps []interface{}
Deps is a set of providers grouped together. This is used by core.Provide method to identify provider sets.
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory is a concurrent safe, generic factory for databases and connections.
func NewFactory ¶
NewFactory creates a new factory.
func (*Factory) Close ¶
func (f *Factory) Close()
Close closes every connection created by the factory. Connections are closed concurrently.
func (*Factory) Make ¶
Make creates an instance under the provided name. It an instance is already created and it is not nil, that instance is returned to the caller.
func (*Factory) SubscribeReloadEventFrom ¶ added in v0.7.0
func (f *Factory) SubscribeReloadEventFrom(dispatcher contract.Dispatcher)
SubscribeReloadEventFrom subscribes to the reload events from dispatcher and then notifies the di factory to clear its cache and shutdown all connections gracefully.
type Modular ¶ added in v0.9.0
type Modular interface {
// Module returns a core module
Module() interface{}
}
Modular is a special interface. A type implements Modular to indicate it contains a valid core module. This property is examined and executed by the core.Provide in package core. Other than that, the interface bears no further meaning.
If the module is not a by-product of dependency construction via core.Provide, then there is no need to use this mechanism.
type OptionalProvider ¶ added in v0.10.0
type OptionalProvider struct { Constructor interface{} Options []dig.ProvideOption }
OptionalProvider is a struct with constructor and dig options. When OptionalProvider is used as the element in di.Deps, the options are applied to the inner dig.Container automatically.