Documentation
¶
Index ¶
Constants ¶
View Source
const ( BehaviourMask = 0x0f Identity = 0 // required dependency Option = 1 // optional dependency IOEither = 2 // lazy and required IOOption = 3 // lazy and optional TypeMask = 0xf0 Multi = 1 << 4 // array of implementations Item = 2 << 4 // item of a multi token )
Variables ¶
View Source
var ( // Empty is the empty array of providers Empty = A.Empty[Provider]() )
Functions ¶
This section is empty.
Types ¶
type Dependency ¶
type Dependency interface { fmt.Stringer // Id returns a unique identifier for a token that can be used as a cache key Id() string // Flag returns a tag that identifies the behaviour of the dependency Flag() int // ProviderFactory optionally returns an attached [ProviderFactory] that represents the default for this dependency ProviderFactory() O.Option[ProviderFactory] }
Dependency describes the relationship to a service
type InjectableFactory ¶
type InjectableFactory = func(Dependency) IOE.IOEither[error, any]
InjectableFactory is a factory function that can create an untyped instance of a service based on its Dependency identifier
func MakeInjector ¶
func MakeInjector(providers []Provider) InjectableFactory
MakeInjector creates an InjectableFactory based on a set of [Provider]s
The resulting InjectableFactory can then be used to retrieve service instances given their Dependency. The implementation makes sure to transitively resolve the required dependencies.
type Provider ¶
type Provider interface { fmt.Stringer // Provides returns the [Dependency] implemented by this provider Provides() Dependency // Factory returns s function that can create an instance of the dependency based on an [InjectableFactory] Factory() ProviderFactory }
func MakeProvider ¶
func MakeProvider(token Dependency, fct ProviderFactory) Provider
type ProviderFactory ¶
type ProviderFactory = func(InjectableFactory) IOE.IOEither[error, any]
func MakeProviderFactory ¶
func MakeProviderFactory( deps []Dependency, fct func(param ...any) IOE.IOEither[error, any]) ProviderFactory
MakeProviderFactory constructs a ProviderFactory based on a set of [Dependency]s and a function that accepts the resolved dependencies to return a result
Click to show internal directories.
Click to hide internal directories.