Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get[T any]() T
Get returns an instance of the type specified by the type parameter T. If an instance has already been created, it is returned from the cache. Otherwise, a new instance is created using the registered constructor function. The constructor function is called with its dependencies resolved using reflection.
func Init ¶
func Init()
Init initializes the dependencies and constructors maps. Init must be called before any other function in this package.
func Inject ¶
func Inject[T any]() T
Inject creates a new instance of the specified struct type with its fields injected with their respective dependencies. It returns the created instance.
func Provide ¶
Provide registers a constructor function that returns a value of type T. The constructor function is called immediately and the result is stored as a dependency. If T is an interface, the constructor function must return a value that implements T. If T is not an interface, the constructor function must return a value of type T. The constructor function must return at least one value. The constructor function must be a function. Provide is a shorthand for ProvideLazy followed by Get[T].
func ProvideLazy ¶
ProvideLazy registers a constructor function that returns a value of type T. The constructor function is not called until Get[T]() is called. If T is an interface, the constructor function must return a value that implements T. If T is not an interface, the constructor function must return a value of type T. The constructor function must return at least one value. The constructor function must be a function.
Types ¶
This section is empty.