Flora offers a streamlined solution for Dependency Injection in Go by automating wiring at compile time. This framework eliminates the trade-off between complicated manual wiring and the unpredictability of runtime reflection. Experience fast startup and enhanced safety with a strongly-typed container generated from your code’s structure.
Flora is a cutting-edge dependency injection framework tailored for Go, focusing on automated wiring and delivering zero runtime overhead while eliminating complex runtime magic.
Flora’s usage is straightforward. Developers define dependencies directly alongside their structures, significantly simplifying the initialization of complex applications. Here is an example:
package main
import "github.com/soner3/flora"
// Greeter component
type Greeter struct {
flora.Component
}
// Constructor for Greeter
func NewGreeter() *Greeter {
return &Greeter{}
}
func (g *Greeter) Greet() string { return "Hello from Flora!" }
// Application component
type App struct {
flora.Component
greeter *Greeter
}
// Flora wires the Greeter dependency automatically.
func NewApp(g *Greeter) *App {
return &App{greeter: g}
}
To generate the dependency container, run the following command:
flora gen -i . -o .
Flora utilizes two primary markers:
Additional advanced features include:
To deepen understanding, visit the examples directory for runnable scenarios that cover a range of use cases from basic components to fully-featured REST APIs.
Flora is designed to enhance developer productivity and provide robust performance in Go applications, allowing seamless integration and management of dependencies.
No comments yet.
Sign in to be the first to comment.