From 7de7f73963a266cceff85d6ab71c3256e5d382ec Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 17 Sep 2022 18:33:43 +0200 Subject: feat!: allow factories to access async DI container BREAKING CHANGE: The to_factory & to_default_factory methods of AsyncBindingBuilder now expects a function returning a factory function --- examples/async/main.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'examples/async/main.rs') diff --git a/examples/async/main.rs b/examples/async/main.rs index 3c884fe..03e36e1 100644 --- a/examples/async/main.rs +++ b/examples/async/main.rs @@ -7,12 +7,15 @@ use tokio::spawn; mod animals; mod bootstrap; +mod food; mod interfaces; use bootstrap::bootstrap; use interfaces::dog::IDog; use interfaces::human::IHuman; +use crate::interfaces::food::IFoodFactory; + #[tokio::main] async fn main() -> Result<()> { @@ -29,6 +32,15 @@ async fn main() -> Result<()> dog.woof(); } + let food_factory = di_container + .get::() + .await? + .threadsafe_factory()?; + + let food = food_factory(); + + food.eat(); + spawn(async move { let human = di_container.get::().await?.transient()?; -- cgit v1.2.3-18-g5258