diff options
author | HampusM <hampus@hampusmat.com> | 2023-09-18 20:35:55 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-09-18 20:35:55 +0200 |
commit | 6d729a4d20944b990c341149729a810a2898cdff (patch) | |
tree | f64218f129b5f7c168e64ede3b99fddb7faca8ac /src/di_container/asynchronous | |
parent | e4fdf58b42c61482741cb12e1faa24cbd50698e8 (diff) |
refactor: make threadsafe castable factory take DI container param
Diffstat (limited to 'src/di_container/asynchronous')
-rw-r--r-- | src/di_container/asynchronous/mod.rs | 26 |
1 files changed, 15 insertions, 11 deletions
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::<dyn IThreadsafeFactory<(Arc<AsyncDIContainer>,), Interface>>() + .cast::<dyn IThreadsafeFactory<Interface, Self>>() .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<Interface> = dyn IThreadsafeFactory< + dyn Fn<(), Output = TransientPtr<Interface>> + Send + Sync, + AsyncDIContainer, + >; + let default_factory = Self::cast_factory_binding::< - dyn IThreadsafeFactory< - (Arc<AsyncDIContainer>,), - dyn Fn<(), Output = TransientPtr<Interface>> + Send + Sync, - >, + DefaultFactoryFn<Interface>, >(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<Interface> = dyn IThreadsafeFactory< + dyn Fn<(), Output = BoxFuture<'static, TransientPtr<Interface>>> + + Send + + Sync, + AsyncDIContainer, + >; + let async_default_factory = Self::cast_factory_binding::< - dyn IThreadsafeFactory< - (Arc<AsyncDIContainer>,), - dyn Fn<(), Output = BoxFuture<'static, TransientPtr<Interface>>> - + Send - + Sync, - >, + AsyncDefaultFactoryFn<Interface>, >( binding, "async default factory" )?; |