Documentation
¶
Index ¶
- func MustMake[T any](c *Container, name string) T
- func TryMake[T any](c *Container, name string) (T, error)
- type Container
- func (c *Container) Bind(name string, factory Factory)
- func (c *Container) Has(name string) bool
- func (c *Container) Instance(name string, instance interface{})
- func (c *Container) Make(name string) interface{}
- func (c *Container) SafeSingleton(name string, factory Factory)
- func (c *Container) Singleton(name string, factory Factory)
- func (c *Container) TryMake(name string) (interface{}, error)
- type Factory
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is the service container for dependency injection.
func (*Container) Bind ¶
Bind registers a factory function for a service. Each Make() call invokes the factory and returns a new instance (transient).
func (*Container) Make ¶
Make resolves a service by name. Checks instances first, then bindings. Panics if the service is not registered.
func (*Container) SafeSingleton ¶ added in v2.7.2
SafeSingleton registers a singleton that catches panics during creation. If the factory panics and the app is in local/development mode, the panic is logged as a warning and the service is skipped (not registered). In production, the panic propagates normally.
type Factory ¶
type Factory func(c *Container) interface{}
Factory is a function that creates a service instance.
type Provider ¶
type Provider interface {
// Register binds services into the container.
// Called before the application boots. Only register bindings here.
Register(c *Container)
// Boot runs after ALL providers have been registered.
// May resolve other services from the container.
Boot(c *Container)
}
Provider defines the lifecycle hooks for service registration.