Skip to main content

Crate verdure_ioc

Crate verdure_ioc 

Source
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§

ComponentContainer
The central IoC container for the Verdure ecosystem
ComponentDefinition
Definition structure for registering components with the container
LifecycleEventPublisher
Publisher for container lifecycle events
LifecycleListenerDefinition
Static definition of a lifecycle event listener

Enums§

ComponentScope
Enumeration of component lifecycle scopes
ContainerLifecycleEvent
Container lifecycle events enumeration

Traits§

ComponentFactory
Trait for retrieving components from a container
ComponentInitializer
Trait for components that can be automatically initialized by the container
LifecycleListener
Trait for implementing lifecycle event listeners

Type Aliases§

ComponentInstance
Type alias for component instances stored in the container