aboutsummaryrefslogtreecommitdiff
path: root/examples/factory/bootstrap.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-22 13:25:45 +0200
committerHampusM <hampus@hampusmat.com>2022-07-22 13:25:45 +0200
commit4cb3884e24b3cba3347ff93475bbabd6fe18d2fa (patch)
tree2fa5e6d81de9dc39bd11d64797914e5d305d98e2 /examples/factory/bootstrap.rs
parent157f38bc2287dcb9a8b21ef3d5e33c569dc5136e (diff)
refactor: make factories an optional feature
Diffstat (limited to 'examples/factory/bootstrap.rs')
-rw-r--r--examples/factory/bootstrap.rs24
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
+}