Documentation ¶
Overview ¶
Package dig is the dig: Dependency Injection Framework for Go.
package dig provides an opinionated way of resolving object dependencies.
Index ¶
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
}
A Container is a directed, acyclic graph of dependencies. Dependencies are constructed on-demand and returned from a cache thereafter, so they're effectively singletons.
func (*Container) Invoke ¶
Invoke runs a function, supplying its arguments from the Container. If the function's last return value is an error, that error is propagated to the caller. All other returned values (if any) are ignored.
Passing anything other than a function to Invoke returns an error immediately.
func (*Container) Provide ¶
Provide teaches the Container how to construct one or more new types. It accepts either a constructor function or an already-constructed object.
Any function passed to Provide is assumed to be a constructor. Constructors can take any number of parameters, which will be supplied by the Container on demand. They must return at least one non-error value, all of which are then available in the Container. If the last returned value is an error, the Container inspects it to determine whether the constructor succeeded or failed. Regardless of position, returned errors are never put into the Container's dependency graph.
All non-functions (including structs, pointers, Go's built-in collections, and primitive types like ints) are inserted into the Container as-is.
type In ¶
type In struct{}
In is an embeddable object that signals to dig that the struct should be treated differently. Instead of itself becoming an object in the graph, memebers of the struct are inserted into the graph.
Tags on those memebers control their behavior. For example,
type Input struct { dig.In S *Something T *Thingy `optional:"true"` }