dingo: flamingo.me/dingo Index | Files | Directories

package dingo

import "flamingo.me/dingo"

Index

Package Files

binding.go dingo.go inspect.go module.go scope.go

Constants

const (
    // INIT state
    INIT = iota
    // DEFAULT state
    DEFAULT
)

func EnableCircularTracing Uses

func EnableCircularTracing()

EnableCircularTracing activates dingo's trace feature to find circular dependencies this is super expensive (memory wise), so it should only be used for debugging purposes

func TryModule Uses

func TryModule(modules ...Module) (resultingError error)

TryModule tests if modules are properly bound

type Binding Uses

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

Binding defines a type mapped to a more concrete type

func (*Binding) AnnotatedWith Uses

func (b *Binding) AnnotatedWith(annotation string) *Binding

AnnotatedWith sets the binding's annotation

func (*Binding) AsEagerSingleton Uses

func (b *Binding) AsEagerSingleton() *Binding

AsEagerSingleton set's the binding to singleton and requests eager initialization

func (*Binding) In Uses

func (b *Binding) In(scope Scope) *Binding

In set's the bindings scope

func (*Binding) To Uses

func (b *Binding) To(what interface{}) *Binding

To binds a concrete type to a binding

func (*Binding) ToInstance Uses

func (b *Binding) ToInstance(instance interface{}) *Binding

ToInstance binds an instance to a binding

func (*Binding) ToProvider Uses

func (b *Binding) ToProvider(p interface{}) *Binding

ToProvider binds a provider to an instance. The provider's arguments are automatically injected

type ChildSingletonScope Uses

type ChildSingletonScope SingletonScope

ChildSingletonScope manages child-specific singleton

func NewChildSingletonScope Uses

func NewChildSingletonScope() *ChildSingletonScope

NewChildSingletonScope creates a new child singleton scope

func (*ChildSingletonScope) ResolveType Uses

func (c *ChildSingletonScope) ResolveType(t reflect.Type, annotation string, unscoped func(t reflect.Type, annotation string, optional bool) (reflect.Value, error)) (reflect.Value, error)

ResolveType delegates to SingletonScope.ResolveType

type Depender Uses

type Depender interface {
    Depends() []Module
}

Depender defines a dependency-aware module

type Injector Uses

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

Injector defines bindings and multibindings it is possible to have a parent-injector, which can be asked if no resolution is available

func NewInjector Uses

func NewInjector(modules ...Module) (*Injector, error)

NewInjector builds up a new Injector out of a list of Modules

func (*Injector) Bind Uses

func (injector *Injector) Bind(what interface{}) *Binding

Bind creates a new binding for an abstract type / interface Use the syntax

injector.Bind((*Interface)(nil))

To specify the interface (cast it to a pointer to a nil of the type Interface)

func (*Injector) BindInterceptor Uses

func (injector *Injector) BindInterceptor(to, interceptor interface{})

BindInterceptor intercepts to interface with interceptor

func (*Injector) BindMap Uses

func (injector *Injector) BindMap(what interface{}, key string) *Binding

BindMap does a registry-like map-based binding, like BindMulti

func (*Injector) BindMulti Uses

func (injector *Injector) BindMulti(what interface{}) *Binding

BindMulti binds multiple concrete types to the same abstract type / interface

func (*Injector) BindScope Uses

func (injector *Injector) BindScope(s Scope)

BindScope binds a scope to be aware of

func (*Injector) BuildEagerSingletons Uses

func (injector *Injector) BuildEagerSingletons(includeParent bool) error

BuildEagerSingletons requests one instance of each singleton, optional letting the parent injector(s) do the same

func (*Injector) Child Uses

func (injector *Injector) Child() (*Injector, error)

Child derives a child injector with a new ChildSingletonScope

func (*Injector) GetAnnotatedInstance Uses

func (injector *Injector) GetAnnotatedInstance(of interface{}, annotatedWith string) (interface{}, error)

GetAnnotatedInstance creates a new instance of what was requested with the given annotation

func (*Injector) GetInstance Uses

func (injector *Injector) GetInstance(of interface{}) (interface{}, error)

GetInstance creates a new instance of what was requested

func (*Injector) InitModules Uses

func (injector *Injector) InitModules(modules ...Module) error

InitModules initializes the injector with the given modules

func (*Injector) Inspect Uses

func (injector *Injector) Inspect(inspector Inspector)

Inspect the injector

func (*Injector) Override Uses

func (injector *Injector) Override(what interface{}, annotatedWith string) *Binding

Override a binding

func (*Injector) RequestInjection Uses

func (injector *Injector) RequestInjection(object interface{}) error

RequestInjection requests the object to have all fields annotated with `inject` to be filled

func (*Injector) SetBuildEagerSingletons Uses

func (injector *Injector) SetBuildEagerSingletons(build bool)

SetBuildEagerSingletons can be used to disable or enable building of eager singletons during InitModules

type Inspector Uses

type Inspector struct {
    InspectBinding      func(of reflect.Type, annotation string, to reflect.Type, provider, instance *reflect.Value, in Scope)
    InspectMultiBinding func(of reflect.Type, index int, annotation string, to reflect.Type, provider, instance *reflect.Value, in Scope)
    InspectMapBinding   func(of reflect.Type, key string, annotation string, to reflect.Type, provider, instance *reflect.Value, in Scope)
    InspectParent       func(parent *Injector)
}

Inspector defines callbacks called during injector inspection

type Instance Uses

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

Instance holds quick-references to type and value

type Module Uses

type Module interface {
    Configure(injector *Injector)
}

Module is provided by packages to generate the DI tree

type Provider Uses

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

Provider holds the provider function

func (*Provider) Create Uses

func (p *Provider) Create(injector *Injector) (reflect.Value, error)

Create creates a new instance by the provider and requests injection, all provider arguments are automatically filled

type Scope Uses

type Scope interface {
    ResolveType(t reflect.Type, annotation string, unscoped func(t reflect.Type, annotation string, optional bool) (reflect.Value, error)) (reflect.Value, error)
}

Scope defines a scope's behaviour

var (
    // Singleton is the default SingletonScope for dingo
    Singleton Scope = NewSingletonScope()

    // ChildSingleton is a per-child singleton, means singletons are scoped and local to an injector instance
    ChildSingleton Scope = NewChildSingletonScope()
)

type SingletonScope Uses

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

SingletonScope is our Scope to handle Singletons todo use RWMutex for proper locking

func NewSingletonScope Uses

func NewSingletonScope() *SingletonScope

NewSingletonScope creates a new singleton scope

func (*SingletonScope) ResolveType Uses

func (s *SingletonScope) ResolveType(t reflect.Type, annotation string, unscoped func(t reflect.Type, annotation string, optional bool) (reflect.Value, error)) (reflect.Value, error)

ResolveType resolves a request in this scope

Directories

PathSynopsis
example
example/application
example/paypal
miniexample
miniexample/logger

Package dingo imports 6 packages (graph) and is imported by 55 packages. Updated 2020-02-18. Refresh now. Tools for package owners.