di

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 10 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotRegistered                  = errors.New("dependency not registered")
	ErrFillParameters                 = errors.New("invalid fill parameters")
	ErrDependencyProviderNotInContext = errors.New("DependencyProvider not in context")
)
View Source
var (
	ErrDependancyCycle   = errors.New("dependancy cycle")
	ErrMissingDependancy = errors.New("missing dependancy")
)

Functions

func ContextWithDependencyProvider added in v0.9.0

func ContextWithDependencyProvider(ctx context.Context, dp *DependencyProvider) context.Context

func Fill added in v0.9.0

func Fill(ctx context.Context, v any) error

func IsFillable added in v0.16.1

func IsFillable(v any) bool

func PrepareFunc added in v0.16.0

func PrepareFunc[T any](dp *DependencyProvider, fn any) T

func PrepareFuncCtx added in v0.16.0

func PrepareFuncCtx[T any](fn any) T

func Register

func Register[T any](ctx context.Context, factory func(ctx context.Context, tag string) (T, error))

func RegisterFactory added in v0.15.0

func RegisterFactory(ctx context.Context, factory Factory)

func RegisterLazySingleton

func RegisterLazySingleton[T any](ctx context.Context, factory func() (T, error))

func RegisterLazySingletonWith added in v0.10.2

func RegisterLazySingletonWith[T, W any](ctx context.Context, factory func(with W) (T, error))

func RegisterSingleton

func RegisterSingleton[T any](ctx context.Context, factory func() T)

func RegisterValue added in v0.14.0

func RegisterValue(ctx context.Context, t reflect.Type, factory func(ctx context.Context, tag string) (reflect.Value, error))

func RegisterWith

func RegisterWith[T, W any](ctx context.Context, factory func(ctx context.Context, tag string, with W) (T, error))

func Resolve

func Resolve[T any](ctx context.Context) (T, error)

func TestDependencyProviderContext added in v0.9.0

func TestDependencyProviderContext() context.Context

Types

type DIValidator added in v0.15.0

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

func Validator added in v0.15.0

func Validator(ctx context.Context, rootType reflect.Type) *DIValidator

func (*DIValidator) Validate added in v0.15.0

func (v *DIValidator) Validate(ctx context.Context) error

type Dependant added in v0.16.0

type Dependant interface {
	DependsOn() []reflect.Type
}

type DependencyProvider

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

func GetDependencyProvider added in v0.9.0

func GetDependencyProvider(ctx context.Context) *DependencyProvider

func NewDependencyProvider

func NewDependencyProvider() *DependencyProvider

func (*DependencyProvider) Fill

func (dp *DependencyProvider) Fill(ctx context.Context, v any) error

func (*DependencyProvider) Register

func (d *DependencyProvider) Register(factory Factory)

func (*DependencyProvider) Singletons added in v0.15.0

func (dp *DependencyProvider) Singletons() []Singleton

func (*DependencyProvider) Validate added in v0.11.0

func (dp *DependencyProvider) Validate(ctx context.Context) error

func (*DependencyProvider) Validator added in v0.15.0

func (dp *DependencyProvider) Validator(rootType reflect.Type) *DIValidator

type Factory added in v0.15.0

type Factory interface {
	Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)
	Type() reflect.Type
}

type FactoryFunc added in v0.15.0

type FactoryFunc[T any] func(ctx context.Context, tag string) (T, error)

func NewFactoryFunc added in v0.15.0

func NewFactoryFunc[T any](f func(ctx context.Context, tag string) (T, error)) FactoryFunc[T]

func (FactoryFunc[T]) Build added in v0.15.0

func (f FactoryFunc[T]) Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)

func (FactoryFunc[T]) Type added in v0.15.0

func (f FactoryFunc[T]) Type() reflect.Type

type FactoryFuncWith added in v0.16.0

type FactoryFuncWith[T, W any] func(ctx context.Context, tag string, with W) (T, error)

func NewFactoryFuncWith added in v0.16.0

func NewFactoryFuncWith[T, W any](f func(ctx context.Context, tag string, with W) (T, error)) FactoryFuncWith[T, W]

func (FactoryFuncWith[T, W]) Build added in v0.16.0

func (f FactoryFuncWith[T, W]) Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)

func (FactoryFuncWith[T, W]) DependsOn added in v0.16.0

func (f FactoryFuncWith[T, W]) DependsOn() []reflect.Type

func (FactoryFuncWith[T, W]) Type added in v0.16.0

func (f FactoryFuncWith[T, W]) Type() reflect.Type

type LazySingletonFactory added in v0.15.0

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

func NewLazySingletonFactory added in v0.15.0

func NewLazySingletonFactory[T any](factory func() (T, error)) *LazySingletonFactory[T]

func (*LazySingletonFactory[T]) Build added in v0.15.0

func (f *LazySingletonFactory[T]) Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)

func (*LazySingletonFactory[T]) Peek added in v0.15.0

func (f *LazySingletonFactory[T]) Peek() (any, error, bool)

func (*LazySingletonFactory[T]) Type added in v0.15.0

func (f *LazySingletonFactory[T]) Type() reflect.Type

type LazySingletonWithFactory added in v0.16.0

type LazySingletonWithFactory[T, W any] struct {
	// contains filtered or unexported fields
}

func NewLazySingletonWithFactory added in v0.16.0

func NewLazySingletonWithFactory[T, W any](factory func(with W) (T, error)) *LazySingletonWithFactory[T, W]

func (*LazySingletonWithFactory[T, W]) Build added in v0.16.0

func (f *LazySingletonWithFactory[T, W]) Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)

func (*LazySingletonWithFactory[T, W]) DependsOn added in v0.16.0

func (f *LazySingletonWithFactory[T, W]) DependsOn() []reflect.Type

func (*LazySingletonWithFactory[T, W]) Peek added in v0.16.0

func (f *LazySingletonWithFactory[T, W]) Peek() (any, error, bool)

func (*LazySingletonWithFactory[T, W]) Type added in v0.16.0

func (f *LazySingletonWithFactory[T, W]) Type() reflect.Type

type Singleton added in v0.15.0

type Singleton interface {
	Peek() (any, error, bool)
}

func Singletons added in v0.15.0

func Singletons(ctx context.Context) []Singleton

type SingletonFactory added in v0.15.0

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

func NewSingletonFactory added in v0.15.0

func NewSingletonFactory[T any](value T) *SingletonFactory[T]

func (*SingletonFactory[T]) Build added in v0.15.0

func (f *SingletonFactory[T]) Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)

func (*SingletonFactory[T]) Peek added in v0.15.0

func (f *SingletonFactory[T]) Peek() (any, error, bool)

func (*SingletonFactory[T]) Type added in v0.15.0

func (f *SingletonFactory[T]) Type() reflect.Type

type ValueFactory added in v0.15.0

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

func NewValueFactory added in v0.15.0

func NewValueFactory(typ reflect.Type, factory func(ctx context.Context, tag string) (reflect.Value, error)) *ValueFactory

func (*ValueFactory) Build added in v0.15.0

func (f *ValueFactory) Build(ctx context.Context, dp *DependencyProvider, tag string) (any, error)

func (*ValueFactory) Type added in v0.15.0

func (f *ValueFactory) Type() reflect.Type

Jump to

Keyboard shortcuts

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