aboutsummaryrefslogtreecommitdiff
path: root/examples/with-3rd-party/bootstrap.rs
blob: 1ab3192c68ab4d9828727d92e358ec6d781c7250 (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
use syrette::errors::di_container::BindingBuilderError;
use syrette::ptr::TransientPtr;
use syrette::{declare_default_factory, DIContainer};
use third_party_lib::Shuriken;

// Interfaces
use crate::interfaces::ninja::INinja;
//
// Concrete implementations
use crate::ninja::Ninja;

declare_default_factory!(Shuriken);

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

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

    di_container
        .bind::<Shuriken>()
        .to_default_factory(&|| TransientPtr::new(Shuriken::new()))?;

    Ok(di_container)
}