aboutsummaryrefslogtreecommitdiff
path: root/examples/prevent-circular/main.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-29 14:38:51 +0200
committerHampusM <hampus@hampusmat.com>2022-10-29 14:40:11 +0200
commitaa548ded39c7ba1927019c748c359523b21d59e8 (patch)
tree779d104f85009dd831e6af6e7a523258a1ab5be9 /examples/prevent-circular/main.rs
parentda94fd3b7dd2265f10957d0f5276881beb057d82 (diff)
refactor!: add dependency history type
BREAKING CHANGE: Binding builders & configurators now take dependency history type arguments, the DetectedCircular variant of InjectableError now contains a dependency history field & the injectable traits take dependency history instead of a Vec
Diffstat (limited to 'examples/prevent-circular/main.rs')
-rw-r--r--examples/prevent-circular/main.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/prevent-circular/main.rs b/examples/prevent-circular/main.rs
new file mode 100644
index 0000000..7e10024
--- /dev/null
+++ b/examples/prevent-circular/main.rs
@@ -0,0 +1,48 @@
+#![deny(clippy::all)]
+#![deny(clippy::pedantic)]
+#![allow(clippy::disallowed_names)]
+use std::error::Error;
+
+use syrette::di_container::blocking::prelude::*;
+use syrette::injectable;
+use syrette::ptr::TransientPtr;
+
+struct Foo
+{
+ bar: TransientPtr<Bar>,
+}
+
+#[injectable]
+impl Foo
+{
+ fn new(bar: TransientPtr<Bar>) -> Self
+ {
+ Self { bar }
+ }
+}
+
+struct Bar
+{
+ foo: TransientPtr<Foo>,
+}
+
+#[injectable]
+impl Bar
+{
+ fn new(foo: TransientPtr<Foo>) -> Self
+ {
+ Self { foo }
+ }
+}
+
+fn main() -> Result<(), anyhow::Error>
+{
+ let mut di_container = DIContainer::new();
+
+ di_container.bind::<Foo>().to::<Foo>()?;
+ di_container.bind::<Bar>().to::<Bar>()?;
+
+ let foo = di_container.get::<Foo>()?.transient()?;
+
+ Ok(())
+}