di

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDependencyFactory       = errors.New("dependency factories must match the type di.DependencyFactory")
	ErrNotRegistered                  = errors.New("dependency not registered")
	ErrFillParameters                 = errors.New("invalid fill parameters")
	ErrDependencyProviderNotInContext = errors.New("DependencyProvider not in context")
)

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, opts ...FillOption) error

func Register

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

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 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 ResolveFill added in v0.9.0

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

func TestDependencyProviderContext added in v0.9.0

func TestDependencyProviderContext() context.Context

func Validate added in v0.11.0

func Validate(ctx context.Context, v any, opts ...FillOption) error

Types

type DependencyFactory

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

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, opts ...FillOption) error

func (*DependencyProvider) Register

func (d *DependencyProvider) Register(factory any)

factory should be of type DependencyFactory[T any] func(ctx context.Context, tag string) (T, error)

func (*DependencyProvider) Validate added in v0.11.0

func (dp *DependencyProvider) Validate(ctx context.Context, v any, opts ...FillOption) error

type FillOption

type FillOption func(*FillOptions) *FillOptions

func AutoResolve

func AutoResolve[T any]() FillOption

type FillOptions

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

type Fillable

type Fillable struct{}

func (*Fillable) IsFillable

func (*Fillable) IsFillable() bool

type IsFillabler

type IsFillabler interface {
	IsFillable() bool
}

Jump to

Keyboard shortcuts

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