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 any, as any) any
- func Bind(from any, to any) any
- func IntoPopulator(container *dig.Container) contract.DIPopulator
- func LocationForPC(constructor any, pc uintptr) any
- func Name(constructor any, name string) any
- 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
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
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
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 []any
Deps is a set of providers grouped together. This is used by core.Provide method to identify provider sets.
type Factory ¶
type Factory[T any] struct { // contains filtered or unexported fields }
Factory is a concurrent safe, generic factory for connections to databases and external network services.
func NewFactory ¶
NewFactory creates a new factory. The constructor is a function that is called to create a new connection.
func (*Factory[T]) Close ¶
func (f *Factory[T]) Close()
Close reloads the factory, purging all cached connections.
type Modular ¶ added in v0.9.0
type Modular interface { // Module returns a core module Module() any }
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 any 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.