Documentation
¶
Index ¶
- func IsDefaultRegisteredTyped[T any]() bool
- func IsRegistered(iface any) bool
- func IsRegisteredTyped[T any](c *Container) bool
- func MustResolve(iface any) any
- func MustResolveDefaultTyped[T any]() T
- func MustResolveTyped[T any](c *Container) T
- func ResetForTesting()
- func Resolve(iface any) (any, error)
- func ResolveDefaultTyped[T any]() (T, error)
- func ResolveTyped[T any](c *Container) (T, error)
- type Container
- func Clear() *Container
- func Default() *Container
- func New() *Container
- func NewWithOptions(opts ...Option) *Container
- func Register(iface any, factory func(*Container) (any, error), isSingleton bool) *Container
- func RegisterDefaultServices(services ...func(*Container) *Container) *Container
- func RegisterDefaultSingletonInstance[T any](instance T) *Container
- func RegisterInstance(iface any, instance any) *Container
- func RegisterSingleton(iface any, factory func(*Container) (any, error)) *Container
- func RegisterSingletonInstance[T any](c *Container, instance T) *Container
- func RegisterTransient(iface any, factory func(*Container) (any, error)) *Container
- func (c *Container) Clear() *Container
- func (c *Container) IsRegistered(iface any) bool
- func (c *Container) MustResolve(iface any) any
- func (c *Container) Register(iface any, factory func(*Container) (any, error), isSingleton bool) *Container
- func (c *Container) RegisterInstance(iface any, instance any) *Container
- func (c *Container) RegisterServices(services ...func(*Container) *Container) *Container
- func (c *Container) RegisterSingleton(iface any, factory func(*Container) (any, error)) *Container
- func (c *Container) RegisterTransient(iface any, factory func(*Container) (any, error)) *Container
- func (c *Container) Resolve(iface any) (any, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDefaultRegisteredTyped ¶
IsDefaultRegisteredTyped checks if a service is registered with the default container with type safety
func IsRegistered ¶
IsRegistered checks if a service is registered with the default container
func IsRegisteredTyped ¶
IsRegisteredTyped checks if a service is registered with type safety
func MustResolve ¶
MustResolve resolves a service from the default container and panics if it fails
func MustResolveDefaultTyped ¶
func MustResolveDefaultTyped[T any]() T
MustResolveDefaultTyped resolves a service from the default container with type safety and panics if it fails
func MustResolveTyped ¶
MustResolveTyped resolves a service from the container with type safety and panics if it fails
func ResetForTesting ¶
func ResetForTesting()
ResetForTesting resets the global default container and its initialization state. This must only be called from test code to ensure clean state between tests. Production code must never call this function.
func ResolveDefaultTyped ¶
ResolveDefaultTyped resolves a service from the default container with type safety
func ResolveTyped ¶
ResolveTyped resolves a service from the container with type safety
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container represents a dependency injection container
func Clear ¶
func Clear() *Container
Clear clears all registered services from the default container
func NewWithOptions ¶
NewWithOptions creates a new container with options
func RegisterDefaultServices ¶
RegisterDefaultServices registers multiple services at once with the default container
func RegisterDefaultSingletonInstance ¶
RegisterDefaultSingletonInstance registers a singleton instance with the default container
func RegisterInstance ¶
RegisterInstance registers an instance with the default container
func RegisterSingleton ¶
RegisterSingleton registers a singleton service with the default container
func RegisterSingletonInstance ¶
RegisterSingletonInstance registers a singleton instance
func RegisterTransient ¶
RegisterTransient registers a transient service with the default container
func (*Container) IsRegistered ¶
IsRegistered checks if a service is registered
func (*Container) MustResolve ¶
MustResolve resolves a service from the container and panics if it fails
func (*Container) Register ¶
func (c *Container) Register(iface any, factory func(*Container) (any, error), isSingleton bool) *Container
Register registers a service with the container
func (*Container) RegisterInstance ¶
RegisterInstance registers an existing instance with the container
func (*Container) RegisterServices ¶
RegisterServices registers multiple services at once
func (*Container) RegisterSingleton ¶
RegisterSingleton registers a singleton service
func (*Container) RegisterTransient ¶
RegisterTransient registers a transient service
type Option ¶
type Option func(*Container)
Option represents a container option
func WithInstance ¶
func WithInstance(iface interface{}, instance interface{}) Option
WithInstance registers an existing instance
func WithSingleton ¶
WithSingleton registers a service as a singleton
func WithTransient ¶
WithTransient registers a service as transient