registry

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelDisposerBundle

func CancelDisposerBundle(closers ...Cancelable)

func CloserDisposerBundle

func CloserDisposerBundle(closers ...io.Closer)

func DisposerBundle

func DisposerBundle(disposers ...any)

func Get

func Get[Type any](c Interface) Type

func Injectable

func Injectable(v ...interface{}) uint

Injectable marks the type as field to be injectable while searching for fields to inject

func NewIOCloserProvider

func NewIOCloserProvider(v io.Closer) (closer *ioCloserProvider)

func NewPoolProvider

func NewPoolProvider(pool *sync.Pool, v interface{}) (pooler *poolerProvider)

func Set

func Set[Type any](c ContainerAware, val Type) (err error)

func SetProvider

func SetProvider[Type any](c Interface, builder func(registry Interface) Type) (err error)

func TypeOf

func TypeOf(i interface{}) reflect.Type

func TypeOfElem

func TypeOfElem(i interface{}) reflect.Type

Types

type Cancelable

type Cancelable interface {
	Cancel() error
}

type ContainerAware

type ContainerAware interface {
	Container() Interface
}

type Definer

type Definer[Type any] interface {
	Config(d TypeDefinition[Type]) error
}

type Disposer

type Disposer interface {
	Dispose()
}

type Initializer

type Initializer interface {
	Initialize(c Interface, value reflect.Value)
}

type InitializerFunc

type InitializerFunc func(c Interface, value reflect.Value)

type Interface

type Interface interface {
	// Container returns the underlying Registry
	Container() Interface

	// Load loads a value into the provided destination
	Load(dst interface{})

	// LoadValue loads a value into the provided reflect.Value
	LoadValue(dst reflect.Value)

	// Autowire walks the target looking for exported fields that match injectable types
	Autowire(target interface{})

	// InjectValue walks the struct value looking for injectable fields
	InjectValue(value reflect.Value)

	// MapProvider maps a provider for a type
	MapProvider(typ reflect.Type, provider Provider)

	// WithTypeAndProviderFunc maps a provider function for a type
	WithTypeAndProviderFunc(typ reflect.Type, provider ProviderFunc)

	// MapInitializer maps an initializer for a type
	MapInitializer(typ reflect.Type, initializer Initializer)

	// MapInitializerFunc maps an initializer function for a type
	MapInitializerFunc(typ reflect.Type, initializer InitializerFunc)

	// WithTypeAndValue sets a value for a type
	WithTypeAndValue(typOf reflect.Type, value interface{})

	// WithValues puts a list of values into the current context
	WithValues(values ...interface{})

	// Fork creates a new registry using the current one as parent
	Fork() Interface

	// LoadType returns a value for the specified type
	LoadType(typ reflect.Type) interface{}

	// Dispose releases all resources and returns the reference count
	Dispose() int64

	// MustDispose disposes and requires all references to be cleared
	MustDispose()
}

Interface registry defines the contract for the registry.Registry type

type LifeCycle

type LifeCycle string

type Provider

type Provider interface {
	Provide(c Interface) interface{}
}

type ProviderFunc

type ProviderFunc func(c Interface) interface{}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func New

func New() (r *Registry)

New creates a new instance of context object

func (*Registry) Autowire

func (r *Registry) Autowire(target interface{})

Autowire walks the target looking the for exported fields that types match injectable types in Registry

func (*Registry) Container

func (r *Registry) Container() Interface

func (*Registry) Dispose

func (r *Registry) Dispose() int64

Dispose call end when the request is not need any more, this will cause all finalizers to run, this will my cause parent scopes to end also, this will happen case the parent scopes already ended but is waiting all children to end

func (*Registry) Fork

func (r *Registry) Fork() Interface

Fork creates a new context using current value's repository as provider for the new context

func (*Registry) InjectValue

func (r *Registry) InjectValue(value reflect.Value)

InjectValue walks the struct value looking to injectable fields

func (*Registry) Load

func (r *Registry) Load(dst interface{})

func (*Registry) LoadType

func (r *Registry) LoadType(typ reflect.Type) (val interface{})

LoadType returns a value for the specified type typ

func (*Registry) LoadValue

func (r *Registry) LoadValue(dst reflect.Value)

func (*Registry) MapInitializer

func (r *Registry) MapInitializer(typ reflect.Type, initializer Initializer)

func (*Registry) MapInitializerFunc

func (r *Registry) MapInitializerFunc(typ reflect.Type, initializer InitializerFunc)

func (*Registry) MapProvider

func (r *Registry) MapProvider(typ reflect.Type, provider Provider)

func (*Registry) MustDispose

func (r *Registry) MustDispose()

MustDispose works same as Close, but require that all children to be terminated when called

func (*Registry) WithTypeAndProviderFunc

func (r *Registry) WithTypeAndProviderFunc(typ reflect.Type, provider ProviderFunc)

func (*Registry) WithTypeAndValue

func (r *Registry) WithTypeAndValue(typOf reflect.Type, value interface{})

WithTypeAndValue sets a provider for the type of typ with value of val

func (*Registry) WithValues

func (r *Registry) WithValues(values ...interface{})

WithValues puts the list of values into the current context

type TypeDefinition

type TypeDefinition[Type any] struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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