di alternatives and similar packages
Based on the "Dependency Injection" category.
Alternatively, view di alternatives based on common mentions on social networks and blogs.
-
IOC-golang
IOC-golang is a powerful golang dependency injection framework that provides a complete implementation of IoC containers. -
container
A lightweight yet powerful IoC dependency injection container for the Go programming language -
Kod
A generics based dependency injection application framework for Go, support OpenTelemetry trace/metric/log natively ๐๐๐
InfluxDB - Purpose built for real-time analytics at any scale.
Do you think we are missing an alternative of di or a related project?
Popular Comparisons
README
DI
Dependency injection for Go programming language.
[Tutorial](./docs/tutorial.md) | [Examples](./_examples) | [Advanced features](./docs/advanced.md)
Dependency injection is one form of the broader technique of inversion of control. It is used to increase modularity of the program and make it extensible.
This library helps you to organize responsibilities in your codebase and make it easy to combine low-level implementation into high-level behavior without boilerplate.
Features
- Intuitive auto wiring
- Interface implementations
- Constructor injection
- Optional injection
- Field injection
- Lazy-loading
- Tagging
- Grouping
- Cleanup
Documentation
You can use standard pkg.go.dev and inline code comments. If you do not have experience with auto-wiring libraries as google/wire, uber-go/dig or another - start with [tutorial](./docs/tutorial.md).
Install
go get github.com/goava/di
What it looks like
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/goava/di"
)
func main() {
di.SetTracer(&di.StdTracer{})
// create container
c, err := di.New(
di.Provide(NewContext), // provide application context
di.Provide(NewServer), // provide http server
di.Provide(NewServeMux), // provide http serve mux
// controllers as []Controller group
di.Provide(NewOrderController, di.As(new(Controller))),
di.Provide(NewUserController, di.As(new(Controller))),
)
// handle container errors
if err != nil {
log.Fatal(err)
}
// invoke function
if err := c.Invoke(StartServer); err != nil {
log.Fatal(err)
}
}
Full code available [here](./_examples/tutorial/main.go).
Questions
If you have any questions, feel free to create an issue.