diff options
Diffstat (limited to 'src/di_container.rs')
-rw-r--r-- | src/di_container.rs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/di_container.rs b/src/di_container.rs index e42175b..b0e5af1 100644 --- a/src/di_container.rs +++ b/src/di_container.rs @@ -1,4 +1,4 @@ -//! Dependency injection container and other related utilities. +//! Dependency injection container. //! //! # Examples //! ``` @@ -53,7 +53,7 @@ use std::any::type_name; use std::marker::PhantomData; #[cfg(feature = "factory")] -use crate::castable_factory::CastableFactory; +use crate::castable_factory::blocking::CastableFactory; use crate::di_container_binding_map::DIContainerBindingMap; use crate::errors::di_container::{ BindingBuilderError, @@ -63,7 +63,12 @@ use crate::errors::di_container::{ }; use crate::interfaces::injectable::Injectable; use crate::libs::intertrait::cast::{CastBox, CastRc}; -use crate::provider::{Providable, SingletonProvider, TransientTypeProvider}; +use crate::provider::blocking::{ + IProvider, + Providable, + SingletonProvider, + TransientTypeProvider, +}; use crate::ptr::{SingletonPtr, SomePtr}; /// When configurator for a binding for type 'Interface' inside a [`DIContainer`]. @@ -256,7 +261,7 @@ where self.di_container.bindings.set::<Interface>( None, - Box::new(crate::provider::FactoryProvider::new( + Box::new(crate::provider::blocking::FactoryProvider::new( crate::ptr::FactoryPtr::new(factory_impl), )), ); @@ -290,7 +295,7 @@ where self.di_container.bindings.set::<Interface>( None, - Box::new(crate::provider::FactoryProvider::new( + Box::new(crate::provider::blocking::FactoryProvider::new( crate::ptr::FactoryPtr::new(factory_impl), )), ); @@ -302,7 +307,7 @@ where /// Dependency injection container. pub struct DIContainer { - bindings: DIContainerBindingMap, + bindings: DIContainerBindingMap<dyn IProvider>, } impl DIContainer @@ -416,7 +421,16 @@ impl DIContainer Interface: 'static + ?Sized, { self.bindings - .get::<Interface>(name)? + .get::<Interface>(name) + .map_or_else( + || { + Err(DIContainerError::BindingNotFound { + interface: type_name::<Interface>(), + name, + }) + }, + Ok, + )? .provide(self, dependency_history) .map_err(|err| DIContainerError::BindingResolveFailed { reason: err, @@ -442,7 +456,7 @@ mod tests use super::*; use crate::errors::injectable::InjectableError; - use crate::provider::IProvider; + use crate::provider::blocking::IProvider; use crate::ptr::TransientPtr; mod subjects |