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

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

declare_default_factory!(IShuriken);

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::<dyn IShuriken>()
        .to_default_factory(&|| {
            let shuriken: TransientPtr<dyn IShuriken> =
                TransientPtr::new(Shuriken::new());

            shuriken
        })?;

    Ok(di_container)
}