Verdure
English | 简体中文
Verdure - An ecosystem framework for Rust.
True to its name, Verdure aims to be a vibrant and thriving ecosystem framework, dedicated to facilitating convenient and efficient Rust development.
The project is currently in the foundational development phase. We are looking for enthusiastic contributors to join us in building it.
Features
- IoC container and container event listening
- Dependency Injection (DI)
- Automatic Configuration
- AOP (Aspect-Oriented Programming)
- Context
- And more...
Add Dependency
= "0.0.1"
= "0.3"
The underlying implementation heavily relies on inventory. Our thanks go to the authors of this excellent repository.
IoC / DI
Initialize the Container
use Arc;
Register a Component
Automatic Registration and Injection (Derive)
Adding the #[derive(Component)] macro to a struct automatically registers it with the container as a singleton by default. For fields marked with the #[autowired] attribute, an instance will be automatically retrieved from the container and injected.
use Component;
There are two important points to note:
- The field to be injected must be wrapped in an
Arc<T>. - Fields that do not require injection must either be of type
Option<T>or implement theDefaulttrait.
Manual Registration and Component Retrieval
Container Event Listening
Using the Macro
lifecycle_listener!;