rainier_container/lib.rs
1//! # rainier-container
2//!
3//! Rainier's inversion-of-control layer: the [`Container`] every component
4//! registers into, the [`ServiceProvider`] two-phase lifecycle that wires them
5//! together, the [`Application`] that drives it, and the [`Facade`] machinery
6//! that makes services reachable as static proxies.
7//!
8//! These four live in one crate because they are one idea,
9//! and because splitting them would only produce three crates that always
10//! travel together.
11//!
12//! ```
13//! use rainier_container::{Application, Container, ServiceProvider};
14//! use rainier_support::Result;
15//!
16//! struct Greeter { greeting: String }
17//! struct GreeterProvider;
18//!
19//! impl ServiceProvider for GreeterProvider {
20//! fn register(&self, app: &Application) -> Result<()> {
21//! app.singleton(|_: &Container| Ok(Greeter { greeting: "hello".into() }));
22//! Ok(())
23//! }
24//! }
25//!
26//! # #[tokio::main] async fn main() -> Result<()> {
27//! let app = Application::new(".");
28//! app.register(GreeterProvider)?;
29//! app.boot().await?;
30//!
31//! assert_eq!(app.resolve::<Greeter>()?.greeting, "hello");
32//! # Ok(()) }
33//! ```
34
35#![deny(missing_docs)]
36#![deny(rustdoc::broken_intra_doc_links)]
37
38pub mod application;
39pub mod container;
40pub mod facade;
41pub mod provider;
42
43pub use application::{Application, LifecycleHook};
44pub use container::Container;
45pub use facade::{
46 clear_facade_application, facade_application, scope_facade_application,
47 scoped_facade_application, set_facade_application, spawn_with_facades, task_facade_application,
48 try_facade_application, with_facade_application, Facade, FacadeScope,
49};
50pub use provider::ServiceProvider;
51
52/// Re-exports the `boot_provider!` macro expands to. Not a stable API.
53#[doc(hidden)]
54pub mod __private {
55 pub use rainier_support::{BoxFuture, Result};
56}