Skip to main content

ServiceModule

Trait ServiceModule 

Source
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§

Source

fn register(container: &Container)

Register all services in this module.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§