di

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MPL-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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