di

package
v2.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpActivators errs.Op = "container: activators"
	OpRegister   errs.Op = "container: register"
	OpFactory    errs.Op = "container: factory"
	OpNew        errs.Op = "container: new"
	OpGet        errs.Op = "container: get"
	OpClose      errs.Op = "container: close"
)

Variables

This section is empty.

Functions

func Activators

func Activators(activators ...*Activator) error

func Close

func Close(ctx context.Context) error

func Configurer

func Configurer() config.Configurer

func Get

func Get[T any](ctx context.Context, key any, c ...Container) (value T, err error)

func Has

func Has(key any, c ...Container) bool

func Init

func Init(cfg config.Configurer)

func Must

func Must[T any](value T, err error) T

func MustGet

func MustGet[T any](ctx context.Context, key any, c ...Container) T

func MustNew

func MustNew[T any](ctx context.Context, key any, c ...Container) T

func New

func New[T any](ctx context.Context, key any, c ...Container) (value T, err error)

func Register

func Register(key any, factory Factory) error

Types

type Activator

type Activator struct {
	Key     any
	Factory Factory
}

type Closer

type Closer interface {
	Close(ctx context.Context) error
}

func ToNilCloser

func ToNilCloser[T any](value T, err error) (T, Closer, error)

type CloserFunc

type CloserFunc func(ctx context.Context) error

func (CloserFunc) Close

func (c CloserFunc) Close(ctx context.Context) error

type Container

type Container interface {
	Configurer() config.Configurer
	Activators(activators ...*Activator) error
	Register(key any, factory Factory) error
	Close(ctx context.Context) error
	New(ctx context.Context, key any) (any, error)
	Get(ctx context.Context, key any) (any, error)
	Has(key any) bool
}

func Default

func Default() Container

func NewContainer

func NewContainer(cfg config.Configurer) Container

type Factory

type Factory interface {
	New(context.Context, Container) (any, Closer, error)
}

type FactoryFunc

type FactoryFunc func(ctx context.Context, c Container) (any, Closer, error)

func (FactoryFunc) New

func (f FactoryFunc) New(ctx context.Context, c Container) (any, Closer, error)

Jump to

Keyboard shortcuts

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