aboutsummaryrefslogtreecommitdiff
path: root/src/di_container/asynchronous/binding/when_configurator.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-04 11:10:36 +0200
committerHampusM <hampus@hampusmat.com>2023-10-04 11:10:36 +0200
commitb0a1af1e312f23eff7fe68ae17132ccded5cf31c (patch)
tree316f9177fcc7d3d73051750d9d87a6e965b6a26c /src/di_container/asynchronous/binding/when_configurator.rs
parent613bf4a8a094df6f048cc8b1fcf2fc425abddd99 (diff)
refactor!: remove mutex in AsyncDIContainer
BREAKING CHANGE: Multiple async DI container binding builder & binding configurator functions are no longer async
Diffstat (limited to 'src/di_container/asynchronous/binding/when_configurator.rs')
-rw-r--r--src/di_container/asynchronous/binding/when_configurator.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/di_container/asynchronous/binding/when_configurator.rs b/src/di_container/asynchronous/binding/when_configurator.rs
index bc8e97f..5cec278 100644
--- a/src/di_container/asynchronous/binding/when_configurator.rs
+++ b/src/di_container/asynchronous/binding/when_configurator.rs
@@ -13,7 +13,7 @@ pub struct AsyncBindingWhenConfigurator<'di_container, Interface>
where
Interface: 'static + ?Sized + Send + Sync,
{
- di_container: &'di_container AsyncDIContainer,
+ di_container: &'di_container mut AsyncDIContainer,
interface_phantom: PhantomData<Interface>,
}
@@ -22,7 +22,7 @@ impl<'di_container, Interface> AsyncBindingWhenConfigurator<'di_container, Inter
where
Interface: 'static + ?Sized + Send + Sync,
{
- pub(crate) fn new(di_container: &'di_container AsyncDIContainer) -> Self
+ pub(crate) fn new(di_container: &'di_container mut AsyncDIContainer) -> Self
{
Self {
di_container,
@@ -56,17 +56,14 @@ where
///
/// di_container
/// .bind::<Kitten>()
- /// .to::<Kitten>()
- /// .await?
+ /// .to::<Kitten>()?
/// .in_transient_scope()
- /// .await
- /// .when_named("Billy")
- /// .await?;
+ /// .when_named("Billy")?;
/// #
/// # Ok(())
/// # }
/// ```
- pub async fn when_named(
+ pub fn when_named(
self,
name: &'static str,
) -> Result<(), AsyncBindingWhenConfiguratorError>
@@ -74,7 +71,6 @@ where
let binding = self
.di_container
.remove_binding::<Interface>(BindingOptions::new())
- .await
.map_or_else(
|| {
Err(AsyncBindingWhenConfiguratorError::BindingNotFound(
@@ -85,8 +81,7 @@ where
)?;
self.di_container
- .set_binding::<Interface>(BindingOptions::new().name(name), binding)
- .await;
+ .set_binding::<Interface>(BindingOptions::new().name(name), binding);
Ok(())
}
@@ -121,11 +116,8 @@ mod tests
let binding_when_configurator = AsyncBindingWhenConfigurator::<
dyn subjects_async::INumber,
- >::new(&di_container_mock);
+ >::new(&mut di_container_mock);
- assert!(binding_when_configurator
- .when_named("awesome")
- .await
- .is_ok());
+ assert!(binding_when_configurator.when_named("awesome").is_ok());
}
}