Documentation
¶
Overview ¶
Package container provides a type-safe IoC dependency injection container.
A Container holds named bindings — factory functions that produce values on demand. Bindings are either transient (a fresh value per resolution) or singleton (a single value cached after the first successful resolution).
The zero value of Container is not usable; call New.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Make ¶
Make resolves a binding by name and type-asserts the result to T. Returns an error if the binding is missing, the factory fails, or the produced value is not assignable to T.
func Must ¶
Must resolves a binding by name and type-asserts the result to T. It panics if the binding is missing, the factory fails, or the type does not match. Prefer Make in code that needs to handle errors gracefully; Must is intended for startup paths where a missing dependency is fatal by definition.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is an IoC dependency injection container. It is safe for concurrent use.
func (*Container) Bind ¶
Bind registers a transient factory under name. Each call to Make invokes the factory again. If name is already bound, the previous binding is replaced.