Documentation ¶
Index ¶
- func AddDecoratorOf[T any](binder *Binder, fn func(injector Injector))
- func BindInterceptor[T any](binder *Binder, fn func(inj Injector, value T) T)
- func GetInstance[T any](injector Injector) T
- func GetInstanceOpt[T any](injector Injector) fp.Option[T]
- func GetInstancesOf[T any](injector Injector) []T
- func TypeOf[T any]() interface{}
- type AbstractModule
- type BindFunc
- type Binder
- func (b *Binder) AddDecoratorOf(ptrToType interface{}, decorator func(ij Injector))
- func (b *Binder) Bind(ptrToType interface{}) *Binding
- func (b *Binder) BindConstructor(ptrToType interface{}, constructor interface{}) *Binding
- func (b *Binder) BindInterceptor(ptrToType interface{}, ...)
- func (b *Binder) BindProvider(ptrToType interface{}, provider func(injector Injector) interface{}) *Binding
- func (b *Binder) BindSingleton(ptrToType interface{}, instance interface{}) *Binding
- func (b *Binder) IfNotBinded(ptrToType interface{}) *Binding
- type Binding
- func (b *Binding) AsEagerSingleton() *Binding
- func (b *Binding) AsNonSingleton() *Binding
- func (b *Binding) ShouldCreateBefore(ptrToType interface{}) *Binding
- func (b *Binding) ToConstructor(function interface{}) *Binding
- func (b *Binding) ToInstance(instance interface{}) *Binding
- func (b *Binding) ToProvider(provider func(injector Injector) interface{}) *Binding
- type BindingTP
- func (b BindingTP[T]) AsEagerSingleton() BindingTP[T]
- func (b BindingTP[T]) ShouldCreateBefore(tpe interface{}) BindingTP[T]
- func (b BindingTP[T]) ToConstructor(constructor interface{}) BindingTP[T]
- func (b BindingTP[T]) ToInstance(singleton T) BindingTP[T]
- func (b BindingTP[T]) ToProvider(provider func(injector Injector) T) BindingTP[T]
- type Implements
- func (r *Implements) AddBind(bindF func(binder *Binder)) *Implements
- func (r *Implements) AddImplement(name string, impl AbstractModule) *Implements
- func (r *Implements) AddImplements(impl *Implements) *Implements
- func (r *Implements) Clone() *Implements
- func (r *Implements) GetImplement(name string) AbstractModule
- func (r *Implements) HasImplement(name string) bool
- func (r *Implements) NewInjector(moduleNames []string) Injector
- func (r *Implements) NewInjectorWithTimeout(moduleNames []string, timeout time.Duration) Injector
- func (r *Implements) NewInjectorWithTrace(moduleNames []string, traceCallback TraceCallback) Injector
- type Injector
- type OverridableModule
- type TraceCallback
- type TraceInfo
- type TraceType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddDecoratorOf ¶ added in v0.3.3
func BindInterceptor ¶ added in v0.3.3
func GetInstance ¶ added in v0.3.3
func GetInstancesOf ¶ added in v0.3.3
Types ¶
type AbstractModule ¶
type AbstractModule interface {
Configure(binder *Binder)
}
AbstractModule is used to create bindings
func CombineModule ¶ added in v0.2.6
func CombineModule(modules ...AbstractModule) AbstractModule
CombineModule Returns a new module that installs all of modules
type BindFunc ¶ added in v0.2.4
type BindFunc func(binder *Binder)
BindFunc can act as AbstractModule
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
Binder has bindings
func (*Binder) AddDecoratorOf ¶ added in v0.2.7
AddDecoratorOf add customizing function which will be applied to the created singleton instance if the type is not singleton, then the decorator callback will not be called
func (*Binder) BindConstructor ¶ added in v0.2.5
BindConstructor binds intf type to constructor function
func (*Binder) BindInterceptor ¶ added in v0.3.0
func (b *Binder) BindInterceptor( ptrToType interface{}, interceptorProvider func(injector Injector, instance interface{}) interface{}, )
BindInterceptor binds interceptor
func (*Binder) BindProvider ¶
func (b *Binder) BindProvider(ptrToType interface{}, provider func(injector Injector) interface{}) *Binding
BindProvider binds intf type to provider function
func (*Binder) BindSingleton ¶
BindSingleton binds intf type to singleton instance
func (*Binder) IfNotBinded ¶ added in v0.2.4
IfNotBinded returns Binding that will used if there are no other binding for tpe type
type Binding ¶ added in v0.1.3
type Binding struct {
// contains filtered or unexported fields
}
Binding has provider function and created singlton instances and it has some configurtions about binding
func BindConstructor ¶ added in v0.3.3
func BindProvider ¶ added in v0.3.3
func BindSingleton ¶ added in v0.3.3
func (*Binding) AsEagerSingleton ¶ added in v0.1.3
AsEagerSingleton set binding as eager singleton
func (*Binding) AsNonSingleton ¶ added in v0.1.5
AsNonSingleton set binding as non singleton
func (*Binding) ShouldCreateBefore ¶ added in v0.2.4
ShouldCreateBefore set creating order. this creation of instance should be performed before instance creation of the tpe type
func (*Binding) ToConstructor ¶ added in v0.2.5
ToConstructor binds type to the constructor
func (*Binding) ToInstance ¶ added in v0.2.4
ToInstance binds type to singleton instance
func (*Binding) ToProvider ¶ added in v0.2.4
ToProvider binds type to the provider
type BindingTP ¶ added in v0.3.3
type BindingTP[T any] struct { // contains filtered or unexported fields }
func IfNotBinded ¶ added in v0.3.3
func (BindingTP[T]) AsEagerSingleton ¶ added in v0.3.3
func (BindingTP[T]) ShouldCreateBefore ¶ added in v0.3.3
func (BindingTP[T]) ToConstructor ¶ added in v0.3.3
func (BindingTP[T]) ToInstance ¶ added in v0.3.3
func (BindingTP[T]) ToProvider ¶ added in v0.3.3
type Implements ¶
type Implements struct {
// contains filtered or unexported fields
}
Implements is registry of AbstractModule
func (*Implements) AddBind ¶ added in v0.1.4
func (r *Implements) AddBind(bindF func(binder *Binder)) *Implements
AddBind adds no named abstrace module
func (*Implements) AddImplement ¶
func (r *Implements) AddImplement(name string, impl AbstractModule) *Implements
AddImplement adds named abstract module to Implements
func (*Implements) AddImplements ¶ added in v0.1.9
func (r *Implements) AddImplements(impl *Implements) *Implements
AddImplements adds all named AbstraceModule of impl to this
func (*Implements) Clone ¶ added in v0.2.3
func (r *Implements) Clone() *Implements
Clone returns clone of this
func (*Implements) GetImplement ¶ added in v0.2.7
func (r *Implements) GetImplement(name string) AbstractModule
GetImplement returns AbstractModule
func (*Implements) HasImplement ¶ added in v0.2.3
func (r *Implements) HasImplement(name string) bool
HasImplement returns whether named module is registered
func (*Implements) NewInjector ¶ added in v0.2.6
func (r *Implements) NewInjector(moduleNames []string) Injector
NewInjector returns new Injector from implements with enabled modulenames
func (*Implements) NewInjectorWithTimeout ¶ added in v0.2.6
func (r *Implements) NewInjectorWithTimeout(moduleNames []string, timeout time.Duration) Injector
NewInjectorWithTimeout returns new Injector from implements with enabled modulenames and it checks timeout
func (*Implements) NewInjectorWithTrace ¶ added in v0.2.9
func (r *Implements) NewInjectorWithTrace(moduleNames []string, traceCallback TraceCallback) Injector
NewInjectorWithTrace creates injector and call callback function when instances are created
type Injector ¶
type Injector interface { GetInstance(ptrToType interface{}) interface{} GetProperty(propName string) string SetProperty(propName string, value string) GetInstancesOf(ptrToType interface{}) []interface{} InjectMembers(ptrToStruct interface{}) InjectAndCall(function interface{}) interface{} InjectValue(ptrToInterface interface{}) }
Injector used to get instance
func CreateInjector ¶ added in v0.2.6
func CreateInjector(modules ...AbstractModule) Injector
CreateInjector creates new Injector with provided modules
func NewInjector ¶
func NewInjector(implements *Implements, moduleNames []string) Injector
NewInjector returns new Injector from implements with enabled modulenames
func NewInjectorWithTimeout ¶ added in v0.1.9
func NewInjectorWithTimeout(implements *Implements, moduleNames []string, timeout time.Duration) Injector
NewInjectorWithTimeout returns new Injector from implements with enabled modulenames and it checks timeout
type OverridableModule ¶ added in v0.2.6
type OverridableModule interface { AbstractModule With(overrides ...AbstractModule) AbstractModule }
OverridableModule is overridable module
func OverrideModule ¶ added in v0.2.6
func OverrideModule(modules ...AbstractModule) OverridableModule
OverrideModule Returns a builder that creates a module that overlays override modules over the given modules.
type TraceCallback ¶ added in v0.2.9
type TraceCallback func(info *TraceInfo)
TraceCallback is trace call back function
type TraceInfo ¶ added in v0.2.9
type TraceInfo struct { TraceType TraceType RequestedType reflect.Type Referer reflect.Type ReturnedInstance interface{} IsCreatedNow bool ElapsedTime time.Duration IsSingleton bool IsBinded bool IsEager bool }
TraceInfo is trace message