From 9bed6b4d2772fd020ea9eb6eaaba4ca014d96f94 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 14 Sep 2023 19:41:56 +0200 Subject: refactor!: remove blocking DI container interface BREAKING CHANGE: IDIContainer have been removed and multiple structs no longer take a DI container generic parameter --- src/provider/blocking.rs | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'src/provider') diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs index bc9134d..c719f59 100644 --- a/src/provider/blocking.rs +++ b/src/provider/blocking.rs @@ -1,7 +1,6 @@ use std::marker::PhantomData; use std::rc::Rc; -use crate::di_container::blocking::IDIContainer; use crate::errors::injectable::InjectableError; use crate::interfaces::injectable::Injectable; use crate::ptr::{SingletonPtr, TransientPtr}; @@ -11,8 +10,6 @@ use_double!(crate::dependency_history::DependencyHistory); #[derive(strum_macros::Display, Debug)] pub enum Providable -where - DIContainerType: IDIContainer, { Transient(TransientPtr>), Singleton(SingletonPtr>), @@ -22,10 +19,8 @@ where DefaultFactory(crate::ptr::FactoryPtr), } -#[cfg_attr(test, mockall::automock, allow(dead_code))] +#[cfg_attr(test, mockall::automock)] pub trait IProvider -where - DIContainerType: IDIContainer, { fn provide( &self, @@ -37,7 +32,6 @@ where pub struct TransientTypeProvider where InjectableType: Injectable, - DIContainerType: IDIContainer, { injectable_phantom: PhantomData, di_container_phantom: PhantomData, @@ -47,7 +41,6 @@ impl TransientTypeProvider where InjectableType: Injectable, - DIContainerType: IDIContainer, { pub fn new() -> Self { @@ -62,7 +55,6 @@ impl IProvider for TransientTypeProvider where InjectableType: Injectable, - DIContainerType: IDIContainer, { fn provide( &self, @@ -80,7 +72,6 @@ where pub struct SingletonProvider where InjectableType: Injectable, - DIContainerType: IDIContainer, { singleton: SingletonPtr, @@ -90,7 +81,6 @@ where impl SingletonProvider where InjectableType: Injectable, - DIContainerType: IDIContainer, { pub fn new(singleton: SingletonPtr) -> Self { @@ -105,7 +95,6 @@ impl IProvider for SingletonProvider where InjectableType: Injectable, - DIContainerType: IDIContainer, { fn provide( &self, @@ -141,8 +130,6 @@ impl FactoryProvider #[cfg(feature = "factory")] impl IProvider for FactoryProvider -where - DIContainerType: IDIContainer, { fn provide( &self, @@ -165,17 +152,16 @@ mod tests use super::*; use crate::dependency_history::MockDependencyHistory; - use crate::test_utils::{mocks, subjects}; + use crate::di_container::blocking::MockDIContainer; + use crate::test_utils::subjects; #[test] fn transient_type_provider_works() -> Result<(), Box> { - let transient_type_provider = TransientTypeProvider::< - subjects::UserManager, - mocks::blocking_di_container::MockDIContainer, - >::new(); + let transient_type_provider = + TransientTypeProvider::::new(); - let di_container = mocks::blocking_di_container::MockDIContainer::new(); + let di_container = MockDIContainer::new(); let dependency_history_mock = MockDependencyHistory::new(); @@ -195,12 +181,11 @@ mod tests fn singleton_provider_works() -> Result<(), Box> { let singleton_provider = - SingletonProvider::< - subjects::UserManager, - mocks::blocking_di_container::MockDIContainer, - >::new(SingletonPtr::new(subjects::UserManager {})); + SingletonProvider::::new( + SingletonPtr::new(subjects::UserManager {}), + ); - let di_container = mocks::blocking_di_container::MockDIContainer::new(); + let di_container = MockDIContainer::new(); assert!( matches!( @@ -230,7 +215,7 @@ mod tests let default_factory_provider = FactoryProvider::new(FactoryPtr::new(FooFactory), true); - let di_container = Rc::new(mocks::blocking_di_container::MockDIContainer::new()); + let di_container = Rc::new(MockDIContainer::new()); assert!( matches!( -- cgit v1.2.3-18-g5258