di

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 11 Imported by: 0

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

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

func Fill

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

func IsFillable

func IsFillable(v any) bool

func PrepareFunc

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

func PrepareFuncCtx

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

func RegisterFactory(ctx context.Context, factory Factory)

func RegisterLazySingleton

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

func RegisterLazySingletonWith

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

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

func TestDependencyProviderContext() context.Context

Types

type DIValidator

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

func Validator

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

func (*DIValidator) Validate

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

type Dependant

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

type DependencyProvider

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

func GetDependencyProvider

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

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

func (*DependencyProvider) Validate

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

func (*DependencyProvider) Validator

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

type Factory

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

type FactoryFunc

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

func NewFactoryFunc

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

func (FactoryFunc[T]) Build

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

func (FactoryFunc[T]) Type

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

type FactoryFuncWith

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

func NewFactoryFuncWith

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

func (FactoryFuncWith[T, W]) Build

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

func (FactoryFuncWith[T, W]) DependsOn

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

func (FactoryFuncWith[T, W]) Type

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

type LazySingletonFactory

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

func NewLazySingletonFactory

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

func (*LazySingletonFactory[T]) Build

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

func (*LazySingletonFactory[T]) Peek

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

func (*LazySingletonFactory[T]) Type

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

type LazySingletonWithFactory

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

func NewLazySingletonWithFactory

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

func (*LazySingletonWithFactory[T, W]) Build

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

func (*LazySingletonWithFactory[T, W]) DependsOn

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

func (*LazySingletonWithFactory[T, W]) Peek

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

func (*LazySingletonWithFactory[T, W]) Type

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

type Singleton

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

func Singletons

func Singletons(ctx context.Context) []Singleton

type SingletonFactory

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

func NewSingletonFactory

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

func (*SingletonFactory[T]) Build

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

func (*SingletonFactory[T]) Peek

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

func (*SingletonFactory[T]) Type

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

type ValueFactory

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

func NewValueFactory

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

func (*ValueFactory) Build

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

func (*ValueFactory) Type

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

Jump to

Keyboard shortcuts

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