From b0a1af1e312f23eff7fe68ae17132ccded5cf31c Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 4 Oct 2023 11:10:36 +0200 Subject: refactor!: remove mutex in AsyncDIContainer BREAKING CHANGE: Multiple async DI container binding builder & binding configurator functions are no longer async --- .../asynchronous/binding/scope_configurator.rs | 52 ++++++++++------------ 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'src/di_container/asynchronous/binding/scope_configurator.rs') diff --git a/src/di_container/asynchronous/binding/scope_configurator.rs b/src/di_container/asynchronous/binding/scope_configurator.rs index b63e644..6f72cf0 100644 --- a/src/di_container/asynchronous/binding/scope_configurator.rs +++ b/src/di_container/asynchronous/binding/scope_configurator.rs @@ -18,7 +18,7 @@ where Interface: 'static + ?Sized + Send + Sync, Implementation: AsyncInjectable, { - di_container: &'di_container AsyncDIContainer, + di_container: &'di_container mut AsyncDIContainer, dependency_history_factory: fn() -> DependencyHistory, interface_phantom: PhantomData, @@ -32,7 +32,7 @@ where Implementation: AsyncInjectable, { pub(crate) fn new( - di_container: &'di_container AsyncDIContainer, + di_container: &'di_container mut AsyncDIContainer, dependency_history_factory: fn() -> DependencyHistory, ) -> Self { @@ -69,19 +69,18 @@ where /// /// di_container /// .bind::() - /// .to::() - /// .await? - /// .in_transient_scope() - /// .await; + /// .to::()? + /// .in_transient_scope(); /// # /// # Ok(()) /// # } /// ``` - pub async fn in_transient_scope( - self, + #[allow(clippy::must_use_candidate)] + pub fn in_transient_scope( + mut self, ) -> AsyncBindingWhenConfigurator<'di_container, Interface> { - self.set_in_transient_scope().await; + self.set_in_transient_scope(); AsyncBindingWhenConfigurator::new(self.di_container) } @@ -127,8 +126,7 @@ where /// /// di_container /// .bind::() - /// .to::() - /// .await? + /// .to::()? /// .in_singleton_scope() /// .await; /// @@ -168,26 +166,22 @@ where .map_err(AsyncBindingScopeConfiguratorError::SingletonResolveFailed)?, ); - self.di_container - .set_binding::( - BindingOptions::new(), - Box::new(AsyncSingletonProvider::new(singleton)), - ) - .await; + self.di_container.set_binding::( + BindingOptions::new(), + Box::new(AsyncSingletonProvider::new(singleton)), + ); Ok(AsyncBindingWhenConfigurator::new(self.di_container)) } - pub(crate) async fn set_in_transient_scope(&self) + pub(crate) fn set_in_transient_scope(&mut self) { - self.di_container - .set_binding::( - BindingOptions::new(), - Box::new( - AsyncTransientTypeProvider::::new(), - ), - ) - .await; + self.di_container.set_binding::( + BindingOptions::new(), + Box::new( + AsyncTransientTypeProvider::::new(), + ), + ); } } @@ -214,9 +208,9 @@ mod tests AsyncBindingScopeConfigurator::< dyn subjects_async::IUserManager, subjects_async::UserManager, - >::new(&di_container_mock, MockDependencyHistory::new); + >::new(&mut di_container_mock, MockDependencyHistory::new); - binding_scope_configurator.in_transient_scope().await; + binding_scope_configurator.in_transient_scope(); } #[tokio::test] @@ -234,7 +228,7 @@ mod tests AsyncBindingScopeConfigurator::< dyn subjects_async::IUserManager, subjects_async::UserManager, - >::new(&di_container_mock, MockDependencyHistory::new); + >::new(&mut di_container_mock, MockDependencyHistory::new); assert!(binding_scope_configurator .in_singleton_scope() -- cgit v1.2.3-18-g5258