Skip to main content

Module facade

Module facade 

Source
Expand description

Facades — static proxies onto container-resolved services.

In PHP, a facade can intercept an unknown static call and forward it to an object pulled from the container. Rust has no such hook, so a Rainier facade is a zero-sized type with inherent methods that each begin by resolving the underlying service:

ⓘ
pub struct Queue;
impl Facade for Queue { type Accessor = QueueManager; }

impl Queue {
    pub async fn push(job: impl Job) -> Result<JobId> {
        Self::instance().push(job).await     // <- resolve, then delegate
    }
}

The convenience is the same and so is the cost: a facade reaches into global state, which makes the dependency invisible at the call site. Prefer taking the service as a constructor argument in anything you intend to unit-test; reach for the facade in application code and route closures, where the ergonomics win.

§Testing

There is no separate swap mechanism, because there does not need to be: facades resolve through the container on every call, so rebinding the accessor swaps what every facade call sees from that point on.

ⓘ
app.instance(MailManager::fake());   // every `Mail::…` call now hits the fake

Structs§

FacadeScope
A facade scope, undone when it is dropped.

Traits§

Facade
A static proxy onto a container-resolved service.

Functions§

clear_facade_application
Forget the installed application. Mainly for tests that assert on the unbound behaviour.
facade_application
Panics
scope_facade_application
Resolve facades through app on this thread, until the guard drops.
scoped_facade_application
The innermost application scoped to this thread, if any.
set_facade_application
Install the application that facades resolve through.
spawn_with_facades
tokio::spawn, carrying the current facade application into the new task.
task_facade_application
The application scoped to this task, if any.
try_facade_application
The application facades resolve through, if one is installed.
with_facade_application
Resolve facades through app for the duration of future — wherever it runs.