Documentation
¶
Index ¶
- type Container
- func (c *Container) Graph() Graph
- func (c *Container) GraphDOT() string
- func (c *Container) GraphDOTModules() map[string]string
- func (c *Container) GraphModules() map[string]Graph
- func (c *Container) Invoke(consumer any) error
- func (c *Container) Provide(deps Dependencies) error
- func (c *Container) Runnables() ([]Runnable, error)
- func (c *Container) Validate() error
- type ContainerOption
- type Dependencies
- type Dependency
- type DependencyOption
- type Graph
- type GraphToken
- type Hook
- type Lifecycle
- type Matching
- type Module
- type Optional
- type OverrideInfo
- type ProviderEdge
- type ProviderInfo
- type ProviderNode
- type Runnable
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 wraps dig.Container with a tiny convenience layer.
func NewContainer ¶
func NewContainer(opts ...ContainerOption) (*Container, error)
func (*Container) Graph ¶
Graph builds a dependency graph for the container root scope (resolved providers only).
func (*Container) GraphDOTModules ¶
GraphDOTModules returns DOT graphs for the root and each module scope.
func (*Container) GraphModules ¶
GraphModules builds dependency graphs for the root and each module scope. Module graphs include the root providers plus module-private providers.
func (*Container) Provide ¶
func (c *Container) Provide(deps Dependencies) error
Provide appends dependencies to the container.
type ContainerOption ¶
type ContainerOption func(c *containerConfig)
func WithDefaultLifecycle ¶
func WithDefaultLifecycle() ContainerOption
WithDefaultLifecycle registers a default Lifecycle in the container.
func WithDependencies ¶
func WithDependencies(d ...Dependencies) ContainerOption
WithDependencies adds dependencies to the container.
func WithMatchings ¶
func WithMatchings(matchings ...any) ContainerOption
WithMatchings applies dig.As mappings automatically for provided dependencies. Accepts pointers to interfaces or Matching instances.
func WithModules ¶
func WithModules(modules ...Module) ContainerOption
WithModules registers module dependencies with optional privacy.
type Dependencies ¶
type Dependencies struct {
// contains filtered or unexported fields
}
func CollectDependencies ¶
func CollectDependencies(deps ...Dependency) Dependencies
func NewSingleDependency ¶
func NewSingleDependency(constructor any, opts ...DependencyOption) Dependencies
func (Dependencies) List ¶
func (d Dependencies) List() []Dependency
type Dependency ¶
type Dependency struct {
// contains filtered or unexported fields
}
func Decorate ¶
func Decorate(constructor any, opts ...DependencyOption) Dependency
Decorate declares a decorator for an existing dependency slot.
func NewDependency ¶
func NewDependency(constructor any, opts ...DependencyOption) Dependency
func Replace ¶
func Replace(constructor any, opts ...DependencyOption) Dependency
Replace declares an explicit replacement for a dependency slot.
func (*Dependency) AddMatchingInterface ¶
func (d *Dependency) AddMatchingInterface(as ...any) error
func (*Dependency) Error ¶
func (d *Dependency) Error() error
func (*Dependency) ExposedTypes ¶
func (d *Dependency) ExposedTypes() []reflect.Type
ExposedTypes returns the types this dependency is exposed as in the container. When matching interfaces are provided (dig.As), only those interfaces are exposed.
func (*Dependency) IsRunnable ¶
func (d *Dependency) IsRunnable() bool
func (*Dependency) Type ¶
func (d *Dependency) Type() reflect.Type
type DependencyOption ¶
type DependencyOption func(*Dependency)
func Private ¶
func Private() DependencyOption
Private marks a dependency as private to its module scope.
func WithGroup ¶
func WithGroup(group string) DependencyOption
WithGroup adds dependency to dig group.
func WithKey ¶
func WithKey(key string) DependencyOption
WithKey attaches a metadata key for diagnostics (no effect on resolution).
func WithMatch ¶
func WithMatch(a any) DependencyOption
WithMatch maps dependency to interface (dig.As).
func WithName ¶
func WithName(name string) DependencyOption
WithName provides dependency under a named key (dig.Name).
type Graph ¶
type Graph struct {
Providers []ProviderNode
Edges []ProviderEdge
}
func BuildGraph ¶
func BuildGraph(deps Dependencies) Graph
BuildGraph builds a dependency graph for the provided dependencies (resolved providers only).
func (Graph) ProviderIDs ¶
type GraphToken ¶
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle manages start/stop hooks in order (start) and reverse order (stop).
func NewLifecycle ¶
func NewLifecycle() *Lifecycle
type Matching ¶
type Matching struct {
// contains filtered or unexported fields
}
func NewMatching ¶
NewMatching matches concrete type to interfaces (dig.As).
type Module ¶
type Module struct {
Name string
Dependencies Dependencies
}
Module groups dependencies and allows marking some as private to the module scope.
func NewModule ¶
func NewModule(name string, dependencies Dependencies) Module
type OverrideInfo ¶
type OverrideInfo struct {
Key string
Previous ProviderInfo
Next ProviderInfo
}
func DetectOverrides ¶
func DetectOverrides(deps Dependencies) []OverrideInfo
DetectOverrides reports explicit replacements (godi.Replace) by slot.