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/mod.rs | 43 ++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'src/di_container/blocking/mod.rs') diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking/mod.rs index cd7065c..5781583 100644 --- a/src/di_container/blocking/mod.rs +++ b/src/di_container/blocking/mod.rs @@ -54,7 +54,6 @@ use std::any::type_name; use std::cell::RefCell; use std::rc::Rc; -use crate::dependency_history::{DependencyHistory, IDependencyHistory}; use crate::di_container::binding_storage::DIContainerBindingStorage; use crate::di_container::blocking::binding::builder::BindingBuilder; use crate::errors::di_container::DIContainerError; @@ -62,6 +61,9 @@ use crate::private::cast::boxed::CastBox; use crate::private::cast::rc::CastRc; use crate::provider::blocking::{IProvider, Providable}; use crate::ptr::SomePtr; +use crate::util::use_dependency_history; + +use_dependency_history!(); pub mod binding; pub mod prelude; @@ -69,15 +71,10 @@ pub mod prelude; /// Blocking dependency injection container interface. /// /// **This trait is sealed and cannot be implemented for types outside this crate.** -pub trait IDIContainer: - Sized + 'static + details::DIContainerInternals -where - DependencyHistoryType: IDependencyHistory, +pub trait IDIContainer: Sized + 'static + details::DIContainerInternals { /// Returns a new [`BindingBuilder`] for the given interface. - fn bind( - self: &mut Rc, - ) -> BindingBuilder + fn bind(self: &mut Rc) -> BindingBuilder where Interface: 'static + ?Sized; @@ -109,7 +106,7 @@ where #[doc(hidden)] fn get_bound( self: &Rc, - dependency_history: DependencyHistoryType, + dependency_history: DependencyHistory, name: Option<&'static str>, ) -> Result, DIContainerError> where @@ -119,8 +116,7 @@ where /// Blocking dependency injection container. pub struct DIContainer { - binding_storage: - RefCell>>, + binding_storage: RefCell>>, } impl DIContainer @@ -135,11 +131,9 @@ impl DIContainer } } -impl IDIContainer for DIContainer +impl IDIContainer for DIContainer { - fn bind( - self: &mut Rc, - ) -> BindingBuilder + fn bind(self: &mut Rc) -> BindingBuilder where Interface: 'static + ?Sized, { @@ -183,7 +177,7 @@ impl IDIContainer for DIContainer } } -impl details::DIContainerInternals for DIContainer +impl details::DIContainerInternals for DIContainer { fn has_binding(self: &Rc, name: Option<&'static str>) -> bool where @@ -195,7 +189,7 @@ impl details::DIContainerInternals for DIContainer fn set_binding( self: &Rc, name: Option<&'static str>, - provider: Box>, + provider: Box>, ) where Interface: 'static + ?Sized, { @@ -207,7 +201,7 @@ impl details::DIContainerInternals for DIContainer fn remove_binding( self: &Rc, name: Option<&'static str>, - ) -> Option>> + ) -> Option>> where Interface: 'static + ?Sized, { @@ -219,7 +213,7 @@ impl DIContainer { fn handle_binding_providable( #[cfg(feature = "factory")] self: &Rc, - binding_providable: Providable, + binding_providable: Providable, ) -> Result, DIContainerError> where Interface: 'static + ?Sized, @@ -278,7 +272,7 @@ impl DIContainer self: &Rc, name: Option<&'static str>, dependency_history: DependencyHistory, - ) -> Result, DIContainerError> + ) -> Result, DIContainerError> where Interface: 'static + ?Sized, { @@ -306,12 +300,9 @@ pub(crate) mod details { use std::rc::Rc; - use crate::dependency_history::IDependencyHistory; use crate::provider::blocking::IProvider; - pub trait DIContainerInternals - where - DependencyHistoryType: IDependencyHistory, + pub trait DIContainerInternals { fn has_binding(self: &Rc, name: Option<&'static str>) -> bool where @@ -320,14 +311,14 @@ pub(crate) mod details fn set_binding( self: &Rc, name: Option<&'static str>, - provider: Box>, + provider: Box>, ) where Interface: 'static + ?Sized; fn remove_binding( self: &Rc, name: Option<&'static str>, - ) -> Option>> + ) -> Option>> where Interface: 'static + ?Sized; } -- cgit v1.2.3-18-g5258