From c1e682c25c24be3174d44ceb95b0537c38299d0c Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 12 Sep 2022 20:22:13 +0200 Subject: feat!: allow factories access to DI container BREAKING CHANGE: Factory types should now be written with the Fn trait instead of the IFactory trait and the to_factory & to_default_factory methods of BindingBuilder now expect a function returning a factory function --- src/provider/blocking.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/provider') diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs index 69bbe78..e00786b 100644 --- a/src/provider/blocking.rs +++ b/src/provider/blocking.rs @@ -14,6 +14,10 @@ pub enum Providable Singleton(SingletonPtr), #[cfg(feature = "factory")] Factory(crate::ptr::FactoryPtr), + #[cfg(feature = "factory")] + DefaultFactory( + crate::ptr::FactoryPtr, + ), } pub trait IProvider @@ -96,6 +100,7 @@ where pub struct FactoryProvider { factory: crate::ptr::FactoryPtr, + is_default_factory: bool, } #[cfg(feature = "factory")] @@ -103,9 +108,13 @@ impl FactoryProvider { pub fn new( factory: crate::ptr::FactoryPtr, + is_default_factory: bool, ) -> Self { - Self { factory } + Self { + factory, + is_default_factory, + } } } @@ -118,6 +127,10 @@ impl IProvider for FactoryProvider _dependency_history: Vec<&'static str>, ) -> Result { - Ok(Providable::Factory(self.factory.clone())) + Ok(if self.is_default_factory { + Providable::DefaultFactory(self.factory.clone()) + } else { + Providable::Factory(self.factory.clone()) + }) } } -- cgit v1.2.3-18-g5258