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: Compile-Time Dependency Injection for Go
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.
Key Features
- Compile-Time Evaluation: Flora distinguishes itself by evaluating dependencies at compile time. If the Go code compiles successfully, the dependency graph is guaranteed to be safe, thereby preventing runtime errors related to missing dependencies.
- Automated Dependency Discovery: With a simple marker, Flora scans your components for dependencies, generating a strongly-typed dependency injection container powered by Google Wire. Developers can focus on building applications without the burden of cumbersome wiring.
- Performance and Safety: The generated container operates at the same speed and memory efficiency as manually written Go code, providing the best of both worlds—a modern development experience with maximum performance.
Getting Started
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 .
Core Concepts
Flora utilizes two primary markers:
- flora.Component: For user-defined structures, Flora automatically manages component lifecycles and resolves dependencies.
- flora.Configuration: Used for third-party structures which cannot be modified. Configuration can be completed using magic comments to define provider methods without altering the original structures.
Additional advanced features include:
- Clean Architecture Compatibility: Flora supports Go Type Aliases to maintain clear separation between domain logic and external frameworks, preserving the integrity of the application's architecture.
- Multi-Binding for Extensibility: Easily inject slices of dependencies, allowing for scalable architecture design without tedious manual wiring.
Explore More
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.