[][src]Macro coi_actix_web::container

macro_rules! container {
    (@ registration $ provider : ident scoped) => { ... };
    (@ registration $ provider : ident singleton) => { ... };
    (@ registration $ provider : ident transient) => { ... };
    (@ registration $ provider : ident) => { ... };
    (@ line $ builder : ident $ key : ident $ provider : ident $ ($ call : ident)
 ?) => { ... };
    ($ ($ key : ident => $ provider : ident $ (. $ call : ident) ?), +) => { ... };
    ($ ($ key : ident => $ provider : ident $ (. $ call : ident) ?,) +) => { ... };
}

A macro to simplify building of Containers.

It takes a list of key-value pairs, where the keys are converted to string keys, and the values are converted into registrations. Transient, singleton and scoped registrations are possible, with transient being the default:

use coi::{container, Inject};

trait Dep: Inject {}

#[derive(Inject)]
#[provides(dyn Dep with Impl)]
struct Impl;

impl Dep for Impl {}

let mut container = container! {
    dep => ImplProvider,
    transient_dep => ImplProvider.transient,
    singleton_dep => ImplProvider.singleton,
    scoped_dep => ImplProvider.scoped
};

For details on how each registration works, see coi::Registration