injectz

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 3 Imported by: 6

Documentation

Overview

Package injectz provides a simple, context-based dependency injection framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootstrap

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

Bootstrap builds and manages a group of Initializer.

func NewBootstrap

func NewBootstrap() *Bootstrap

NewBootstrap initializes a new *Bootstrap.

func (*Bootstrap) Add

func (i *Bootstrap) Add(initializers ...Initializer) *Bootstrap

Add one or more Initializer.

func (*Bootstrap) MustInitialize

func (i *Bootstrap) MustInitialize() (Injector, Releaser)

MustInitialize runs all the Initializer in the group, returns a compound Injector and Releaser.

type Initializer

type Initializer func(ctx context.Context) (Injector, Releaser)

Initializer initializes a module, returning a corresponding Injector and Releaser.

type Injector

type Injector func(ctx context.Context) context.Context

Injector injects modules into a context.Context.

func NewInjectors

func NewInjectors(injectors ...Injector) Injector

NewInjectors combines multiple Injector into a compound one.

func NewNoopInjector

func NewNoopInjector() Injector

NewNoopInjector returns an Injector that does nothing.

func NewSingletonInjector

func NewSingletonInjector(contextKey, value interface{}) Injector

NewSingletonInjector returns a constant Injector.

type Releaser

type Releaser func()

Releaser releases a module (e.g. closes DB connections).

func NewCloseReleaser

func NewCloseReleaser(closer io.Closer) Releaser

NewCloseReleaser returns a Releaser that calls io.Closer.Close, ignoring any returned error.

func NewNoopReleaser

func NewNoopReleaser() Releaser

NewNoopReleaser returns a Releaser that does nothing.

func NewReleasers

func NewReleasers(releasers ...Releaser) Releaser

NewReleasers combines multiple Releaser into a compound one (which invokes them in reverse order).

Directories

Path Synopsis
internal
tinjectz
Package tinjectz is a generated GoMock package.
Package tinjectz is a generated GoMock package.

Jump to

Keyboard shortcuts

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