From 89c238f9c82ade2d7656e2bee76838a391609a88 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 5 Aug 2023 23:14:06 +0200 Subject: refactor!: remove IDependencyHistory BREAKING CHANGE: IDependencyHistory has been removed as part of an effort to simplify the API. This affects IDIContainer, DIContainer, IAsyncDIContainer, AsyncDIContainer, Injectable, AsyncInjectable, BindingBuilder, AsyncBindingBuilder, BindingScopeConfigurator, BindingWhenConfigurator, AsyncBindingScopeConfigurator, AsyncBindingWhenConfigurator and DependencyHistory --- src/test_utils.rs | 155 ++++++++++++++++++++---------------------------------- 1 file changed, 57 insertions(+), 98 deletions(-) (limited to 'src/test_utils.rs') diff --git a/src/test_utils.rs b/src/test_utils.rs index 78ad63b..2bc1671 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -7,12 +7,13 @@ pub mod subjects use syrette_macros::declare_interface; - use crate::dependency_history::IDependencyHistory; use crate::di_container::blocking::IDIContainer; use crate::interfaces::injectable::Injectable; use crate::private::cast::CastFromArc; use crate::ptr::TransientPtr; + use_dependency_history!(); + pub trait IUserManager { fn add_user(&self, user_id: i128); @@ -44,18 +45,17 @@ pub mod subjects } use crate as syrette; + use crate::util::use_dependency_history; declare_interface!(UserManager -> IUserManager); - impl - Injectable for UserManager + impl Injectable for UserManager where - DIContainerType: IDIContainer, - DependencyHistoryType: IDependencyHistory, + DIContainerType: IDIContainer, { fn resolve( _di_container: &Rc, - _dependency_history: DependencyHistoryType, + _dependency_history: DependencyHistory, ) -> Result, crate::errors::injectable::InjectableError> where Self: Sized, @@ -115,15 +115,13 @@ pub mod subjects declare_interface!(Number -> INumber); - impl - Injectable for Number + impl Injectable for Number where - DIContainerType: IDIContainer, - DependencyHistoryType: IDependencyHistory, + DIContainerType: IDIContainer, { fn resolve( _di_container: &Rc, - _dependency_history: DependencyHistoryType, + _dependency_history: DependencyHistory, ) -> Result, crate::errors::injectable::InjectableError> where Self: Sized, @@ -151,11 +149,12 @@ pub mod subjects_async use async_trait::async_trait; use syrette_macros::declare_interface; - use crate::dependency_history::IDependencyHistory; use crate::di_container::asynchronous::IAsyncDIContainer; use crate::interfaces::async_injectable::AsyncInjectable; use crate::ptr::TransientPtr; + use_dependency_history!(); + pub trait IUserManager: Send + Sync { fn add_user(&self, user_id: i128); @@ -187,19 +186,18 @@ pub mod subjects_async } use crate as syrette; + use crate::util::use_dependency_history; declare_interface!(UserManager -> IUserManager); #[async_trait] - impl - AsyncInjectable for UserManager + impl AsyncInjectable for UserManager where - DIContainerType: IAsyncDIContainer, - DependencyHistoryType: IDependencyHistory + Send + Sync + 'static, + DIContainerType: IAsyncDIContainer, { async fn resolve( _: &Arc, - _dependency_history: DependencyHistoryType, + _dependency_history: DependencyHistory, ) -> Result, crate::errors::injectable::InjectableError> where Self: Sized, @@ -260,15 +258,13 @@ pub mod subjects_async declare_interface!(Number -> INumber, threadsafe_sharable = true); #[async_trait] - impl - AsyncInjectable for Number + impl AsyncInjectable for Number where - DIContainerType: IAsyncDIContainer, - DependencyHistoryType: IDependencyHistory + Send + Sync + 'static, + DIContainerType: IAsyncDIContainer, { async fn resolve( _: &Arc, - _dependency_history: DependencyHistoryType, + _dependency_history: DependencyHistory, ) -> Result, crate::errors::injectable::InjectableError> where Self: Sized, @@ -290,27 +286,22 @@ pub mod mocks use std::rc::Rc; use super::*; - use crate::dependency_history::IDependencyHistory; use crate::di_container::blocking::binding::builder::BindingBuilder; use crate::di_container::blocking::details::DIContainerInternals; use crate::di_container::blocking::IDIContainer; use crate::errors::di_container::DIContainerError; use crate::provider::blocking::IProvider; use crate::ptr::SomePtr; + use crate::util::use_dependency_history; + + use_dependency_history!(); mock! { - pub DIContainer - where - DependencyHistoryType: IDependencyHistory + 'static - {} + pub DIContainer {} - impl IDIContainer for - DIContainer - where - DependencyHistoryType: IDependencyHistory + 'static + impl IDIContainer for DIContainer { - fn bind(self: &mut Rc) -> - BindingBuilder + fn bind(self: &mut Rc) -> BindingBuilder where Interface: 'static + ?Sized; @@ -328,18 +319,14 @@ pub mod mocks #[doc(hidden)] fn get_bound( self: &Rc, - dependency_history: DependencyHistoryType, + dependency_history: DependencyHistory, name: Option<&'static str>, ) -> Result, DIContainerError> where Interface: 'static + ?Sized; } - impl DIContainerInternals< - DependencyHistoryType - > for DIContainer - where - DependencyHistoryType: IDependencyHistory + impl DIContainerInternals for DIContainer { fn has_binding(self: &Rc, name: Option<&'static str>) -> bool where @@ -349,14 +336,14 @@ pub mod mocks fn set_binding( self: &Rc, name: Option<&'static str>, - provider: Box>, + provider: Box>, ) where Interface: 'static + ?Sized; fn remove_binding( self: &Rc, name: Option<&'static str>, - ) -> Option>> + ) -> Option>> where Interface: 'static + ?Sized; } @@ -369,29 +356,24 @@ pub mod mocks use std::sync::Arc; use super::*; - use crate::dependency_history::IDependencyHistory; use crate::di_container::asynchronous::binding::builder::AsyncBindingBuilder; use crate::di_container::asynchronous::details::DIContainerInternals; use crate::di_container::asynchronous::IAsyncDIContainer; use crate::errors::async_di_container::AsyncDIContainerError; use crate::provider::r#async::IAsyncProvider; use crate::ptr::SomePtr; + use crate::util::use_dependency_history; + + use_dependency_history!(); mock! { - pub AsyncDIContainer - where - DependencyHistoryType: IDependencyHistory + 'static + Send + Sync - {} + pub AsyncDIContainer {} #[async_trait::async_trait] - impl IAsyncDIContainer< - DependencyHistoryType - > for AsyncDIContainer - where - DependencyHistoryType: IDependencyHistory + 'static + Send + Sync + impl IAsyncDIContainer for AsyncDIContainer { fn bind(self: &mut Arc) -> - AsyncBindingBuilder + AsyncBindingBuilder where Interface: 'static + ?Sized + Send + Sync; @@ -411,7 +393,7 @@ pub mod mocks #[doc(hidden)] async fn get_bound( self: &Arc, - dependency_history: DependencyHistoryType, + dependency_history: DependencyHistory, name: Option<&'static str>, ) -> Result, AsyncDIContainerError> where @@ -419,11 +401,7 @@ pub mod mocks } #[async_trait::async_trait] - impl DIContainerInternals< - DependencyHistoryType - > for AsyncDIContainer - where - DependencyHistoryType: IDependencyHistory + 'static + Send + Sync + impl DIContainerInternals for AsyncDIContainer { async fn has_binding( self: &Arc, @@ -435,14 +413,14 @@ pub mod mocks async fn set_binding( self: &Arc, name: Option<&'static str>, - provider: Box>, + provider: Box>, ) where Interface: 'static + ?Sized; async fn remove_binding( self: &Arc, name: Option<&'static str>, - ) -> Option>> + ) -> Option>> where Interface: 'static + ?Sized; } @@ -457,34 +435,31 @@ pub mod mocks use async_trait::async_trait; use super::*; - use crate::dependency_history::IDependencyHistory; use crate::di_container::asynchronous::IAsyncDIContainer; use crate::errors::injectable::InjectableError; use crate::provider::r#async::{AsyncProvidable, IAsyncProvider}; + use crate::util::use_dependency_history; + + use_dependency_history!(); mock! { - pub AsyncProvider< - DIContainerType: IAsyncDIContainer, - DependencyHistoryType: IDependencyHistory + Send + Sync - > {} + pub AsyncProvider {} #[async_trait] impl< - DIContainerType: IAsyncDIContainer, - DependencyHistoryType: IDependencyHistory + Send + Sync - > IAsyncProvider for AsyncProvider< + DIContainerType: IAsyncDIContainer, + > IAsyncProvider for AsyncProvider< DIContainerType, - DependencyHistoryType > { async fn provide( &self, di_container: &Arc, - dependency_history: DependencyHistoryType - ) -> Result, InjectableError>; + dependency_history: DependencyHistory + ) -> Result, InjectableError>; fn do_clone(&self) -> - Box>; + Box>; } } } @@ -494,47 +469,31 @@ pub mod mocks use std::rc::Rc; use super::*; - use crate::dependency_history::IDependencyHistory; use crate::di_container::blocking::IDIContainer; use crate::errors::injectable::InjectableError; use crate::provider::blocking::{IProvider, Providable}; + use crate::util::use_dependency_history; + + use_dependency_history!(); mock! { - pub Provider + pub Provider where - DIContainerType: IDIContainer, - DependencyHistoryType: IDependencyHistory, + DIContainerType: IDIContainer {} - impl IProvider< - DIContainerType, - DependencyHistoryType - > for Provider - where - DIContainerType: IDIContainer, - DependencyHistoryType: IDependencyHistory + impl IProvider for Provider + where + DIContainerType: IDIContainer, { fn provide( &self, di_container: &Rc, - dependency_history: DependencyHistoryType, - ) -> Result, InjectableError>; + dependency_history: DependencyHistory, + ) -> Result, InjectableError>; } } } - - mock! { - pub DependencyHistory {} - - impl crate::dependency_history::IDependencyHistory for DependencyHistory - { - fn push(&mut self); - - fn contains(&self) -> bool; - } - - impl crate::dependency_history::private::Sealed for DependencyHistory {} - } } #[cfg(feature = "async")] -- cgit v1.2.3-18-g5258