Documentation
¶
Overview ¶
Package plumbing defines generic types for the dependency injection mechanisms in rig.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
Factory is a function that takes a parameter of type R and returns a value of type T or an error.
type LazyService ¶
LazyService is a generic lazy-initializer that calls a provider function once and memoizes the result.
func NewLazyService ¶
func NewLazyService[S any, T any](get func(S) (T, error), source S) *LazyService[S, T]
NewLazyService creates a new instance of LazyService with the given provider function.
func (*LazyService[S, T]) Get ¶
func (s *LazyService[S, T]) Get() (T, error)
Get retrieves the service value, initializing it if necessary.
type Provider ¶
Provider is a generic provider of values of type T that can be initialized with a value of type R.
func NewProvider ¶
NewProvider creates a new instance of Provider. The error is returned if no factory can produce a value of type T.
func (*Provider[R, T]) Get ¶
Get retrieves the first value of type T from the Factories in the Provider. If none can be found, the error supplied at creation time is returned. The first factory that does not error is moved to the front of the list to optimize future lookups.