erasure

package
v2.2.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

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 Entry added in v2.0.1

type Entry[K comparable, V any] = record.Entry[K, V]

type IOOption

type IOOption[T any] = iooption.IOOption[T]

type IOResult

type IOResult[T any] = ioresult.IOResult[T]

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 Option

type Option[T any] = option.Option[T]

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]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL