From aa548ded39c7ba1927019c748c359523b21d59e8 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 29 Oct 2022 14:38:51 +0200 Subject: 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 --- examples/prevent-circular/main.rs | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/prevent-circular/main.rs (limited to 'examples/prevent-circular/main.rs') 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, +} + +#[injectable] +impl Foo +{ + fn new(bar: TransientPtr) -> Self + { + Self { bar } + } +} + +struct Bar +{ + foo: TransientPtr, +} + +#[injectable] +impl Bar +{ + fn new(foo: TransientPtr) -> Self + { + Self { foo } + } +} + +fn main() -> Result<(), anyhow::Error> +{ + let mut di_container = DIContainer::new(); + + di_container.bind::().to::()?; + di_container.bind::().to::()?; + + let foo = di_container.get::()?.transient()?; + + Ok(()) +} -- cgit v1.2.3-18-g5258