di

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 8 Imported by: 10

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)

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

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)

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