aboutsummaryrefslogtreecommitdiff
path: root/examples/named/bootstrap.rs
blob: b5fa39dfcf24e3b65420000b1e73be3590019253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use anyhow::Result;
use syrette::DIContainer;

use crate::interfaces::ninja::INinja;
use crate::interfaces::weapon::IWeapon;
use crate::katana::Katana;
use crate::ninja::Ninja;
use crate::shuriken::Shuriken;

pub fn bootstrap() -> Result<DIContainer>
{
    let mut di_container: DIContainer = DIContainer::new();

    di_container
        .bind::<dyn IWeapon>()
        .to::<Katana>()?
        .in_transient_scope()
        .when_named("strong")?;

    di_container
        .bind::<dyn IWeapon>()
        .to::<Shuriken>()?
        .in_transient_scope()
        .when_named("weak")?;

    di_container.bind::<dyn INinja>().to::<Ninja>()?;

    Ok(di_container)
}