pub trait AddServiceExt {
// Required methods
fn add_service<T>(&mut self) -> &mut Self
where T: Service + 'static;
fn has_service<T>(&self) -> bool
where T: Service + 'static;
}Expand description
Extension trait for AppBuilder to add service registration methods.
This trait provides convenient methods for registering services with the application builder. Services registered this way will be automatically built during the application build process according to their declared dependencies.
Required Methods§
Sourcefn add_service<T>(&mut self) -> &mut Selfwhere
T: Service + 'static,
fn add_service<T>(&mut self) -> &mut Selfwhere
T: Service + 'static,
Registers a service with the application builder.
The service will be built during the application build process and its handle will be available for injection into other services or retrieval from the final app.
§Type Parameters
T- The service type to register. Must implementService + 'static.
§Returns
Returns &mut Self for method chaining.
§Examples
use diode::{App, Service, AddServiceExt, StdError};
use std::sync::Arc;
struct MyService;
impl Service for MyService {
type Handle = Arc<Self>;
async fn build(_app: &diode::AppBuilder) -> Result<Self::Handle, StdError> {
Ok(Arc::new(Self))
}
}
let app = App::builder()
.add_service::<MyService>()
.build()
.await?;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.