Getting Started
Install Remy DI in your Go project (requires Go 1.20+):
1
| go get github.com/wrapped-owls/goremy-di/remy
|
Here’s a simple example to get you started:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| package main
import (
"log"
"github.com/wrapped-owls/goremy-di/remy"
)
var Injector = remy.NewInjector()
func init() {
// Register a service as singleton
remy.RegisterSingleton(Injector, func(retriever remy.DependencyRetriever) (string, error) {
return "Hello, Remy!", nil
})
}
func main() {
// Retrieve the service
message := remy.MustGet[string](Injector)
log.Println(message) // Output: Hello, Remy!
}
|
- Injector: The container that manages your dependencies. You can create multiple injectors or use the global one.
- Registration: Register your services during application startup using one of the bind types.
- Retrieval: Get your registered services anywhere in your code using type-safe generic functions.