aboutsummaryrefslogtreecommitdiff
path: root/examples/with-3rd-party/bootstrap.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-20 17:10:08 +0200
committerHampusM <hampus@hampusmat.com>2022-08-21 18:17:50 +0200
commitade21185976ea2324d313a5c28a88cc0492f2934 (patch)
treef217d55ad324160d8a9a099c562c8bc6cbb60c1f /examples/with-3rd-party/bootstrap.rs
parentb31422d48a600ccccb682567f5eb11fc0bca547c (diff)
docs: add a example that uses a 3rd party library
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)
+}