Documentation
¶
Index ¶
- Constants
- Variables
- func AddInstance[T any](cb ContainerBuilder, instance any)
- func AddScoped[T any](cb ContainerBuilder, ctor any)
- func AddScopedFactory[T any](cb ContainerBuilder, factory Factory)
- func AddSingleton[T any](cb ContainerBuilder, ctor any)
- func AddSingletonFactory[T any](cb ContainerBuilder, factory Factory)
- func AddTransient[T any](cb ContainerBuilder, ctor any)
- func AddTransientFactory[T any](cb ContainerBuilder, factory Factory)
- func Get[T any](c Container) T
- func Invoke(c Container, fn any) (fnReturn []any, err error)
- func TryGet[T any](c Container) (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)
- type Descriptor
- func Instance[T any](instance any) *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) *Descriptor
- func ScopedFactory[T any](factory Factory) *Descriptor
- func Singleton[T any](ctor any) *Descriptor
- func SingletonFactory[T any](factory Factory) *Descriptor
- func Transient[T any](ctor any) *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)
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 AddScoped ¶
func AddScoped[T any](cb ContainerBuilder, ctor any)
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.
func AddScopedFactory ¶ added in v0.2.0
func AddScopedFactory[T any](cb ContainerBuilder, factory Factory)
func AddSingleton ¶
func AddSingleton[T any](cb ContainerBuilder, ctor any)
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 ¶ added in v0.2.0
func AddSingletonFactory[T any](cb ContainerBuilder, factory Factory)
func AddTransient ¶
func AddTransient[T any](cb ContainerBuilder, ctor any)
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 ¶ added in v0.2.0
func AddTransientFactory[T any](cb ContainerBuilder, factory Factory)
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()
type Descriptor ¶
type Descriptor struct { ServiceType reflect.Type Lifetime Lifetime Ctor *ConstructorInfo Instance any Factory func(Container) any }
service descriptor
func NewConstructorDescriptor ¶
func NewConstructorDescriptor(serviceType reflect.Type, lifetime Lifetime, ctor any) *Descriptor
func NewFactoryDescriptor ¶ added in v0.2.0
func NewFactoryDescriptor(serviceType reflect.Type, lifetime Lifetime, factory Factory) *Descriptor
func NewInstanceDescriptor ¶
func NewInstanceDescriptor(serviceType reflect.Type, instance any) *Descriptor
func ScopedFactory ¶ added in v0.2.0
func ScopedFactory[T any](factory Factory) *Descriptor
New a scoped factory descriptor
func SingletonFactory ¶ added in v0.2.0
func SingletonFactory[T any](factory Factory) *Descriptor
New a singleton factory descriptor
func TransientFactory ¶ added in v0.2.0
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 ¶ added in v0.2.0
type FactoryCallSite struct { Factory Factory // contains filtered or unexported fields }
Factory call site
func (*FactoryCallSite) Cache ¶ added in v0.2.0
func (cs *FactoryCallSite) Cache() ResultCache
func (*FactoryCallSite) Kind ¶ added in v0.2.0
func (cs *FactoryCallSite) Kind() CallSiteKind
func (*FactoryCallSite) ServiceType ¶ added in v0.2.0
func (cs *FactoryCallSite) ServiceType() reflect.Type
func (*FactoryCallSite) SetValue ¶ added in v0.2.0
func (cs *FactoryCallSite) SetValue(v any)
func (*FactoryCallSite) Value ¶ added in v0.2.0
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