di

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package di provides a reflection-based dependency injection toolkit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Catch

func Catch(format string, err *error)

Catch catches the panic and format the error.

Types

type Builder

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

Builder represents a injector builder.

func New

func New(parent *Injector) *Builder

New creates a new builder.

func (*Builder) AddScoped

func (a *Builder) AddScoped(constructor any, itype any) *Builder

AddScoped adds a scoped service.

func (*Builder) AddShared

func (a *Builder) AddShared(constructor any, itype any) *Builder

AddShared adds a shared service.

func (*Builder) AddValue

func (a *Builder) AddValue(value any, itype any) *Builder

AddValue adds a value service.

func (*Builder) Build

func (a *Builder) Build() (injector *Injector, err error)

Build builds the injector.

func (*Builder) SetCreator

func (a *Builder) SetCreator(creator Creator) *Builder

SetCreator sets the creator.

type Clean

type Clean func() error

Clean represents a clean function.

func (Clean) Do

func (a Clean) Do() (err error)

Do does the clean up.

type Closer

type Closer interface {
	Close() error
}

Closer is the interface that wraps the basic Close method.

type Creator

type Creator func(reflect.Type) (reflect.Value, error)

Creator represents a creator function.

type Injector

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

Injector represents a dependency injector.

func (*Injector) Clone

func (a *Injector) Clone() *Injector

Clone clones the injector.

func (*Injector) Close

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

Close closes 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) Resolve

func (a *Injector) Resolve(vs ...any) (err error)

Resolve resolves the 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