From 613bf4a8a094df6f048cc8b1fcf2fc425abddd99 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 3 Oct 2023 19:38:22 +0200 Subject: refactor: remove inner mutability of blocking DI container --- src/di_container/blocking/binding/builder.rs | 12 ++++++------ src/di_container/blocking/binding/scope_configurator.rs | 16 ++++++++++------ src/di_container/blocking/binding/when_configurator.rs | 6 +++--- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/di_container/blocking/binding') diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index cd547d4..f322809 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -19,7 +19,7 @@ pub struct BindingBuilder<'di_container, Interface> where Interface: 'static + ?Sized, { - di_container: &'di_container DIContainer, + di_container: &'di_container mut DIContainer, dependency_history_factory: fn() -> DependencyHistory, interface_phantom: PhantomData, @@ -30,7 +30,7 @@ where Interface: 'static + ?Sized, { pub(crate) fn new( - di_container: &'di_container DIContainer, + di_container: &'di_container mut DIContainer, dependency_history_factory: fn() -> DependencyHistory, ) -> Self { @@ -98,7 +98,7 @@ where >())); } - let binding_scope_configurator = BindingScopeConfigurator::new( + let mut binding_scope_configurator = BindingScopeConfigurator::new( self.di_container, self.dependency_history_factory, ); @@ -324,7 +324,7 @@ mod tests .once(); let binding_builder = BindingBuilder::::new( - &mock_di_container, + &mut mock_di_container, MockDependencyHistory::new, ); @@ -358,7 +358,7 @@ mod tests .once(); let binding_builder = BindingBuilder::::new( - &mock_di_container, + &mut mock_di_container, MockDependencyHistory::new, ); @@ -400,7 +400,7 @@ mod tests .once(); let binding_builder = BindingBuilder::::new( - &mock_di_container, + &mut mock_di_container, MockDependencyHistory::new, ); diff --git a/src/di_container/blocking/binding/scope_configurator.rs b/src/di_container/blocking/binding/scope_configurator.rs index ee935a5..ef7578b 100644 --- a/src/di_container/blocking/binding/scope_configurator.rs +++ b/src/di_container/blocking/binding/scope_configurator.rs @@ -18,7 +18,7 @@ where Interface: 'static + ?Sized, Implementation: Injectable, { - di_container: &'di_container DIContainer, + di_container: &'di_container mut DIContainer, dependency_history_factory: fn() -> DependencyHistory, interface_phantom: PhantomData, @@ -32,7 +32,7 @@ where Implementation: Injectable, { pub(crate) fn new( - di_container: &'di_container DIContainer, + di_container: &'di_container mut DIContainer, dependency_history_factory: fn() -> DependencyHistory, ) -> Self { @@ -75,7 +75,9 @@ where /// # } /// ``` #[allow(clippy::must_use_candidate)] - pub fn in_transient_scope(self) -> BindingWhenConfigurator<'di_container, Interface> + pub fn in_transient_scope( + mut self, + ) -> BindingWhenConfigurator<'di_container, Interface> { self.set_in_transient_scope(); @@ -161,7 +163,7 @@ where Ok(BindingWhenConfigurator::new(self.di_container)) } - pub(crate) fn set_in_transient_scope(&self) + pub(crate) fn set_in_transient_scope(&mut self) { self.di_container.set_binding::( BindingOptions::new(), @@ -193,7 +195,8 @@ mod tests dyn subjects::IUserManager, subjects::UserManager, >::new( - &di_container_mock, MockDependencyHistory::new + &mut di_container_mock, + MockDependencyHistory::new, ); binding_scope_configurator.in_transient_scope(); @@ -214,7 +217,8 @@ mod tests dyn subjects::IUserManager, subjects::UserManager, >::new( - &di_container_mock, MockDependencyHistory::new + &mut di_container_mock, + MockDependencyHistory::new, ); assert!(binding_scope_configurator.in_singleton_scope().is_ok()); diff --git a/src/di_container/blocking/binding/when_configurator.rs b/src/di_container/blocking/binding/when_configurator.rs index d23d213..e40f7b9 100644 --- a/src/di_container/blocking/binding/when_configurator.rs +++ b/src/di_container/blocking/binding/when_configurator.rs @@ -13,7 +13,7 @@ pub struct BindingWhenConfigurator<'di_container, Interface> where Interface: 'static + ?Sized, { - di_container: &'di_container DIContainer, + di_container: &'di_container mut DIContainer, interface_phantom: PhantomData, } @@ -22,7 +22,7 @@ impl<'di_container, Interface> BindingWhenConfigurator<'di_container, Interface> where Interface: 'static + ?Sized, { - pub(crate) fn new(di_container: &'di_container DIContainer) -> Self + pub(crate) fn new(di_container: &'di_container mut DIContainer) -> Self { Self { di_container, @@ -115,7 +115,7 @@ mod tests .once(); let binding_when_configurator = - BindingWhenConfigurator::::new(&di_container_mock); + BindingWhenConfigurator::::new(&mut di_container_mock); assert!(binding_when_configurator.when_named("cool").is_ok()); } -- cgit v1.2.3-18-g5258