di

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 2 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

This section is empty.

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.

type Graph

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

Graph is a wrapper around dig.

func NewGraph

func NewGraph() *Graph

NewGraph creates a graph

func (*Graph) Invoke

func (g *Graph) Invoke(function interface{}) error

Invoke runs the given function after instantiating its dependencies. Any arguments that the function has are treated as its dependencies. The dependencies are instantiated in an unspecified order along with any dependencies that they might have. The function may return an error to indicate failure. The error will be returned to the caller as-is.

func (*Graph) Provide

func (g *Graph) Provide(constructor interface{}) error

Provide teaches the container how to build values of one or more types and expresses their dependencies. The first argument of Provide is a function that accepts zero or more parameters and returns one or more results. The function may optionally return an error to indicate that it failed to build the value. This function will be treated as the constructor for all the types it returns. This function will be called AT MOST ONCE when a type produced by it, or a type that consumes this function's output, is requested via Invoke. If the same types are requested multiple times, the previously produced value will be reused. In addition to accepting constructors that accept dependencies as separate arguments and produce results as separate return values, Provide also accepts constructors that specify dependencies as di.In structs and/or specify results as di.Out structs.

func (*Graph) String

func (g *Graph) String() string

String representation of the entire Container

type In

type In struct {
	dig.In
}

In is an alias of dig.In

type Module

type Module interface {
	// ModuleSentinel marks the type as a core module
	ModuleSentinel()
}

Module is a special interface. A type implements Module to indicate it is 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 a module is not created by core.Provide, there is no need to implements this interface.

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