Skip to main content

ServiceProvider

Trait ServiceProvider 

Source
pub trait ServiceProvider:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn name(&self) -> &'static str { ... }
    fn register(&self, app: &Application) -> Result<(), Error> { ... }
    fn boot<'a>(
        &'a self,
        app: &'a Application,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> { ... }
}
Expand description

A bundle of related bindings and their boot-time wiring.

struct Clock;
struct ClockProvider;

impl ServiceProvider for ClockProvider {
    fn register(&self, app: &Application) -> Result<()> {
        app.singleton(|_: &Container| Ok(Clock));
        Ok(())
    }
}

Provided Methods§

Source

fn name(&self) -> &'static str

A label for diagnostics and provider:list. Defaults to the Rust type name.

Source

fn register(&self, app: &Application) -> Result<(), Error>

Bind services into the container.

Runs for every provider before any provider boots. Do not resolve here.

Source

fn boot<'a>( &'a self, app: &'a Application, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Wire things together once every provider has registered.

Safe to resolve from. Returns a boxed future so the trait stays object-safe — providers are held as Arc<dyn ServiceProvider>.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§