aboutsummaryrefslogtreecommitdiff
path: root/src/provider.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-02 14:31:31 +0200
committerHampusM <hampus@hampusmat.com>2022-08-02 14:31:31 +0200
commit826592eac2601e9fcd5aabb17482b4816ed7ab88 (patch)
tree3c3ba5436ca76e0738e4cc8deefef3025fd5d4bd /src/provider.rs
parent163cd3cedd398f5676edbcb3249dd958d3e97aca (diff)
feat: add detection and prevention of circular dependencies
Diffstat (limited to 'src/provider.rs')
-rw-r--r--src/provider.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/provider.rs b/src/provider.rs
index 2e832f8..e12a12a 100644
--- a/src/provider.rs
+++ b/src/provider.rs
@@ -7,8 +7,6 @@ use crate::interfaces::injectable::Injectable;
use crate::ptr::{FactoryPtr, SingletonPtr, TransientPtr};
use crate::DIContainer;
-extern crate error_stack;
-
pub enum Providable
{
Transient(TransientPtr<dyn Injectable>),
@@ -22,6 +20,7 @@ pub trait IProvider
fn provide(
&self,
di_container: &DIContainer,
+ dependency_history: Vec<&'static str>,
) -> error_stack::Result<Providable, ResolveError>;
}
@@ -51,10 +50,12 @@ where
fn provide(
&self,
di_container: &DIContainer,
+ dependency_history: Vec<&'static str>,
) -> error_stack::Result<Providable, ResolveError>
{
Ok(Providable::Transient(InjectableType::resolve(
di_container,
+ dependency_history,
)?))
}
}
@@ -83,6 +84,7 @@ where
fn provide(
&self,
_di_container: &DIContainer,
+ _dependency_history: Vec<&'static str>,
) -> error_stack::Result<Providable, ResolveError>
{
Ok(Providable::Singleton(self.singleton.clone()))
@@ -110,6 +112,7 @@ impl IProvider for FactoryProvider
fn provide(
&self,
_di_container: &DIContainer,
+ _dependency_history: Vec<&'static str>,
) -> error_stack::Result<Providable, ResolveError>
{
Ok(Providable::Factory(self.factory.clone()))