aboutsummaryrefslogtreecommitdiff
path: root/examples/with-3rd-party/bootstrap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/with-3rd-party/bootstrap.rs')
-rw-r--r--examples/with-3rd-party/bootstrap.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/with-3rd-party/bootstrap.rs b/examples/with-3rd-party/bootstrap.rs
new file mode 100644
index 0000000..e51c104
--- /dev/null
+++ b/examples/with-3rd-party/bootstrap.rs
@@ -0,0 +1,30 @@
+use syrette::errors::di_container::BindingBuilderError;
+use syrette::ptr::TransientPtr;
+use syrette::{declare_default_factory, DIContainer};
+use third_party_lib::{IShuriken, Shuriken};
+
+// Interfaces
+use crate::interfaces::ninja::INinja;
+//
+// Concrete implementations
+use crate::ninja::Ninja;
+
+declare_default_factory!(IShuriken);
+
+pub fn bootstrap() -> error_stack::Result<DIContainer, BindingBuilderError>
+{
+ let mut di_container: DIContainer = DIContainer::new();
+
+ di_container.bind::<dyn INinja>().to::<Ninja>()?;
+
+ di_container
+ .bind::<dyn IShuriken>()
+ .to_default_factory(&|| {
+ let shuriken: TransientPtr<dyn IShuriken> =
+ TransientPtr::new(Shuriken::new());
+
+ shuriken
+ })?;
+
+ Ok(di_container)
+}