dep

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EHealthCheckTimeout todo
	EHealthCheckTimeout = errors.PersistentCode(errors.DDependency, errors.ATimeout)
)

Functions

func Name

func Name(parts ...string) string

Types

type Container

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

func NewContainer

func NewContainer(name string) *Container

func (*Container) Manifest

func (c *Container) Manifest() async.Manifest

func (*Container) UnsafeExecute added in v0.1.3

func (c *Container) UnsafeExecute(ctx context.Context, fn any) error

func (*Container) Use

func (c *Container) Use(modules ...Module) *Container

type Dependency

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

func NewFactory

func NewFactory(value any) (*Dependency, error)

func NewInstance

func NewInstance(kind reflect.Type) (*Dependency, error)

func NewSideEffect

func NewSideEffect(value any) (*Dependency, error)

func (*Dependency) HasIO

func (d *Dependency) HasIO() bool

func (*Dependency) ID

func (d *Dependency) ID() xid.ID

func (*Dependency) Kind

func (d *Dependency) Kind() Kind

func (*Dependency) Name

func (d *Dependency) Name() string

func (*Dependency) Solve

func (d *Dependency) Solve(value any, err error)

func (*Dependency) Status

func (d *Dependency) Status() Status

func (*Dependency) Value

func (d *Dependency) Value() (any, error)

type Graph

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

func NewGraph

func NewGraph(topo *topo.Graph, registry *Registry) *Graph

func (*Graph) Solve

func (g *Graph) Solve(ctx context.Context) error

Solve solves the dependency DAG and instantiate it todo: check that toposort works

func (*Graph) UnsafeExecute added in v0.1.3

func (g *Graph) UnsafeExecute(ctx context.Context, fn interface{}) error

type GraphBuilder

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

func NewGraphBuilder

func NewGraphBuilder() *GraphBuilder

func (*GraphBuilder) Build

func (g *GraphBuilder) Build(ctx context.Context, modules ...Module) (*Graph, error)

type InstanceContainer

type InstanceContainer struct {
	sync.RWMutex
	Type  reflect.Type
	Value any
}

func (*InstanceContainer) String

func (i *InstanceContainer) String() string

type Kind

type Kind int
const (
	//Factory represent a dependency which can instantiate new dependencies.
	//This is the entrypoint to the whole DI system and the solver will try to associate every declare Instance with
	//their own Factory.
	//Do not declare a Factory which uses scalar types like `int32` or `[]string{}`, always use opaque types or rethink
	//your implementation.
	//Factory should be implemented with a pure function, with no side-effects. If you need to mutate external state
	//use SideEffect instead.
	//Factory should only be used to declare heavy-lifter objects (services, drivers, resources) which have complex
	//lifecycles, or depends on each other.
	Factory Kind = iota
	//SideEffect is a dependency which should be invoked whenever the DI system has finished bootstrapping.
	SideEffect
	//Instance represent the actual value of the dependency, used and created by both factories and transitives
	Instance
)

type Module

type Module struct {
	Name        string
	Factories   []any
	SideEffects []any
}

func Declare

func Declare(name string, options ...ModuleOption) Module

func (Module) Print

func (m Module) Print() string

type ModuleOption

type ModuleOption func(module *Module)

func Factories

func Factories(exports ...any) ModuleOption

func SideEffects

func SideEffects(invocation ...any) ModuleOption

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) FindByName

func (r *Registry) FindByName(name string) (*Dependency, bool)

func (*Registry) Get

func (r *Registry) Get(id xid.ID) (*Dependency, bool)

func (*Registry) Kind

func (r *Registry) Kind(kinds ...Kind) []*Dependency

func (*Registry) Lookup

func (r *Registry) Lookup(dependency *Dependency) (xid.ID, bool)

func (*Registry) Register

func (r *Registry) Register(dependency *Dependency) error

type Status

type Status int
const (
	NewStatus Status = iota
	InitialisedStatus
	CorruptedStatus
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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