Skip to main content

Crate rainier_container

Crate rainier_container 

Source
Expand description

§rainier-container

Rainier’s inversion-of-control layer: the Container every component registers into, the ServiceProvider two-phase lifecycle that wires them together, the Application that drives it, and the Facade machinery that makes services reachable as static proxies.

These four live in one crate because they are one idea, and because splitting them would only produce three crates that always travel together.

use rainier_container::{Application, Container, ServiceProvider};
use rainier_support::Result;

struct Greeter { greeting: String }
struct GreeterProvider;

impl ServiceProvider for GreeterProvider {
    fn register(&self, app: &Application) -> Result<()> {
        app.singleton(|_: &Container| Ok(Greeter { greeting: "hello".into() }));
        Ok(())
    }
}

let app = Application::new(".");
app.register(GreeterProvider)?;
app.boot().await?;

assert_eq!(app.resolve::<Greeter>()?.greeting, "hello");

Re-exports§

pub use application::Application;
pub use application::LifecycleHook;
pub use container::Container;
pub use facade::clear_facade_application;
pub use facade::facade_application;
pub use facade::scope_facade_application;
pub use facade::scoped_facade_application;
pub use facade::set_facade_application;
pub use facade::spawn_with_facades;
pub use facade::task_facade_application;
pub use facade::try_facade_application;
pub use facade::with_facade_application;
pub use facade::Facade;
pub use facade::FacadeScope;
pub use provider::ServiceProvider;

Modules§

application
The Application — the container plus a lifecycle.
container
The IoC Container — Rainier’s service locator and the thing every component registers itself into.
facade
Facades — static proxies onto container-resolved services.
provider
ServiceProvider — the unit of framework wiring.

Macros§

boot_provider
Implements ServiceProvider::boot from an async fn, so a provider can be written with ordinary async syntax instead of hand-boxing the future.
facade
Declare a facade type and its Facade impl.