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

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

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

    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
}