From 6d729a4d20944b990c341149729a810a2898cdff Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 18 Sep 2023 20:35:55 +0200 Subject: refactor: make threadsafe castable factory take DI container param --- src/di_container/asynchronous/mod.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/di_container/asynchronous') diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous/mod.rs index c2b4f6f..e651d81 100644 --- a/src/di_container/asynchronous/mod.rs +++ b/src/di_container/asynchronous/mod.rs @@ -279,7 +279,7 @@ impl AsyncDIContainer use crate::private::factory::IThreadsafeFactory; let factory = factory_binding - .cast::,), Interface>>() + .cast::>() .map_err(|err| match err { CastError::NotArcCastable(_) => { AsyncDIContainerError::InterfaceNotAsync( @@ -306,11 +306,13 @@ impl AsyncDIContainer use crate::private::factory::IThreadsafeFactory; use crate::ptr::TransientPtr; + type DefaultFactoryFn = dyn IThreadsafeFactory< + dyn Fn<(), Output = TransientPtr> + Send + Sync, + AsyncDIContainer, + >; + let default_factory = Self::cast_factory_binding::< - dyn IThreadsafeFactory< - (Arc,), - dyn Fn<(), Output = TransientPtr> + Send + Sync, - >, + DefaultFactoryFn, >(binding, "default factory")?; Ok(SomePtr::Transient(default_factory(self.clone())())) @@ -321,13 +323,15 @@ impl AsyncDIContainer use crate::private::factory::IThreadsafeFactory; use crate::ptr::TransientPtr; + type AsyncDefaultFactoryFn = dyn IThreadsafeFactory< + dyn Fn<(), Output = BoxFuture<'static, TransientPtr>> + + Send + + Sync, + AsyncDIContainer, + >; + let async_default_factory = Self::cast_factory_binding::< - dyn IThreadsafeFactory< - (Arc,), - dyn Fn<(), Output = BoxFuture<'static, TransientPtr>> - + Send - + Sync, - >, + AsyncDefaultFactoryFn, >( binding, "async default factory" )?; -- cgit v1.2.3-18-g5258