diff options
author | HampusM <hampus@hampusmat.com> | 2022-10-23 18:12:23 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-10-23 18:12:23 +0200 |
commit | 9e01cdf341a7866180b3a63d745f3b2d7578d28a (patch) | |
tree | 0c036b7b4a68e44b6eb2221bf7beb3c34fe9c1c8 /src/interfaces | |
parent | 740ef47d49e02ae2f2184f4c347d8eba8aee38fd (diff) |
refactor!: reduce DI container coupling
BREAKING CHANGE: You now have to import the DI containers's interfaces to use the DI containers's methods
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/async_injectable.rs | 12 | ||||
-rw-r--r-- | src/interfaces/injectable.rs | 12 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/interfaces/async_injectable.rs b/src/interfaces/async_injectable.rs index dadb603..fb7f8ba 100644 --- a/src/interfaces/async_injectable.rs +++ b/src/interfaces/async_injectable.rs @@ -2,21 +2,23 @@ use std::fmt::Debug; use std::sync::Arc; +use crate::di_container::asynchronous::IAsyncDIContainer; use crate::errors::injectable::InjectableError; use crate::future::BoxFuture; use crate::libs::intertrait::CastFromSync; use crate::ptr::TransientPtr; -use crate::AsyncDIContainer; /// Interface for structs that can be injected into or be injected to. -pub trait AsyncInjectable: CastFromSync +pub trait AsyncInjectable<DIContainerType>: CastFromSync +where + DIContainerType: IAsyncDIContainer, { /// Resolves the dependencies of the injectable. /// /// # Errors /// Will return `Err` if resolving the dependencies fails. fn resolve<'di_container, 'fut>( - di_container: &'di_container Arc<AsyncDIContainer>, + di_container: &'di_container Arc<DIContainerType>, dependency_history: Vec<&'static str>, ) -> BoxFuture<'fut, Result<TransientPtr<Self>, InjectableError>> where @@ -24,7 +26,9 @@ pub trait AsyncInjectable: CastFromSync 'di_container: 'fut; } -impl Debug for dyn AsyncInjectable +impl<DIContainerType> Debug for dyn AsyncInjectable<DIContainerType> +where + DIContainerType: IAsyncDIContainer, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/src/interfaces/injectable.rs b/src/interfaces/injectable.rs index f4c7fda..132935d 100644 --- a/src/interfaces/injectable.rs +++ b/src/interfaces/injectable.rs @@ -2,27 +2,31 @@ use std::fmt::Debug; use std::rc::Rc; +use crate::di_container::blocking::IDIContainer; use crate::errors::injectable::InjectableError; use crate::libs::intertrait::CastFrom; use crate::ptr::TransientPtr; -use crate::DIContainer; /// Interface for structs that can be injected into or be injected to. -pub trait Injectable: CastFrom +pub trait Injectable<DIContainerType>: CastFrom +where + DIContainerType: IDIContainer, { /// Resolves the dependencies of the injectable. /// /// # Errors /// Will return `Err` if resolving the dependencies fails. fn resolve( - di_container: &Rc<DIContainer>, + di_container: &Rc<DIContainerType>, dependency_history: Vec<&'static str>, ) -> Result<TransientPtr<Self>, InjectableError> where Self: Sized; } -impl Debug for dyn Injectable +impl<DIContainerType> Debug for dyn Injectable<DIContainerType> +where + DIContainerType: IDIContainer, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |