Help us shape the future of Go! Take the 2026 Go Developer Survey

betterdep

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 1 Imported by: 1

README

betterdep

一个简单的依赖注入系统

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PreRegister

func PreRegister[T any](dp *DependencyManager, dep Dependency[T]) error

func Provide

func Provide[T any](dp *DependencyManager, dep *Dependency[T]) (T, error)

func Register

func Register[T any](dp *DependencyManager, dep Dependency[T], instance T, dispose func())

Types

type Dependency

type Dependency[T any] struct {
	Identifier string
	Resolver   func(*DependencyManager) (T, func(), error)
}

type DependencyManager

type DependencyManager struct {
	Cache        sync.Map
	DisposeFuncs []func()
}

func NewDependencyManager

func NewDependencyManager() *DependencyManager

func (*DependencyManager) Dispose

func (dp *DependencyManager) Dispose()

func (*DependencyManager) PreRegister

func (dp *DependencyManager) PreRegister(dep Dependency[any])

func (*DependencyManager) Provide

func (dp *DependencyManager) Provide(dep *Dependency[any]) (any, error)

func (*DependencyManager) Register

func (dp *DependencyManager) Register(dep Dependency[any], instance any, dispose func())

Jump to

Keyboard shortcuts

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