aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/async/bootstrap.rs11
-rw-r--r--examples/async/main.rs14
2 files changed, 9 insertions, 16 deletions
diff --git a/examples/async/bootstrap.rs b/examples/async/bootstrap.rs
index b640712..7e1d2cd 100644
--- a/examples/async/bootstrap.rs
+++ b/examples/async/bootstrap.rs
@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
use anyhow::Result;
use syrette::async_di_container::AsyncDIContainer;
@@ -11,18 +13,19 @@ use crate::interfaces::cat::ICat;
use crate::interfaces::dog::IDog;
use crate::interfaces::human::IHuman;
-pub async fn bootstrap() -> Result<AsyncDIContainer>
+pub async fn bootstrap() -> Result<Arc<AsyncDIContainer>>
{
let mut di_container = AsyncDIContainer::new();
di_container
.bind::<dyn IDog>()
- .to::<Dog>()?
+ .to::<Dog>()
+ .await?
.in_singleton_scope()
.await?;
- di_container.bind::<dyn ICat>().to::<Cat>()?;
- di_container.bind::<dyn IHuman>().to::<Human>()?;
+ di_container.bind::<dyn ICat>().to::<Cat>().await?;
+ di_container.bind::<dyn IHuman>().to::<Human>().await?;
Ok(di_container)
}
diff --git a/examples/async/main.rs b/examples/async/main.rs
index f72ff39..3c884fe 100644
--- a/examples/async/main.rs
+++ b/examples/async/main.rs
@@ -2,11 +2,8 @@
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
-use std::sync::Arc;
-
use anyhow::Result;
use tokio::spawn;
-use tokio::sync::Mutex;
mod animals;
mod bootstrap;
@@ -21,12 +18,10 @@ async fn main() -> Result<()>
{
println!("Hello, world!");
- let di_container = Arc::new(Mutex::new(bootstrap().await?));
+ let di_container = bootstrap().await?;
{
let dog = di_container
- .lock()
- .await
.get::<dyn IDog>()
.await?
.threadsafe_singleton()?;
@@ -35,12 +30,7 @@ async fn main() -> Result<()>
}
spawn(async move {
- let human = di_container
- .lock()
- .await
- .get::<dyn IHuman>()
- .await?
- .transient()?;
+ let human = di_container.get::<dyn IHuman>().await?.transient()?;
human.make_pets_make_sounds();