From 826592eac2601e9fcd5aabb17482b4816ed7ab88 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 2 Aug 2022 14:31:31 +0200 Subject: feat: add detection and prevention of circular dependencies --- src/provider.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/provider.rs') 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), @@ -22,6 +20,7 @@ pub trait IProvider fn provide( &self, di_container: &DIContainer, + dependency_history: Vec<&'static str>, ) -> error_stack::Result; } @@ -51,10 +50,12 @@ where fn provide( &self, di_container: &DIContainer, + dependency_history: Vec<&'static str>, ) -> error_stack::Result { 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 { 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 { Ok(Providable::Factory(self.factory.clone())) -- cgit v1.2.3-18-g5258