Documentation
¶
Overview ¶
Package container provides dependency injection for Typosentinel This package implements a service container for managing dependencies and their lifecycle
Index ¶
- type Container
- func (c *Container) AddFinalizer(name string, finalizer func(interface{}) error) error
- func (c *Container) AddInitializer(name string, initializer func(interface{}) error) error
- func (c *Container) AddTag(name string, tag string) error
- func (c *Container) ClearScope(scope string) error
- func (c *Container) Get(name string) (interface{}, error)
- func (c *Container) GetByTag(tag string) ([]interface{}, error)
- func (c *Container) GetByType(serviceType reflect.Type) (interface{}, error)
- func (c *Container) GetScoped(name string, scope string) (interface{}, error)
- func (c *Container) GetServiceInfo(name string) (*ServiceDefinition, error)
- func (c *Container) Initialize(ctx context.Context) error
- func (c *Container) IsShutdown() bool
- func (c *Container) ListServices() []string
- func (c *Container) Register(name string, factory interface{}, lifecycle ServiceLifecycle) error
- func (c *Container) RegisterInstance(name string, instance interface{}) error
- func (c *Container) RegisterScoped(name string, factory interface{}) error
- func (c *Container) RegisterSingleton(name string, factory interface{}) error
- func (c *Container) RegisterTransient(name string, factory interface{}) error
- func (c *Container) SetLogger(logger interfaces.Logger)
- func (c *Container) SetMetrics(metrics interfaces.Metrics)
- func (c *Container) Shutdown(ctx context.Context) error
- type ServiceDefinition
- type ServiceLifecycle
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
}
Container manages service dependencies and their lifecycle
func NewContainer ¶
func NewContainer() *Container
NewContainer creates a new dependency injection container
func (*Container) AddFinalizer ¶
AddFinalizer adds a finalizer function for a service
func (*Container) AddInitializer ¶
AddInitializer adds an initializer function for a service
func (*Container) ClearScope ¶
ClearScope clears all scoped instances for a specific scope
func (*Container) GetServiceInfo ¶
func (c *Container) GetServiceInfo(name string) (*ServiceDefinition, error)
GetServiceInfo returns information about a service
func (*Container) Initialize ¶
Initialize initializes the container and validates dependencies
func (*Container) IsShutdown ¶
IsShutdown returns true if the container has been shut down
func (*Container) ListServices ¶
ListServices returns a list of all registered services
func (*Container) Register ¶
func (c *Container) Register(name string, factory interface{}, lifecycle ServiceLifecycle) error
Register registers a service with the container
func (*Container) RegisterInstance ¶
RegisterInstance registers a pre-created instance as a singleton
func (*Container) RegisterScoped ¶
RegisterScoped registers a scoped service
func (*Container) RegisterSingleton ¶
RegisterSingleton registers a singleton service
func (*Container) RegisterTransient ¶
RegisterTransient registers a transient service
func (*Container) SetLogger ¶
func (c *Container) SetLogger(logger interfaces.Logger)
SetLogger sets the logger for the container
func (*Container) SetMetrics ¶
func (c *Container) SetMetrics(metrics interfaces.Metrics)
SetMetrics sets the metrics collector for the container
type ServiceDefinition ¶
type ServiceDefinition struct {
Name string
Type reflect.Type
Factory interface{}
Lifecycle ServiceLifecycle
Dependencies []string
Tags []string
Initializer func(interface{}) error
Finalizer func(interface{}) error
}
ServiceDefinition defines how a service should be created
type ServiceLifecycle ¶
type ServiceLifecycle string
ServiceLifecycle represents the lifecycle of a service
const ( // Singleton services are created once and reused LifecycleSingleton ServiceLifecycle = "singleton" // Transient services are created on each request LifecycleTransient ServiceLifecycle = "transient" // Scoped services are created once per scope (e.g., per request) LifecycleScoped ServiceLifecycle = "scoped" )