/godi

Primary LanguageGoGNU General Public License v3.0GPL-3.0

GoDi: The simplest Dependency Injection for Golang

Diagram

diagram

Simple usage

package main

import "github.com/AmbroseNTK/godi/injector"

func main() {
    injector.Init()
    // Provide your dependencies with their constructor
    injector.ProvideLazy[*StructA](NewStructA)
	injector.Provide[*InterfaceX](NewStructB)
    //...

    // Get your dependencies
    objA := injector.Get[*StructA]()

    // Get new object with dependencies injected by fields
    objB := injector.Inject[*StructB]()
}