di

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseInjector

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

BaseInjector holds instances registered with the injector.

func NewInjector

func NewInjector() *BaseInjector

NewInjector creates a new injector.

func (*BaseInjector) Register

func (i *BaseInjector) Register(name string, instance interface{})

Register registers an instance with the injector.

func (*BaseInjector) Resolve

func (i *BaseInjector) Resolve(name string) interface{}

Resolve resolves an instance from the injector.

func (*BaseInjector) ResolveAll

func (i *BaseInjector) ResolveAll(targetType interface{}) ([]interface{}, error)

ResolveAll resolves all instances that match the given interface.

type Injector

type Injector interface {
	Register(name string, instance interface{})
	Resolve(name string) interface{}
	ResolveAll(targetType interface{}) ([]interface{}, error)
}

Injector defines the methods for the injector.

type MockInjector

type MockInjector struct {
	*BaseInjector
	// contains filtered or unexported fields
}

MockInjector extends the RealInjector with additional testing functionality

func NewMockInjector

func NewMockInjector() *MockInjector

NewMockInjector creates a new mock DI injector

func (*MockInjector) Resolve

func (m *MockInjector) Resolve(name string) interface{}

Resolve overrides the RealInjector's Resolve method to add error simulation

func (*MockInjector) ResolveAll

func (m *MockInjector) ResolveAll(targetType interface{}) ([]interface{}, error)

ResolveAll overrides the RealInjector's ResolveAll method to add error simulation

func (*MockInjector) SetResolveAllError

func (m *MockInjector) SetResolveAllError(targetType interface{}, err error)

SetResolveAllError sets a specific error to be returned when resolving all instances of a specific type

Jump to

Keyboard shortcuts

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