aboutsummaryrefslogtreecommitdiff
path: root/src/provider/blocking.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-09-12 20:22:13 +0200
committerHampusM <hampus@hampusmat.com>2022-09-17 14:33:15 +0200
commitc1e682c25c24be3174d44ceb95b0537c38299d0c (patch)
tree6e59f37e1b98e68fad2e3e2fe4a428ac97fcf8b4 /src/provider/blocking.rs
parente8e48906a3899e71c9c9d86a3d4528cb7d17e5b9 (diff)
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
Diffstat (limited to 'src/provider/blocking.rs')
-rw-r--r--src/provider/blocking.rs17
1 files changed, 15 insertions, 2 deletions
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<dyn Injectable>),
#[cfg(feature = "factory")]
Factory(crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>),
+ #[cfg(feature = "factory")]
+ DefaultFactory(
+ crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>,
+ ),
}
pub trait IProvider
@@ -96,6 +100,7 @@ where
pub struct FactoryProvider
{
factory: crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>,
+ is_default_factory: bool,
}
#[cfg(feature = "factory")]
@@ -103,9 +108,13 @@ impl FactoryProvider
{
pub fn new(
factory: crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>,
+ 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<Providable, InjectableError>
{
- Ok(Providable::Factory(self.factory.clone()))
+ Ok(if self.is_default_factory {
+ Providable::DefaultFactory(self.factory.clone())
+ } else {
+ Providable::Factory(self.factory.clone())
+ })
}
}