aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-29 14:38:51 +0200
committerHampusM <hampus@hampusmat.com>2022-10-29 14:40:11 +0200
commitaa548ded39c7ba1927019c748c359523b21d59e8 (patch)
tree779d104f85009dd831e6af6e7a523258a1ab5be9 /src/interfaces
parentda94fd3b7dd2265f10957d0f5276881beb057d82 (diff)
refactor!: add dependency history type
BREAKING CHANGE: Binding builders & configurators now take dependency history type arguments, the DetectedCircular variant of InjectableError now contains a dependency history field & the injectable traits take dependency history instead of a Vec
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/async_injectable.rs14
-rw-r--r--src/interfaces/injectable.rs14
2 files changed, 18 insertions, 10 deletions
diff --git a/src/interfaces/async_injectable.rs b/src/interfaces/async_injectable.rs
index fb7f8ba..4e614a3 100644
--- a/src/interfaces/async_injectable.rs
+++ b/src/interfaces/async_injectable.rs
@@ -2,6 +2,7 @@
use std::fmt::Debug;
use std::sync::Arc;
+use crate::dependency_history::IDependencyHistory;
use crate::di_container::asynchronous::IAsyncDIContainer;
use crate::errors::injectable::InjectableError;
use crate::future::BoxFuture;
@@ -9,9 +10,10 @@ use crate::libs::intertrait::CastFromSync;
use crate::ptr::TransientPtr;
/// Interface for structs that can be injected into or be injected to.
-pub trait AsyncInjectable<DIContainerType>: CastFromSync
+pub trait AsyncInjectable<DIContainerType, DependencyHistoryType>: CastFromSync
where
- DIContainerType: IAsyncDIContainer,
+ DIContainerType: IAsyncDIContainer<DependencyHistoryType>,
+ DependencyHistoryType: IDependencyHistory + Send + Sync,
{
/// Resolves the dependencies of the injectable.
///
@@ -19,16 +21,18 @@ where
/// Will return `Err` if resolving the dependencies fails.
fn resolve<'di_container, 'fut>(
di_container: &'di_container Arc<DIContainerType>,
- dependency_history: Vec<&'static str>,
+ dependency_history: DependencyHistoryType,
) -> BoxFuture<'fut, Result<TransientPtr<Self>, InjectableError>>
where
Self: Sized + 'fut,
'di_container: 'fut;
}
-impl<DIContainerType> Debug for dyn AsyncInjectable<DIContainerType>
+impl<DIContainerType, DependencyHistoryType> Debug
+ for dyn AsyncInjectable<DIContainerType, DependencyHistoryType>
where
- DIContainerType: IAsyncDIContainer,
+ DIContainerType: IAsyncDIContainer<DependencyHistoryType>,
+ DependencyHistoryType: IDependencyHistory + Send + Sync,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
{
diff --git a/src/interfaces/injectable.rs b/src/interfaces/injectable.rs
index 132935d..6130d2b 100644
--- a/src/interfaces/injectable.rs
+++ b/src/interfaces/injectable.rs
@@ -2,15 +2,17 @@
use std::fmt::Debug;
use std::rc::Rc;
+use crate::dependency_history::IDependencyHistory;
use crate::di_container::blocking::IDIContainer;
use crate::errors::injectable::InjectableError;
use crate::libs::intertrait::CastFrom;
use crate::ptr::TransientPtr;
/// Interface for structs that can be injected into or be injected to.
-pub trait Injectable<DIContainerType>: CastFrom
+pub trait Injectable<DIContainerType, DependencyHistoryType>: CastFrom
where
- DIContainerType: IDIContainer,
+ DIContainerType: IDIContainer<DependencyHistoryType>,
+ DependencyHistoryType: IDependencyHistory,
{
/// Resolves the dependencies of the injectable.
///
@@ -18,15 +20,17 @@ where
/// Will return `Err` if resolving the dependencies fails.
fn resolve(
di_container: &Rc<DIContainerType>,
- dependency_history: Vec<&'static str>,
+ dependency_history: DependencyHistoryType,
) -> Result<TransientPtr<Self>, InjectableError>
where
Self: Sized;
}
-impl<DIContainerType> Debug for dyn Injectable<DIContainerType>
+impl<DIContainerType, DependencyHistoryType> Debug
+ for dyn Injectable<DIContainerType, DependencyHistoryType>
where
- DIContainerType: IDIContainer,
+ DIContainerType: IDIContainer<DependencyHistoryType>,
+ DependencyHistoryType: IDependencyHistory,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
{