di

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 3 Imported by: 3

Documentation

Overview

Package di provides a reflection based dependency injection toolkit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder added in v0.0.5

type Builder func(reflect.Type) (reflect.Value, CleanUp, error)

Builder represents a builder function.

type CleanUp

type CleanUp func() error

CleanUp represents a clean up function.

func (CleanUp) Do

func (a CleanUp) Do() (err error)

Do does the clean up.

type Closer added in v0.0.2

type Closer interface {
	Close() error
}

Closer is the interface that wraps the basic Close method.

type Injector

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

Injector represents a dependency injector.

func New

func New(parent *Injector) *Injector

New creates a new injector.

func (*Injector) Close added in v0.0.2

func (a *Injector) Close() (err error)

Close frees up resources allocated for the injector.

func (*Injector) Invoke

func (a *Injector) Invoke(function any) (result Result, err error)

Invoke runs the given function after instantiating its dependencies.

func (*Injector) MustProvide

func (a *Injector) MustProvide(constructor any, itype any)

MustProvide is like Provide but panics if has error.

func (*Injector) Provide

func (a *Injector) Provide(constructor any, itype any) error

Provide teaches the injector how to build values and expresses their dependencies.

type Result

type Result []reflect.Value

Result represents a invoke result.

func (Result) Scan

func (a Result) Scan(vs ...any) (err error)

Scan copies the result into the values pointed at by vs.

Jump to

Keyboard shortcuts

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