diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-22 13:25:45 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-07-22 13:25:45 +0200 |
commit | 4cb3884e24b3cba3347ff93475bbabd6fe18d2fa (patch) | |
tree | 2fa5e6d81de9dc39bd11d64797914e5d305d98e2 /examples/factory/bootstrap.rs | |
parent | 157f38bc2287dcb9a8b21ef3d5e33c569dc5136e (diff) |
refactor: make factories an optional feature
Diffstat (limited to 'examples/factory/bootstrap.rs')
-rw-r--r-- | examples/factory/bootstrap.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/factory/bootstrap.rs b/examples/factory/bootstrap.rs new file mode 100644 index 0000000..5086b1a --- /dev/null +++ b/examples/factory/bootstrap.rs @@ -0,0 +1,24 @@ +use syrette::ptr::InterfacePtr; +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: InterfacePtr<dyn IUser> = + InterfacePtr::new(User::new(name, date_of_birth, password)); + + user + }); + + di_container +} |