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
//! # Fibre IoC
//!
//! A flexible, thread-safe, and dynamic Inversion of Control (IoC) container for Rust.
//!
//! Fibre IoC provides a way to manage dependencies within your application. Unlike some
//! other containers that require a single, upfront initialization, Fibre IoC allows
//! for dynamic registration of services at any point during the application's lifecycle.
//!
//! ## Core Concepts
//!
//! - **Container**: The central registry for all your services.
//! - **Global Container**: A static, globally-available container, accessible via `global()`.
//! - **Resolution**: Services are resolved using the `resolve!` macro, which panics
//! if a dependency is missing.
//! - **Traits**: Services can be registered against a trait and resolved as a trait object.
//!
//! ## Quick Start
//!
//! ```
//! use fibre_ioc::{global, resolve};
//! use std::sync::Arc;
//!
//! // Define a trait and a concrete implementation.
//! trait Greeter {
//! fn greet(&self) -> String;
//! }
//!
//! struct EnglishGreeter {
//! message: String,
//! }
//!
//! impl Greeter for EnglishGreeter {
//! fn greet(&self) -> String {
//! self.message.clone()
//! }
//! }
//!
//! fn main() {
//! // Register a simple value from anywhere in your app.
//! global().add_singleton(Some("greeting_message"), || String::from("Hello, World!"));
//!
//! // Register a service that implements a trait.
//! // The factory can itself resolve other dependencies.
//! global().add_singleton_trait::<dyn Greeter, _>(None, || {
//! let message = resolve!(String, "greeting_message");
//! EnglishGreeter { message: (*message).clone() }
//! });
//!
//! // In another part of your application, resolve the service by its trait.
//! let greeter_service = resolve!(trait Greeter);
//!
//! assert_eq!(greeter_service.greet(), "Hello, World!");
//! println!("{}", greeter_service.greet());
//! }
//! ```
pub use Container;
pub use global;
pub use LocalContainer;