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() Option[ProviderFactory]
}
Dependency describes the relationship to a service
type InjectableFactory ¶
type InjectableFactory = ReaderIOResult[Dependency, 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 = ReaderIOResult[InjectableFactory, any]
func MakeProviderFactory ¶
func MakeProviderFactory( deps []Dependency, fct func(param ...any) IOResult[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
type ReaderIOResult ¶ added in v2.2.1
type ReaderIOResult[R, T any] = readerioresult.ReaderIOResult[R, T]
Click to show internal directories.
Click to hide internal directories.