aboutsummaryrefslogtreecommitdiff
path: root/src/async_di_container.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-09-24 16:14:45 +0200
committerHampusM <hampus@hampusmat.com>2022-09-24 16:14:45 +0200
commit2a44ec3ffdcd78b23ac31b722b4312774d643c3a (patch)
treed3056a1fffe6311f863c4d683cc3444507c3e7d8 /src/async_di_container.rs
parent695f90bf900015df1e2728445f833dabced838a9 (diff)
refactor!: remove repetition of declaring factory interfaces
BREAKING CHANGE: The to_default_factory method of the blocking and async DI containers now expect a function returning another function
Diffstat (limited to 'src/async_di_container.rs')
-rw-r--r--src/async_di_container.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/async_di_container.rs b/src/async_di_container.rs
index c67900e..d90cc0b 100644
--- a/src/async_di_container.rs
+++ b/src/async_di_container.rs
@@ -78,7 +78,7 @@ use crate::provider::r#async::{
AsyncTransientTypeProvider,
IAsyncProvider,
};
-use crate::ptr::{SomeThreadsafePtr, ThreadsafeSingletonPtr};
+use crate::ptr::{SomeThreadsafePtr, ThreadsafeSingletonPtr, TransientPtr};
/// When configurator for a binding for type 'Interface' inside a [`AsyncDIContainer`].
pub struct AsyncBindingWhenConfigurator<Interface>
@@ -361,8 +361,12 @@ where
) -> Result<AsyncBindingWhenConfigurator<Interface>, AsyncBindingBuilderError>
where
Return: 'static + ?Sized,
- FactoryFunc: Fn<(Arc<AsyncDIContainer>,), Output = crate::ptr::TransientPtr<Return>>
- + Send
+ FactoryFunc: Fn<
+ (Arc<AsyncDIContainer>,),
+ Output = Box<
+ (dyn Fn<(), Output = crate::ptr::TransientPtr<Return>> + Send + Sync),
+ >,
+ > + Send
+ Sync,
{
let mut bindings_lock = self.di_container.bindings.lock().await;
@@ -531,7 +535,10 @@ impl AsyncDIContainer
use crate::interfaces::factory::IFactory;
let default_factory = default_factory_binding
- .cast::<dyn IFactory<(Arc<AsyncDIContainer>,), Interface>>()
+ .cast::<dyn IFactory<
+ (Arc<AsyncDIContainer>,),
+ dyn Fn<(), Output = TransientPtr<Interface>> + Send + Sync,
+ >>()
.map_err(|err| match err {
CastError::NotArcCastable(_) => {
AsyncDIContainerError::InterfaceNotAsync(
@@ -546,7 +553,7 @@ impl AsyncDIContainer
}
})?;
- Ok(SomeThreadsafePtr::Transient(default_factory(self.clone())))
+ Ok(SomeThreadsafePtr::Transient(default_factory(self.clone())()))
}
}
}