Flora Example: Basic Component Auto-Wiring
This example demonstrates the absolute core of the Flora DI framework: Zero-configuration auto-wiring.
The Concept
Normally, you would have to manually instantiate your dependencies and pass them into your constructors. With Flora, you simply embed the flora.Component tag into your structs.
Flora will automatically:
- Discover the struct.
- Find its constructor (
New...).
- Notice that
App requires a Greeter interface.
- Automatically bind
EnglishGreeter to the Greeter interface because it is the only implementation.
- Generate the boilerplate code to wire them together.
How to run
- Generate the DI container (
flora_container.go) in the current directory:
flora gen -o .
2. Run the application:
```bash
go run .
Expected Output
Starting the application...
Hello! Flora has successfully injected this component.