Documentation
¶
Index ¶
- type Constructor
- type Container
- func (c *Container) Bind(name string, constructor Constructor)
- func (c *Container) Has(name string) bool
- func (c *Container) Instance(name string, value any)
- func (c *Container) Make(name string) (any, error)
- func (c *Container) MustMake(name string) any
- func (c *Container) Singleton(name string, constructor Constructor)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Constructor ¶
type Constructor any
Constructor is a function that builds a value (lazy). Return T or (T, error).
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a simple IoC container: bind name → constructor, resolve with Make (AdonisJS/Laravel style). Supports auto-wiring: constructors whose parameters are interface or pointer types are resolved automatically from the container's type bindings.
func (*Container) Bind ¶
func (c *Container) Bind(name string, constructor Constructor)
Bind registers a constructor for name. Each Make(name) calls the constructor.
func (*Container) Instance ¶
Instance registers a pre-built value directly (no constructor). Subsequent Make calls return this exact value.
c.Instance("stripe", stripeClient)
func (*Container) Singleton ¶
func (c *Container) Singleton(name string, constructor Constructor)
Singleton registers a constructor that is invoked once; subsequent Make returns the same instance.
Click to show internal directories.
Click to hide internal directories.