diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-17 18:33:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-17 18:33:43 +0200 |
commit | 7de7f73963a266cceff85d6ab71c3256e5d382ec (patch) | |
tree | 67575870945b7ed0a5eeb99ccba79327598b3e02 /examples/async/main.rs | |
parent | 8651f84f205da7a89f2fc7333d1dd8de0d80a22b (diff) |
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
Diffstat (limited to 'examples/async/main.rs')
-rw-r--r-- | examples/async/main.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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::<IFoodFactory>() + .await? + .threadsafe_factory()?; + + let food = food_factory(); + + food.eat(); + spawn(async move { let human = di_container.get::<dyn IHuman>().await?.transient()?; |