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/di_container/blocking/binding/when_configurator.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/di_container/blocking/binding/when_configurator.rs')
-rw-r--r-- | src/di_container/blocking/binding/when_configurator.rs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/di_container/blocking/binding/when_configurator.rs b/src/di_container/blocking/binding/when_configurator.rs index 52b23ff..3d267b2 100644 --- a/src/di_container/blocking/binding/when_configurator.rs +++ b/src/di_container/blocking/binding/when_configurator.rs @@ -1,33 +1,29 @@ -//! When configurator for a binding for types inside of a [`IDIContainer`]. -//! -//! [`IDIContainer`]: crate::di_container::blocking::IDIContainer +//! When configurator for a binding for types inside of a [`DIContainer`]. use std::any::type_name; use std::marker::PhantomData; use std::rc::Rc; -use crate::di_container::blocking::IDIContainer; use crate::di_container::BindingOptions; use crate::errors::di_container::BindingWhenConfiguratorError; +use crate::util::use_double; -/// When configurator for a binding for type `Interface` inside a [`IDIContainer`]. -/// -/// [`IDIContainer`]: crate::di_container::blocking::IDIContainer -pub struct BindingWhenConfigurator<Interface, DIContainerType> +use_double!(crate::di_container::blocking::DIContainer); + +/// When configurator for a binding for type `Interface` inside a [`DIContainer`]. +pub struct BindingWhenConfigurator<Interface> where Interface: 'static + ?Sized, - DIContainerType: IDIContainer, { - di_container: Rc<DIContainerType>, + di_container: Rc<DIContainer>, interface_phantom: PhantomData<Interface>, } -impl<Interface, DIContainerType> BindingWhenConfigurator<Interface, DIContainerType> +impl<Interface> BindingWhenConfigurator<Interface> where Interface: 'static + ?Sized, - DIContainerType: IDIContainer, { - pub(crate) fn new(di_container: Rc<DIContainerType>) -> Self + pub(crate) fn new(di_container: Rc<DIContainer>) -> Self { Self { di_container, @@ -70,13 +66,14 @@ mod tests use mockall::predicate::eq; use super::*; + use crate::di_container::blocking::MockDIContainer; use crate::provider::blocking::MockIProvider; - use crate::test_utils::{mocks, subjects}; + use crate::test_utils::subjects; #[test] fn when_named_works() { - let mut di_container_mock = mocks::blocking_di_container::MockDIContainer::new(); + let mut di_container_mock = MockDIContainer::new(); di_container_mock .expect_remove_binding::<dyn subjects::INumber>() @@ -90,10 +87,10 @@ mod tests .return_once(|_name, _provider| ()) .once(); - let binding_when_configurator = BindingWhenConfigurator::< - dyn subjects::INumber, - mocks::blocking_di_container::MockDIContainer, - >::new(Rc::new(di_container_mock)); + let binding_when_configurator = + BindingWhenConfigurator::<dyn subjects::INumber>::new(Rc::new( + di_container_mock, + )); assert!(binding_when_configurator.when_named("cool").is_ok()); } |