aboutsummaryrefslogtreecommitdiff
path: root/examples/named/bootstrap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/named/bootstrap.rs')
-rw-r--r--examples/named/bootstrap.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/named/bootstrap.rs b/examples/named/bootstrap.rs
new file mode 100644
index 0000000..b5fa39d
--- /dev/null
+++ b/examples/named/bootstrap.rs
@@ -0,0 +1,29 @@
+use anyhow::Result;
+use syrette::DIContainer;
+
+use crate::interfaces::ninja::INinja;
+use crate::interfaces::weapon::IWeapon;
+use crate::katana::Katana;
+use crate::ninja::Ninja;
+use crate::shuriken::Shuriken;
+
+pub fn bootstrap() -> Result<DIContainer>
+{
+ let mut di_container: DIContainer = DIContainer::new();
+
+ di_container
+ .bind::<dyn IWeapon>()
+ .to::<Katana>()?
+ .in_transient_scope()
+ .when_named("strong")?;
+
+ di_container
+ .bind::<dyn IWeapon>()
+ .to::<Shuriken>()?
+ .in_transient_scope()
+ .when_named("weak")?;
+
+ di_container.bind::<dyn INinja>().to::<Ninja>()?;
+
+ Ok(di_container)
+}