di

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 8 Imported by: 9

Documentation

Overview

Package di is a thin wrapper around dig. See https://github.com/uber-go/dig

This package is not intended for direct usage. Only use it for libraries written for package core.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As added in v0.10.0

func As(constructor interface{}, as interface{}) interface{}

As constructs the instance and bind it to another interface. As means to be used as an argument to graph.Provide. For example:

As(MyConstructor, new(MyAbstractInterface))

func Bind added in v0.9.0

func Bind(from interface{}, to interface{}) interface{}

Bind binds a type to another. Useful when binding implementation to interfaces. The arguments should be a ptr to the binding types, rather than the types themselves. For example:

Bind(new(MyConcreteStruct), new(MyAbstractInterface))

func IntoPopulator added in v0.9.0

func IntoPopulator(container *dig.Container) contract.DIPopulator

IntoPopulator converts a *dig.Container to contract.DIPopulator.

func LocationForPC added in v0.10.0

func LocationForPC(constructor interface{}, pc uintptr) interface{}

LocationForPC sets the constructor pointer to a specified location. Use this Options to reduce vague debug message when constructor are made by reflect.makeFunc. For example:

LocationForPC(reflect.makeFunc(...), reflect.ValueOf(realConstructor).Pointer())

func Name added in v0.10.0

func Name(constructor interface{}, name string) interface{}

Name constructs a named instance. Name means to be used as an argument to graph.Provide. For example:

Name(MyConstructor, "foo")

Types

type Deps added in v0.2.0

type Deps []interface{}

Deps is a set of providers grouped together. This is used by core.Provide method to identify provider sets.

type Factory

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

Factory is a concurrent safe, generic factory for databases and connections.

func NewFactory

func NewFactory(constructor func(name string) (Pair, error)) *Factory

NewFactory creates a new factory.

func (*Factory) Close

func (f *Factory) Close()

Close closes every connection created by the factory. Connections are closed concurrently.

func (*Factory) CloseConn

func (f *Factory) CloseConn(name string)

CloseConn closes a specific connection in the factory.

func (*Factory) List

func (f *Factory) List() map[string]Pair

List lists created instance in the factory.

func (*Factory) Make

func (f *Factory) Make(name string) (interface{}, error)

Make creates an instance under the provided name. It an instance is already created and it is not nil, that instance is returned to the caller.

func (*Factory) SubscribeReloadEventFrom added in v0.7.0

func (f *Factory) SubscribeReloadEventFrom(dispatcher contract.Dispatcher)

SubscribeReloadEventFrom subscribes to the reload events from dispatcher and then notifies the di factory to clear its cache and shutdown all connections gracefully.

type In

type In struct {
	dig.In
}

In is an alias of dig.In

type Modular added in v0.9.0

type Modular interface {
	// Module returns a core module
	Module() interface{}
}

Modular is a special interface. A type implements Modular to indicate it contains a valid core module. This property is examined and executed by the core.Provide in package core. Other than that, the interface bears no further meaning.

If the module is not a by-product of dependency construction via core.Provide, then there is no need to use this mechanism.

type OptionalProvider added in v0.10.0

type OptionalProvider struct {
	Constructor interface{}
	Options     []dig.ProvideOption
}

OptionalProvider is a struct with constructor and dig options. When OptionalProvider is used as the element in di.Deps, the options are applied to the inner dig.Container automatically.

type Out

type Out struct {
	dig.Out
}

Out is an alias of dig.Out

type Pair

type Pair struct {
	Conn   interface{}
	Closer func()
}

Pair is a tuple representing a connection and a closer function

Jump to

Keyboard shortcuts

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