diff options
author | HampusM <hampus@hampusmat.com> | 2023-09-14 19:41:56 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-09-14 21:17:37 +0200 |
commit | 9bed6b4d2772fd020ea9eb6eaaba4ca014d96f94 (patch) | |
tree | dff0d7768f4a56c9d75e4a6c89974891373e997b /src/test_utils.rs | |
parent | 9a7cf8cfd376da09c982606aa79f253319dfe382 (diff) |
refactor!: remove blocking DI container interface
BREAKING CHANGE: IDIContainer have been removed and multiple structs no longer take a DI container generic parameter
Diffstat (limited to 'src/test_utils.rs')
-rw-r--r-- | src/test_utils.rs | 124 |
1 files changed, 7 insertions, 117 deletions
diff --git a/src/test_utils.rs b/src/test_utils.rs index a304a71..95b7ce1 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -7,7 +7,6 @@ pub mod subjects use syrette_macros::declare_interface; - use crate::di_container::blocking::IDIContainer; use crate::interfaces::injectable::Injectable; use crate::private::cast::CastFromArc; use crate::ptr::TransientPtr; @@ -49,12 +48,10 @@ pub mod subjects declare_interface!(UserManager -> IUserManager); - impl<DIContainerType> Injectable<DIContainerType> for UserManager - where - DIContainerType: IDIContainer, + impl<DIContainerT> Injectable<DIContainerT> for UserManager { fn resolve( - _di_container: &Rc<DIContainerType>, + _di_container: &Rc<DIContainerT>, _dependency_history: DependencyHistory, ) -> Result<TransientPtr<Self>, crate::errors::injectable::InjectableError> where @@ -115,12 +112,10 @@ pub mod subjects declare_interface!(Number -> INumber); - impl<DIContainerType> Injectable<DIContainerType> for Number - where - DIContainerType: IDIContainer, + impl<DIContainerT> Injectable<DIContainerT> for Number { fn resolve( - _di_container: &Rc<DIContainerType>, + _di_container: &Rc<DIContainerT>, _dependency_history: DependencyHistory, ) -> Result<TransientPtr<Self>, crate::errors::injectable::InjectableError> where @@ -279,87 +274,13 @@ pub mod mocks #![allow(clippy::ref_option_ref)] // Caused by Mockall #![allow(dead_code)] // Not all mock functions may be used - use mockall::mock; - - pub mod blocking_di_container - { - use std::rc::Rc; - - use super::*; - use crate::di_container::blocking::binding::builder::BindingBuilder; - use crate::di_container::blocking::details::DIContainerInternals; - use crate::di_container::blocking::{BindingOptionsWithLt, IDIContainer}; - use crate::di_container::BindingOptions; - use crate::errors::di_container::DIContainerError; - use crate::provider::blocking::IProvider; - use crate::ptr::SomePtr; - use crate::util::use_double; - - use_double!(crate::dependency_history::DependencyHistory); - - mock! { - pub DIContainer {} - - impl IDIContainer for DIContainer - { - fn bind<Interface>(self: &mut Rc<Self>) -> BindingBuilder<Interface, Self> - where - Interface: 'static + ?Sized; - - fn get<Interface>(self: &Rc<Self>) -> Result<SomePtr<Interface>, DIContainerError> - where - Interface: 'static + ?Sized; - - fn get_named<Interface>( - self: &Rc<Self>, - name: &'static str, - ) -> Result<SomePtr<Interface>, DIContainerError> - where - Interface: 'static + ?Sized; - - #[doc(hidden)] - fn get_bound<'opts, Interface>( - self: &Rc<Self>, - dependency_history: DependencyHistory, - binding_options: BindingOptionsWithLt, - ) -> Result<SomePtr<Interface>, DIContainerError> - where - Interface: 'static + ?Sized; - } - - impl DIContainerInternals for DIContainer - { - fn has_binding<Interface>( - self: &Rc<Self>, - binding_options: BindingOptionsWithLt - ) -> bool - where - Interface: ?Sized + 'static; - - #[doc(hidden)] - fn set_binding<Interface>( - self: &Rc<Self>, - binding_options: BindingOptions<'static>, - provider: Box<dyn IProvider<Self>>, - ) where - Interface: 'static + ?Sized; - - fn remove_binding<Interface>( - self: &Rc<Self>, - binding_options: BindingOptions<'static>, - ) -> Option<Box<dyn IProvider<Self>>> - where - Interface: 'static + ?Sized; - } - } - } - #[cfg(feature = "async")] pub mod async_di_container { use std::sync::Arc; - use super::*; + use mockall::mock; + use crate::di_container::asynchronous::binding::builder::AsyncBindingBuilder; use crate::di_container::asynchronous::details::DIContainerInternals; use crate::di_container::asynchronous::IAsyncDIContainer; @@ -438,8 +359,8 @@ pub mod mocks use std::sync::Arc; use async_trait::async_trait; + use mockall::mock; - use super::*; use crate::di_container::asynchronous::IAsyncDIContainer; use crate::errors::injectable::InjectableError; use crate::provider::r#async::{AsyncProvidable, IAsyncProvider}; @@ -468,37 +389,6 @@ pub mod mocks } } } - - pub mod blocking_provider - { - use std::rc::Rc; - - use super::*; - use crate::di_container::blocking::IDIContainer; - use crate::errors::injectable::InjectableError; - use crate::provider::blocking::{IProvider, Providable}; - use crate::util::use_double; - - use_double!(crate::dependency_history::DependencyHistory); - - mock! { - pub Provider<DIContainerType> - where - DIContainerType: IDIContainer - {} - - impl<DIContainerType> IProvider<DIContainerType> for Provider<DIContainerType> - where - DIContainerType: IDIContainer, - { - fn provide( - &self, - di_container: &Rc<DIContainerType>, - dependency_history: DependencyHistory, - ) -> Result<Providable<DIContainerType>, InjectableError>; - } - } - } } #[cfg(all(feature = "async", feature = "factory"))] |