aboutsummaryrefslogtreecommitdiff
path: root/examples/factory/bootstrap.rs
blob: 1967c6a9b6c8e5d06b5e146d4fcd6710a5b45340 (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
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
        });

    di_container
}