di

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Binding_Instance bindingtype = iota
	Binding_Singleton
)

Variables

View Source
var GlobalInjector = NewInjector()

GlobalInjector is the global repository of bindings

Functions

func Call

func Call(receiver interface{})

Call takes a function (receiver) with one or more arguments of the abstractions (interfaces). It invokes the function (receiver) and passes the related implementations.

func DisableDebugLogging

func DisableDebugLogging()

DisableDebugLogging disables debug logging.

func EnableDebugLogging

func EnableDebugLogging()

EnableDebugLogging enables debug logging.

func Fill

func Fill(receiver interface{})

Fill takes a struct and resolves the fields with the tag `container:"inject"`

func Instance

func Instance(resolver interface{})

Instance binds an abstraction to concrete for further transient resolves. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Injector already.

func NamedInstance

func NamedInstance(name string, resolver interface{})

NamedInstance binds like the Instance method but for named bindings.

func NamedResolve

func NamedResolve(abstraction interface{}, name string)

NamedResolve resolves like the Resolve method but for named bindings.

func NamedSingleton

func NamedSingleton(name string, resolver interface{})

NamedSingleton binds like the Singleton method but for named bindings.

func Reset

func Reset()

Reset deletes all the existing bindings and empties the container instance.

func Resolve

func Resolve(abstraction interface{})

Resolve takes an abstraction (interface reference) and fills it with the related implementation.

func SetErrorHandler

func SetErrorHandler(handler errorHandler)

SetErrorHandler sets the global error handler

func SetLogger

func SetLogger(logger log.Logger)

SetLogger attaches a custom logger.

func Singleton

func Singleton(resolver interface{})

Singleton binds an abstraction to concrete for further singleton resolves. It takes a resolver function that returns the concrete, and its return type matches the abstraction (interface). The resolver function can have arguments of abstraction that have been declared in the Injector already.

Types

type Injector

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

Injector holds all of the declared bindings

func NewInjector

func NewInjector() *Injector

NewInjector creates a new instance of the Injector

func (*Injector) Call

func (injector *Injector) Call(function interface{})

Call takes a function (receiver) with one or more arguments of the abstractions (interfaces). It invokes the function (receiver) and passes the related implementations.

func (*Injector) DisableDebugLogging

func (injector *Injector) DisableDebugLogging()

DisableDebugLogging disables debug logging.

func (*Injector) EnableDebugLogging

func (injector *Injector) EnableDebugLogging()

EnableDebugLogging enables debug logging.

func (*Injector) Fill

func (injector *Injector) Fill(structure interface{})

Fill takes a struct and resolves the fields with the tag `di:"inject"`

func (*Injector) Instance

func (injector *Injector) Instance(provider interface{}) *Injector

Instance binds an abstraction to concrete for further transient resolves. It takes a provider function that returns the concrete, and its return type matches the abstraction (interface). The provider function can have arguments of abstraction that have been declared in the Injector already.

func (*Injector) NamedInstance

func (injector *Injector) NamedInstance(name string, provider interface{}) *Injector

NamedInstance binds like the Instance method but for named bindings.

func (*Injector) NamedResolve

func (injector *Injector) NamedResolve(abstraction interface{}, name string)

NamedResolve resolves like the Resolve method but for named bindings.

func (*Injector) NamedSingleton

func (injector *Injector) NamedSingleton(name string, provider interface{}) *Injector

NamedSingleton binds like the Singleton method but for named bindings.

func (*Injector) Reset

func (injector *Injector) Reset()

Reset deletes all the existing bindings from the injector instance.

func (*Injector) Resolve

func (injector *Injector) Resolve(abstraction interface{})

Resolve takes an abstraction (interface reference) and fills it with the related implementation.

func (*Injector) SetErrorHandler

func (injector *Injector) SetErrorHandler(handler errorHandler)

SetErrorHandler sets the injectors error handler

func (*Injector) SetLogger

func (injector *Injector) SetLogger(logger log.Logger)

SetLogger sets the injectors logger

func (*Injector) Singleton

func (injector *Injector) Singleton(provider interface{}) *Injector

Singleton binds an abstraction to concrete for further singleton resolves. It takes a provider function that returns the concrete, and its return type matches the abstraction (interface). The provider function can have arguments of abstraction that have been declared in the Injector already.

Jump to

Keyboard shortcuts

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