aboutsummaryrefslogtreecommitdiff
path: root/examples/factory/bootstrap.rs
blob: b75276448abc1ed30b15f1e25f71fbe14396d2d5 (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
31
32
use syrette::ptr::TransientPtr;
use syrette::DIContainer;

// Interfaces
use crate::interfaces::user::{IUser, IUserFactory};
use crate::interfaces::user_manager::IUserManager;
//
// Concrete implementations
use crate::user::User;
use crate::user_manager::UserManager;

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

    di_container
        .bind::<dyn IUserManager>()
        .to::<UserManager>()
        .unwrap();

    di_container
        .bind::<IUserFactory>()
        .to_factory(&|name, date_of_birth, password| {
            let user: TransientPtr<dyn IUser> =
                TransientPtr::new(User::new(name, date_of_birth, password));

            user
        })
        .unwrap();

    di_container
}