diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/async-factory/main.rs | 18 | ||||
-rw-r--r-- | examples/async/bootstrap.rs | 31 |
2 files changed, 19 insertions, 30 deletions
diff --git a/examples/async-factory/main.rs b/examples/async-factory/main.rs index f0365a1..83f79f0 100644 --- a/examples/async-factory/main.rs +++ b/examples/async-factory/main.rs @@ -75,18 +75,15 @@ async fn main() -> Result<()> { let mut di_container = AsyncDIContainer::new(); - di_container - .bind::<IFooFactory>() - .to_async_factory(&|_| { - Box::new(|cnt| { - Box::pin(async move { - let foo_ptr = Box::new(Foo::new(cnt)); + di_container.bind::<IFooFactory>().to_async_factory(&|_| { + Box::new(|cnt| { + Box::pin(async move { + let foo_ptr = Box::new(Foo::new(cnt)); - foo_ptr as Box<dyn IFoo> - }) + foo_ptr as Box<dyn IFoo> }) }) - .await?; + })?; di_container .bind::<dyn IPerson>() @@ -101,8 +98,7 @@ async fn main() -> Result<()> person as TransientPtr<dyn IPerson> }) }) - }) - .await?; + })?; let foo_factory = di_container .get::<IFooFactory>() diff --git a/examples/async/bootstrap.rs b/examples/async/bootstrap.rs index d26876a..6fbe831 100644 --- a/examples/async/bootstrap.rs +++ b/examples/async/bootstrap.rs @@ -18,34 +18,27 @@ pub async fn bootstrap() -> Result<AsyncDIContainer, anyhow::Error> di_container .bind::<dyn IDog>() - .to::<Dog>() - .await? + .to::<Dog>()? .in_singleton_scope() .await?; - di_container - .bind::<dyn ICat>() - .to_default_factory(&|_| { - Box::new(|| { - let cat: TransientPtr<dyn ICat> = TransientPtr::new(Cat::new()); + di_container.bind::<dyn ICat>().to_default_factory(&|_| { + Box::new(|| { + let cat: TransientPtr<dyn ICat> = TransientPtr::new(Cat::new()); - cat - }) + cat }) - .await?; + })?; - di_container.bind::<dyn IHuman>().to::<Human>().await?; + di_container.bind::<dyn IHuman>().to::<Human>()?; - di_container - .bind::<IFoodFactory>() - .to_factory(&|_| { - Box::new(|| { - let food: Box<dyn IFood> = Box::new(Food::new()); + di_container.bind::<IFoodFactory>().to_factory(&|_| { + Box::new(|| { + let food: Box<dyn IFood> = Box::new(Food::new()); - food - }) + food }) - .await?; + })?; Ok(di_container) } |