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 fakeStructs§
- Facade
Scope - 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
appon 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
appfor the duration offuture— wherever it runs.