registry

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const InjectTag = "aperture"

Variables

View Source
var EmptyContext = context.Background()
View Source
var TaskDispatcher asynctask.TaskDispatcher = nil

Functions

func AcquireInfrastructure

func AcquireInfrastructure()

func AcquireSingleton

func AcquireSingleton[T any](iface T) T

func AcquireSingletonByName

func AcquireSingletonByName[T any](name string) T

func ContainerProvide

func ContainerProvide[T any](c *Container) (T, bool)

func Load

func Load[T any](val T) T

Load is a shortcut for TryInject(val) Load will also check if val can add to registry

func MustRegister

func MustRegister[T any](val T, err error) T

func Register

func Register[T any](val T) T

func RegisterConfig

func RegisterConfig(config config.ConfigUnmarshaler)

func RegisterLogger

func RegisterLogger(logger logger.ILogger)

func RegisterSingleton

func RegisterSingleton[T any](singleton interface{})

func RegisterSingletonByName

func RegisterSingletonByName(name string, singleton interface{})

func RegisterTaskDispatcher

func RegisterTaskDispatcher(taskDispatcher asynctask.TaskDispatcher)

func TryInject

func TryInject[T any](injectable T) T

func Use

func Use[T any](val T) T

Use is a function to get instance from registry if val is not nil, then return itself if val is nil, then return the instance from registry

func Validate

func Validate()

Types

type Container

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

func NewContainer

func NewContainer(providers ...Provider[any]) *Container

func (*Container) ContainerName

func (c *Container) ContainerName() string

type Dependency

type Dependency[T any] interface {
	Inject(T)
}

type Provider

type Provider[T any] interface {
	Provide() T
}

type Registrant

type Registrant func(impl any)

type Registry

type Registry[I comparable, T any] interface {
	Register(impl T)
	RegisterByEntry(entry I, impl T)
	Acquire(impl T) T
	AcquireByEntry(entry I) T
	AcquireAll() []T
}
var Disposable Registry[int, scene.Disposable]

var Repository Registry[string, scene.Repository] var Service Registry[string, scene.Service]

var Setupable Registry[int, scene.Setupable]

func NewOrderedRegistry

func NewOrderedRegistry[I constraints.Ordered, T any](naming naming[I, T]) Registry[I, T]

func NewRegistry

func NewRegistry[I comparable, T any](naming naming[I, T]) Registry[I, T]

type SingletonProvider

type SingletonProvider[T any] struct {
	// contains filtered or unexported fields
}

func NewSingletonProvider

func NewSingletonProvider[T any](instance T) *SingletonProvider[T]

func (*SingletonProvider[T]) Provide

func (p *SingletonProvider[T]) Provide() T

Jump to

Keyboard shortcuts

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