pub trait ServiceModule {
// Required method
fn register(container: &Container);
}Expand description
A module that groups related service registrations.
§Example
use dependency_injector::{Container, verified::{Service, ServiceModule, ServiceProvider}};
#[derive(Clone)]
struct Database;
impl Service for Database {
type Dependencies = ();
fn create(_: ()) -> Self { Database }
}
#[derive(Clone)]
struct Cache;
impl Service for Cache {
type Dependencies = ();
fn create(_: ()) -> Self { Cache }
}
struct DataModule;
impl ServiceModule for DataModule {
fn register(container: &Container) {
container.provide::<Database>();
container.provide::<Cache>();
}
}
let container = Container::new();
DataModule::register(&container);
assert!(container.contains::<Database>());
assert!(container.contains::<Cache>());Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".