#[service]Expand description
Mark a trait as a service for the App container
This attribute macro automatically adds Send + Sync + 'static bounds
to your trait, making it suitable for use with the dependency injection
container.
§Example
ⓘ
use kit::service;
#[service]
pub trait HttpClient {
async fn get(&self, url: &str) -> Result<String, Error>;
}
// This expands to:
pub trait HttpClient: Send + Sync + 'static {
async fn get(&self, url: &str) -> Result<String, Error>;
}Then you can use it with the App container:
ⓘ
// Register
App::bind::<dyn HttpClient>(Arc::new(RealHttpClient::new()));
// Resolve
let client: Arc<dyn HttpClient> = App::make::<dyn HttpClient>().unwrap();