1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! LRDI — Rust Dependency Injection Framework
//!
//! A dependency injection container for Rust inspired by
//! Microsoft.Extensions.DependencyInjection (MEDI).
//!
//! # Quick start
//!
//! ```rust
//! use rust_dicore::*;
//! use std::sync::Arc;
//!
//! struct Logger(String);
//! struct Worker { log: Arc<Logger> }
//!
//! let provider = ServiceCollection::new()
//! .singleton(|_| Arc::new(Logger("INFO".into())))
//! .singleton(|_| Arc::new(Worker { log: Arc::new(Logger("INFO".into())) }))
//! .build()
//! .unwrap();
//!
//! let logger: Arc<Logger> = provider.get::<Logger>();
//! ```
//!
//! # Features
//!
//! - **Three lifetimes**: Singleton, Scoped, Transient
//! - **Keyed services**: multiple instances of the same type, distinguished by key
//! - **Constructor injection**: `#[derive(Inject)]` on structs
//! - **Compile-time module scanning**: `#[rust_dicore::module]` collects service registrations
//! - **Cross-DLL support**: named service registry for cdylib plugins
//!
//! # Crate layout
//!
//! | Module | Description |
//! |--------|-------------|
//! | [`ServiceCollection`] | Register services with a builder API |
//! | [`ServiceProvider`] | The root DI container |
//! | [`Scope`] / [`ServiceScope`] | Scoped container (one per scope) |
//! | [`IServiceResolver`] | Resolution trait (implemented by `ServiceProvider` & `Scope`) |
//! | [`ServiceProviderWrapper`] | Child-first layered container |
//! | [`ServiceLifetime`] | Enum: Singleton, Scoped, Transient |
//! | [`IServiceLocator`] / [`ServiceLocatorBridge`] | Cross-DLL / plugin integration |
//! | [`RdiError`] | Error types |
//!
//! # Proc-macros
//!
//! - `#[derive(Inject)]` — auto-generates constructor injection code
//! - `#[rust_dicore::module]` — compile-time module scanning
//! - `rust_dicore::inject!(...)` — declare services inside `#[rust_dicore::module]`
// ── Core types (MEDI-inspired naming) ──
/// Service collection — register services, then call `.build()`.
///
/// Analogous to `IServiceCollection` in Microsoft.Extensions.DependencyInjection.
pub use ServiceCollection;
/// Built service provider — the root DI container (read-only after build).
///
/// Analogous to `IServiceProvider` in MEDI.
pub use ServiceProvider;
/// Service descriptor containing registration metadata.
pub use ServiceDescriptor;
/// Service lifetime enum: [`Singleton`](ServiceLifetime::Singleton),
/// [`Scoped`](ServiceLifetime::Scoped), [`Transient`](ServiceLifetime::Transient).
pub use ServiceLifetime;
/// Core resolution trait. Both [`ServiceProvider`] and [`Scope`] implement this.
pub use IServiceResolver;
/// A scoped service provider — created via [`ServiceProvider::create_scope`].
///
/// Analogous to `IServiceScope` in MEDI.
pub use Scope;
/// Alias for [`Scope`] with MEDI-inspired naming (`IServiceScope`).
pub use Scope as ServiceScope;
/// Internal types used by the container.
pub use ;
/// Wrapper combining child + root provider with child-first resolution.
pub use ServiceProviderWrapper;
// ── Plugin / cross-DLL support ──
/// Trait for service location (type-based + named) — used for external integration.
pub use IServiceLocator;
/// Trait for named service registration.
pub use INamedRegistrar;
/// Adapts RDI types to [`IServiceLocator`].
pub use ;
// ── Error types ──
/// Error types returned from service resolution.
pub use RdiError;
// ── Runtime registration ──
pub use ServiceRegistration;
/// Re-export of `inventory` so that `#[rust_dicore::inject]` generated code
/// can call `rust_dicore::inventory::submit!` without requiring downstream crates
/// to add `inventory` to their own `Cargo.toml`.
pub use inventory;
// ── Proc-macros ──
// Note: `inject_attr` is the attribute macro; `inject` is the declare macro
// used inside `#[rust_dicore::module]`. Users write both as `#[rust_dicore::inject(...)]`
// and `rust_dicore::inject!(...)` respectively.
pub use ;