diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-17 18:33:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-17 18:33:43 +0200 |
commit | 7de7f73963a266cceff85d6ab71c3256e5d382ec (patch) | |
tree | 67575870945b7ed0a5eeb99ccba79327598b3e02 /src/provider | |
parent | 8651f84f205da7a89f2fc7333d1dd8de0d80a22b (diff) |
feat!: allow factories to access async DI container
BREAKING CHANGE: The to_factory & to_default_factory methods of AsyncBindingBuilder now expects a function returning a factory function
Diffstat (limited to 'src/provider')
-rw-r--r-- | src/provider/async.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/provider/async.rs b/src/provider/async.rs index 1ddb614..df96b27 100644 --- a/src/provider/async.rs +++ b/src/provider/async.rs @@ -20,6 +20,12 @@ pub enum AsyncProvidable dyn crate::interfaces::any_factory::AnyThreadsafeFactory, >, ), + #[cfg(feature = "factory")] + DefaultFactory( + crate::ptr::ThreadsafeFactoryPtr< + dyn crate::interfaces::any_factory::AnyThreadsafeFactory, + >, + ), } #[async_trait] @@ -150,6 +156,7 @@ pub struct AsyncFactoryProvider factory: crate::ptr::ThreadsafeFactoryPtr< dyn crate::interfaces::any_factory::AnyThreadsafeFactory, >, + is_default_factory: bool, } #[cfg(feature = "factory")] @@ -159,9 +166,13 @@ impl AsyncFactoryProvider factory: crate::ptr::ThreadsafeFactoryPtr< dyn crate::interfaces::any_factory::AnyThreadsafeFactory, >, + is_default_factory: bool, ) -> Self { - Self { factory } + Self { + factory, + is_default_factory, + } } } @@ -175,7 +186,11 @@ impl IAsyncProvider for AsyncFactoryProvider _dependency_history: Vec<&'static str>, ) -> Result<AsyncProvidable, InjectableError> { - Ok(AsyncProvidable::Factory(self.factory.clone())) + Ok(if self.is_default_factory { + AsyncProvidable::DefaultFactory(self.factory.clone()) + } else { + AsyncProvidable::Factory(self.factory.clone()) + }) } fn do_clone(&self) -> Box<dyn IAsyncProvider> @@ -191,6 +206,7 @@ impl Clone for AsyncFactoryProvider { Self { factory: self.factory.clone(), + is_default_factory: self.is_default_factory.clone(), } } } |