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/di_container/blocking/binding/builder.rs | 78 +++++++++++----------------- 1 file changed, 29 insertions(+), 49 deletions(-) (limited to 'src/di_container/blocking/binding/builder.rs') diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index 27151d7..991961c 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -5,40 +5,39 @@ use std::any::type_name; use std::marker::PhantomData; use std::rc::Rc; -use crate::dependency_history::IDependencyHistory; use crate::di_container::blocking::binding::scope_configurator::BindingScopeConfigurator; #[cfg(feature = "factory")] use crate::di_container::blocking::binding::when_configurator::BindingWhenConfigurator; use crate::di_container::blocking::IDIContainer; use crate::errors::di_container::BindingBuilderError; use crate::interfaces::injectable::Injectable; +use crate::util::use_dependency_history; + +use_dependency_history!(); /// Binding builder for type `Interface` inside a [`IDIContainer`]. /// /// [`IDIContainer`]: crate::di_container::blocking::IDIContainer #[must_use = "No binding will be created if you don't use the binding builder"] -pub struct BindingBuilder +pub struct BindingBuilder where Interface: 'static + ?Sized, - DIContainerType: IDIContainer, - DependencyHistoryType: IDependencyHistory, + DIContainerType: IDIContainer, { di_container: Rc, - dependency_history_factory: fn() -> DependencyHistoryType, + dependency_history_factory: fn() -> DependencyHistory, interface_phantom: PhantomData, } -impl - BindingBuilder +impl BindingBuilder where Interface: 'static + ?Sized, - DIContainerType: IDIContainer, - DependencyHistoryType: IDependencyHistory + 'static, + DIContainerType: IDIContainer, { pub(crate) fn new( di_container: Rc, - dependency_history_factory: fn() -> DependencyHistoryType, + dependency_history_factory: fn() -> DependencyHistory, ) -> Self { Self { @@ -93,16 +92,11 @@ where pub fn to( self, ) -> Result< - BindingScopeConfigurator< - Interface, - Implementation, - DIContainerType, - DependencyHistoryType, - >, + BindingScopeConfigurator, BindingBuilderError, > where - Implementation: Injectable, + Implementation: Injectable, { { if self.di_container.has_binding::(None) { @@ -194,10 +188,7 @@ where pub fn to_factory( self, factory_func: &'static Func, - ) -> Result< - BindingWhenConfigurator, - BindingBuilderError, - > + ) -> Result, BindingBuilderError> where Args: std::marker::Tuple + 'static, Return: 'static + ?Sized, @@ -283,10 +274,7 @@ where pub fn to_default_factory( self, factory_func: &'static FactoryFunc, - ) -> Result< - BindingWhenConfigurator, - BindingBuilderError, - > + ) -> Result, BindingBuilderError> where Return: 'static + ?Sized, FactoryFunc: Fn< @@ -326,6 +314,7 @@ mod tests use mockall::predicate::eq; use super::*; + use crate::dependency_history::MockDependencyHistory; use crate::test_utils::{mocks, subjects}; #[test] @@ -345,14 +334,11 @@ mod tests .return_once(|_name, _provider| ()) .once(); - let binding_builder = BindingBuilder::< - dyn subjects::INumber, - mocks::blocking_di_container::MockDIContainer, - mocks::MockDependencyHistory, - >::new( - Rc::new(mock_di_container), - mocks::MockDependencyHistory::new, - ); + let binding_builder = + BindingBuilder::< + dyn subjects::INumber, + mocks::blocking_di_container::MockDIContainer, + >::new(Rc::new(mock_di_container), MockDependencyHistory::new); binding_builder.to::()?; @@ -384,14 +370,11 @@ mod tests .return_once(|_name, _provider| ()) .once(); - let binding_builder = BindingBuilder::< - IUserManagerFactory, - mocks::blocking_di_container::MockDIContainer, - mocks::MockDependencyHistory, - >::new( - Rc::new(mock_di_container), - mocks::MockDependencyHistory::new, - ); + let binding_builder = + BindingBuilder::< + IUserManagerFactory, + mocks::blocking_di_container::MockDIContainer, + >::new(Rc::new(mock_di_container), MockDependencyHistory::new); binding_builder.to_factory(&|_| { Box::new(move |_num, _text| { @@ -430,14 +413,11 @@ mod tests .return_once(|_name, _provider| ()) .once(); - let binding_builder = BindingBuilder::< - dyn subjects::IUserManager, - mocks::blocking_di_container::MockDIContainer, - mocks::MockDependencyHistory, - >::new( - Rc::new(mock_di_container), - mocks::MockDependencyHistory::new, - ); + let binding_builder = + BindingBuilder::< + dyn subjects::IUserManager, + mocks::blocking_di_container::MockDIContainer, + >::new(Rc::new(mock_di_container), MockDependencyHistory::new); binding_builder.to_default_factory(&|_| { Box::new(move || { -- cgit v1.2.3-18-g5258