Expand description
Verdure IoC Container - Core IoC Module of the Verdure Ecosystem
This crate provides the foundational Inversion of Control (IoC) container functionality for the Verdure ecosystem framework. As the core dependency injection engine of Verdure, it enables the declarative, annotation-driven development model that powers the entire ecosystem.
§Ecosystem Integration
As a core module of the Verdure ecosystem, this IoC container integrates seamlessly with:
- verdure-web: Web framework components and request handling
- verdure-data: Repository and data access layer components
- verdure-config: Configuration-driven component initialization
- verdure-security: Authentication and authorization components
- verdure-boot: Auto-configuration and component discovery
§Core Features
- Ecosystem Foundation: Powers dependency injection across all Verdure modules
- Annotation-Driven:
#[derive(Component)]and#[autowired]for declarative configuration - Component Lifecycle: Comprehensive lifecycle management with singleton and prototype scopes
- Event System: Container lifecycle events for monitoring and debugging
- Circular Dependency Detection: Prevents infinite dependency loops
- Thread Safety: Full support for multi-threaded applications
- Zero-Cost Abstractions: Compile-time dependency resolution where possible
§Quick Start
use verdure_ioc::{ComponentContainer, ComponentFactory};
use std::sync::Arc;
// Create a container
let container = ComponentContainer::new();
// Register a component manually
#[derive(Debug)]
struct DatabaseService {
connection_string: String,
}
let db_service = Arc::new(DatabaseService {
connection_string: "postgres://localhost:5432/db".to_string(),
});
container.register_component(db_service);
// Retrieve the component
let retrieved_service: Option<Arc<DatabaseService>> = container.get_component();
assert!(retrieved_service.is_some());Macros§
- lifecycle_
listener - Macro for registering lifecycle event listeners
Structs§
- Component
Container - The central IoC container for the Verdure ecosystem
- Component
Definition - Definition structure for registering components with the container
- Lifecycle
Event Publisher - Publisher for container lifecycle events
- Lifecycle
Listener Definition - Static definition of a lifecycle event listener
Enums§
- Component
Scope - Enumeration of component lifecycle scopes
- Container
Lifecycle Event - Container lifecycle events enumeration
Traits§
- Component
Factory - Trait for retrieving components from a container
- Component
Initializer - Trait for components that can be automatically initialized by the container
- Lifecycle
Listener - Trait for implementing lifecycle event listeners
Type Aliases§
- Component
Instance - Type alias for component instances stored in the container