Documentation ¶
Index ¶
- Constants
- Variables
- func AddInstance[T any](cb ContainerBuilder, instance any, implementedInterfaceTypes ...reflect.Type)
- func AddInstanceWithLookupKeys[T any](cb ContainerBuilder, instance any, lookupKeys []string, ...)
- func AddScoped[T any](cb ContainerBuilder, ctor any, implementedInterfaceTypes ...reflect.Type)
- func AddScopedFactory[T any](cb ContainerBuilder, factory Factory)
- func AddScopedWithLookupKeys[T any](cb ContainerBuilder, ctor any, lookupKeys []string, ...)
- func AddSingleton[T any](cb ContainerBuilder, ctor any, implementedInterfaceTypes ...reflect.Type)
- func AddSingletonFactory[T any](cb ContainerBuilder, factory Factory)
- func AddSingletonWithLookupKeys[T any](cb ContainerBuilder, ctor any, lookupKeys []string, ...)
- func AddTransient[T any](cb ContainerBuilder, ctor any, implementedInterfaceTypes ...reflect.Type)
- func AddTransientFactory[T any](cb ContainerBuilder, factory Factory)
- func AddTransientWithLookupKeys[T any](cb ContainerBuilder, ctor any, lookupKeys []string, ...)
- func Get[T any](c Container) T
- func GetByLookupKey[T any](c Container, key string) T
- func Invoke(c Container, fn any) (fnReturn []any, err error)
- func TryGet[T any](c Container) (result T, err error)
- func TryGetByLookupKey[T any](c Container, key string) (result T, err error)
- type CacheLocation
- type CallSite
- type CallSiteFactory
- func (f *CallSiteFactory) Add(serviceType reflect.Type, callSite CallSite)
- func (f *CallSiteFactory) Descriptors() []*Descriptor
- func (f *CallSiteFactory) GetCallSite(serviceType reflect.Type, chain *callSiteChain) (CallSite, error)
- func (f *CallSiteFactory) GetCallSiteByDescriptor(descriptor *Descriptor, chain *callSiteChain) (CallSite, error)
- func (f *CallSiteFactory) IsService(serviceType reflect.Type) bool
- type CallSiteKind
- type CallSiteResolver
- type CallSiteValidator
- type ConstantCallSite
- type ConstructorCallSite
- type ConstructorInfo
- type Container
- type ContainerBuilder
- type ContainerCallSite
- type ContainerEngine
- type ContainerEngineScope
- func (s *ContainerEngineScope) BeginDispose() []Disposable
- func (s *ContainerEngineScope) CaptureDisposable(service any) (Disposable, error)
- func (s *ContainerEngineScope) CaptureDisposableWithoutLock(service any) (Disposable, error)
- func (s *ContainerEngineScope) Container() Container
- func (s *ContainerEngineScope) CreateScope() Scope
- func (s *ContainerEngineScope) Disposables() []Disposable
- func (s *ContainerEngineScope) Dispose()
- func (s *ContainerEngineScope) Get(serviceType reflect.Type) (any, error)
- func (s *ContainerEngineScope) GetByLookupKey(serviceType reflect.Type, key string) (any, error)
- func (c *ContainerEngineScope) GetDescriptors() []*Descriptor
- type Descriptor
- func Instance[T any](instance any, implementedInterfaceTypes ...reflect.Type) *Descriptor
- func NewConstructorDescriptor(serviceType reflect.Type, lifetime Lifetime, ctor any, ...) *Descriptor
- func NewFactoryDescriptor(serviceType reflect.Type, lifetime Lifetime, factory Factory) *Descriptor
- func NewInstanceDescriptor(serviceType reflect.Type, instance any, ...) *Descriptor
- func Scoped[T any](ctor any, implementedInterfaceTypes ...reflect.Type) *Descriptor
- func ScopedFactory[T any](factory Factory) *Descriptor
- func Singleton[T any](ctor any, implementedInterfaceTypes ...reflect.Type) *Descriptor
- func SingletonFactory[T any](factory Factory) *Descriptor
- func Transient[T any](ctor any, implementedInterfaceTypes ...reflect.Type) *Descriptor
- func TransientFactory[T any](factory Factory) *Descriptor
- type Disposable
- type Factory
- type FactoryCallSite
- type IsService
- type Lifetime
- type Options
- type ResultCache
- type Scope
- type ScopeFactory
- type ServiceAccessor
- type ServiceCacheKey
- type SliceCallSite
Constants ¶
const DefaultSlot int = 0
const Version = "v0.1.0"
Variables ¶
var ContainerImplType = reflectx.TypeOf[container]()
var ContainerType = reflectx.TypeOf[Container]()
var EmptyServiceCacheKey = ServiceCacheKey{nil, 0}
var IsServiceType = reflectx.TypeOf[IsService]()
var NoneResultCache = newResultCache(CacheLocation_None, EmptyServiceCacheKey)
var ScopeFactoryType = reflectx.TypeOf[ScopeFactory]()
Functions ¶
func AddInstance ¶
func AddInstance[T any](cb ContainerBuilder, instance any, implementedInterfaceTypes ...reflect.Type)
Add an instance service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, the instance must be assignable to the service T.
func AddInstanceWithLookupKeys ¶
func AddInstanceWithLookupKeys[T any](cb ContainerBuilder, instance any, lookupKeys []string, metadata map[string]interface{}, implementedInterfaceTypes ...reflect.Type)
Add an instance service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, the instance must be assignable to the service T. lookupKeys is the lookup keys of the service T. implementedInterfaceTypes is the implemented interface types of the service T.
func AddScoped ¶
func AddScoped[T any](cb ContainerBuilder, ctor any, implementedInterfaceTypes ...reflect.Type)
Add a scoped service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, ctor is the constructor of the service T. implementedInterfaceTypes is the implemented interface types of the service T.
func AddScopedFactory ¶
func AddScopedFactory[T any](cb ContainerBuilder, factory Factory)
func AddScopedWithLookupKeys ¶
func AddScopedWithLookupKeys[T any](cb ContainerBuilder, ctor any, lookupKeys []string, metadata map[string]interface{}, implementedInterfaceTypes ...reflect.Type)
Add a scoped service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, ctor is the constructor of the service T. lookupKeys is the lookup keys of the service T. implementedInterfaceTypes is the implemented interface types of the service T.
func AddSingleton ¶
func AddSingleton[T any](cb ContainerBuilder, ctor any, implementedInterfaceTypes ...reflect.Type)
Add a singleton service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, ctor is the constructor of the service T.
func AddSingletonFactory ¶
func AddSingletonFactory[T any](cb ContainerBuilder, factory Factory)
func AddSingletonWithLookupKeys ¶
func AddSingletonWithLookupKeys[T any](cb ContainerBuilder, ctor any, lookupKeys []string, metadata map[string]interface{}, implementedInterfaceTypes ...reflect.Type)
Add a singleton service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, ctor is the constructor of the service T. lookupKeys is the lookup keys of the service T. implementedInterfaceTypes is the implemented interface types of the service T.
func AddTransient ¶
func AddTransient[T any](cb ContainerBuilder, ctor any, implementedInterfaceTypes ...reflect.Type)
Add a transient service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, ctor is the constructor of the service T.
func AddTransientFactory ¶
func AddTransientFactory[T any](cb ContainerBuilder, factory Factory)
func AddTransientWithLookupKeys ¶
func AddTransientWithLookupKeys[T any](cb ContainerBuilder, ctor any, lookupKeys []string, metadata map[string]interface{}, implementedInterfaceTypes ...reflect.Type)
Add a transient service descriptor to the ContainerBuilder. T is the service type, cb is the ContainerBuilder, ctor is the constructor of the service T. lookupKeys is the lookup keys of the service T. implementedInterfaceTypes is the implemented interface types of the service T.
func GetByLookupKey ¶
Get service of the type T from the container c
Types ¶
type CacheLocation ¶
type CacheLocation byte
callsite result cache location
const ( CacheLocation_Root CacheLocation = iota CacheLocation_Scope CacheLocation_Dispose CacheLocation_None )
type CallSite ¶
type CallSite interface { ServiceType() reflect.Type Kind() CallSiteKind Value() any SetValue(any) Cache() ResultCache }
type CallSiteFactory ¶
type CallSiteFactory struct {
// contains filtered or unexported fields
}
func (*CallSiteFactory) Add ¶
func (f *CallSiteFactory) Add(serviceType reflect.Type, callSite CallSite)
func (*CallSiteFactory) Descriptors ¶
func (f *CallSiteFactory) Descriptors() []*Descriptor
func (*CallSiteFactory) GetCallSite ¶
func (f *CallSiteFactory) GetCallSite(serviceType reflect.Type, chain *callSiteChain) (CallSite, error)
func (*CallSiteFactory) GetCallSiteByDescriptor ¶
func (f *CallSiteFactory) GetCallSiteByDescriptor(descriptor *Descriptor, chain *callSiteChain) (CallSite, error)
type CallSiteKind ¶
type CallSiteKind byte
const ( CallSiteKind_Factory CallSiteKind = iota CallSiteKind_Constructor CallSiteKind_Constant CallSiteKind_Slice CallSiteKind_Container CallSiteKind_Scope CallSiteKind_Transient CallSiteKind_Singleton )
type CallSiteResolver ¶
type CallSiteResolver struct {
// contains filtered or unexported fields
}
var CallSiteResolverInstance *CallSiteResolver = newCallSiteResolver()
func (*CallSiteResolver) Resolve ¶
func (r *CallSiteResolver) Resolve(callSite CallSite, scope *ContainerEngineScope) (any, error)
type CallSiteValidator ¶
type CallSiteValidator struct {
// contains filtered or unexported fields
}
func (*CallSiteValidator) ValidateCallSite ¶
func (v *CallSiteValidator) ValidateCallSite(callSite CallSite) error
func (*CallSiteValidator) ValidateResolution ¶
type ConstantCallSite ¶
type ConstantCallSite struct {
// contains filtered or unexported fields
}
func (*ConstantCallSite) Cache ¶
func (cs *ConstantCallSite) Cache() ResultCache
func (*ConstantCallSite) DefaultValue ¶
func (cs *ConstantCallSite) DefaultValue() any
func (*ConstantCallSite) Kind ¶
func (cs *ConstantCallSite) Kind() CallSiteKind
func (*ConstantCallSite) ServiceType ¶
func (cs *ConstantCallSite) ServiceType() reflect.Type
func (*ConstantCallSite) SetValue ¶
func (cs *ConstantCallSite) SetValue(v any)
func (*ConstantCallSite) Value ¶
func (cs *ConstantCallSite) Value() any
type ConstructorCallSite ¶
type ConstructorCallSite struct { Ctor *ConstructorInfo Parameters []CallSite // contains filtered or unexported fields }
func (*ConstructorCallSite) Cache ¶
func (cs *ConstructorCallSite) Cache() ResultCache
func (*ConstructorCallSite) Kind ¶
func (cs *ConstructorCallSite) Kind() CallSiteKind
func (*ConstructorCallSite) ServiceType ¶
func (cs *ConstructorCallSite) ServiceType() reflect.Type
func (*ConstructorCallSite) SetValue ¶
func (cs *ConstructorCallSite) SetValue(v any)
func (*ConstructorCallSite) Value ¶
func (cs *ConstructorCallSite) Value() any
type ConstructorInfo ¶
type ContainerBuilder ¶
type ContainerCallSite ¶
type ContainerCallSite struct {
// contains filtered or unexported fields
}
func (*ContainerCallSite) Cache ¶
func (cs *ContainerCallSite) Cache() ResultCache
func (*ContainerCallSite) Kind ¶
func (cs *ContainerCallSite) Kind() CallSiteKind
func (*ContainerCallSite) ServiceType ¶
func (cs *ContainerCallSite) ServiceType() reflect.Type
func (*ContainerCallSite) SetValue ¶
func (cs *ContainerCallSite) SetValue(v any)
func (*ContainerCallSite) Value ¶
func (cs *ContainerCallSite) Value() any
type ContainerEngine ¶
type ContainerEngine interface {
RealizeService(CallSite) (ServiceAccessor, error)
}
type ContainerEngineScope ¶
type ContainerEngineScope struct { RootContainer *container IsRootScope bool ResolvedServices map[ServiceCacheKey]any Locker *sync.Mutex // contains filtered or unexported fields }
func (*ContainerEngineScope) BeginDispose ¶
func (s *ContainerEngineScope) BeginDispose() []Disposable
func (*ContainerEngineScope) CaptureDisposable ¶
func (s *ContainerEngineScope) CaptureDisposable(service any) (Disposable, error)
func (*ContainerEngineScope) CaptureDisposableWithoutLock ¶
func (s *ContainerEngineScope) CaptureDisposableWithoutLock(service any) (Disposable, error)
func (*ContainerEngineScope) Container ¶
func (s *ContainerEngineScope) Container() Container
func (*ContainerEngineScope) CreateScope ¶
func (s *ContainerEngineScope) CreateScope() Scope
func (*ContainerEngineScope) Disposables ¶
func (s *ContainerEngineScope) Disposables() []Disposable
func (*ContainerEngineScope) Dispose ¶
func (s *ContainerEngineScope) Dispose()
func (*ContainerEngineScope) Get ¶
func (s *ContainerEngineScope) Get(serviceType reflect.Type) (any, error)
func (*ContainerEngineScope) GetByLookupKey ¶
func (*ContainerEngineScope) GetDescriptors ¶
func (c *ContainerEngineScope) GetDescriptors() []*Descriptor
type Descriptor ¶
type Descriptor struct { ServiceType reflect.Type Lifetime Lifetime Ctor *ConstructorInfo Instance any Factory func(Container) any ImplementedInterfaceTypes []reflect.Type LookupKeys []string Metadata map[string]interface{} }
service descriptor
func Instance ¶
func Instance[T any](instance any, implementedInterfaceTypes ...reflect.Type) *Descriptor
New a descriptor with instance
func NewFactoryDescriptor ¶
func NewFactoryDescriptor(serviceType reflect.Type, lifetime Lifetime, factory Factory) *Descriptor
func NewInstanceDescriptor ¶
func Scoped ¶
func Scoped[T any](ctor any, implementedInterfaceTypes ...reflect.Type) *Descriptor
New a scoped constructor descriptor
func ScopedFactory ¶
func ScopedFactory[T any](factory Factory) *Descriptor
New a scoped factory descriptor
func Singleton ¶
func Singleton[T any](ctor any, implementedInterfaceTypes ...reflect.Type) *Descriptor
New a singleton constructor descriptor
func SingletonFactory ¶
func SingletonFactory[T any](factory Factory) *Descriptor
New a singleton factory descriptor
func Transient ¶
func Transient[T any](ctor any, implementedInterfaceTypes ...reflect.Type) *Descriptor
New a transient constructor descriptor
func TransientFactory ¶
func TransientFactory[T any](factory Factory) *Descriptor
New a transient factory descriptor
func (*Descriptor) String ¶
func (d *Descriptor) String() string
type Disposable ¶
type Disposable interface {
Dispose()
}
type FactoryCallSite ¶
type FactoryCallSite struct { Factory Factory // contains filtered or unexported fields }
Factory call site
func (*FactoryCallSite) Cache ¶
func (cs *FactoryCallSite) Cache() ResultCache
func (*FactoryCallSite) Kind ¶
func (cs *FactoryCallSite) Kind() CallSiteKind
func (*FactoryCallSite) ServiceType ¶
func (cs *FactoryCallSite) ServiceType() reflect.Type
func (*FactoryCallSite) SetValue ¶
func (cs *FactoryCallSite) SetValue(v any)
func (*FactoryCallSite) Value ¶
func (cs *FactoryCallSite) Value() any
type IsService ¶
Optional service used to determine if the specified type is available from the Container.
type ResultCache ¶
type ResultCache struct { Location CacheLocation Key ServiceCacheKey }
callsite result cache
type ScopeFactory ¶
type ScopeFactory interface {
CreateScope() Scope
}
type ServiceAccessor ¶
type ServiceAccessor func(*ContainerEngineScope) (any, error)
type ServiceCacheKey ¶
type SliceCallSite ¶
type SliceCallSite struct { Elem reflect.Type CallSites []CallSite // contains filtered or unexported fields }
func (*SliceCallSite) Cache ¶
func (cs *SliceCallSite) Cache() ResultCache
func (*SliceCallSite) Kind ¶
func (cs *SliceCallSite) Kind() CallSiteKind
func (*SliceCallSite) ServiceType ¶
func (cs *SliceCallSite) ServiceType() reflect.Type
func (*SliceCallSite) SetValue ¶
func (cs *SliceCallSite) SetValue(v any)
func (*SliceCallSite) Value ¶
func (cs *SliceCallSite) Value() any