Skip to content
/ diego Public

Simple dependency injection container for Go

Notifications You must be signed in to change notification settings

pipe01/diego

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

diego

diego is a simple dependency injection container for Go. It currently supports singleton and transient lifetimes.

Example usage:

func main() {
	c := diego.NewContainer()

	c.Register(NewA, diego.Transient)
	c.Register(NewB, diego.Transient)

	var b IntB
	c.MustGetInstance(&b)

	b.B()
}

type IntA interface {
	A()
}

type ImplA struct{}

func (*ImplA) A() {}

func NewA() *ImplA { return &ImplA{} }

type IntB interface {
	B()
}

type ImplB struct{ a IntA }

func (*ImplB) B() {}

func NewB(a IntA) *ImplB { return &ImplB{a} }

About

Simple dependency injection container for Go

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages