diff options
Diffstat (limited to 'src/di_container')
-rw-r--r-- | src/di_container/asynchronous.rs (renamed from src/di_container/asynchronous/mod.rs) | 84 | ||||
-rw-r--r-- | src/di_container/asynchronous/binding.rs (renamed from src/di_container/asynchronous/binding/mod.rs) | 0 | ||||
-rw-r--r-- | src/di_container/asynchronous/binding/builder.rs | 100 | ||||
-rw-r--r-- | src/di_container/blocking.rs (renamed from src/di_container/blocking/mod.rs) | 56 | ||||
-rw-r--r-- | src/di_container/blocking/binding.rs (renamed from src/di_container/blocking/binding/mod.rs) | 0 | ||||
-rw-r--r-- | src/di_container/blocking/binding/builder.rs | 55 | ||||
-rw-r--r-- | src/di_container/mod.rs | 43 |
7 files changed, 138 insertions, 200 deletions
diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous.rs index 3e29ef6..6cb54f3 100644 --- a/src/di_container/asynchronous/mod.rs +++ b/src/di_container/asynchronous.rs @@ -51,15 +51,17 @@ //! ``` use std::any::type_name; +use crate::castable_function::threadsafe::ThreadsafeCastableFunction; use crate::di_container::asynchronous::binding::builder::AsyncBindingBuilder; use crate::di_container::binding_storage::DIContainerBindingStorage; use crate::di_container::BindingOptions; use crate::errors::async_di_container::AsyncDIContainerError; +use crate::future::BoxFuture; use crate::private::cast::arc::CastArc; use crate::private::cast::boxed::CastBox; use crate::private::cast::error::CastError; -use crate::provider::r#async::{AsyncProvidable, IAsyncProvider}; -use crate::ptr::SomePtr; +use crate::provider::r#async::{AsyncProvidable, IAsyncProvider, ProvidableFunctionKind}; +use crate::ptr::{SomePtr, TransientPtr}; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); @@ -347,12 +349,10 @@ impl AsyncDIContainer )) } #[cfg(feature = "factory")] - AsyncProvidable::Factory(factory_binding) => { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - - let factory = factory_binding + AsyncProvidable::Function(func_bound, ProvidableFunctionKind::UserCalled) => { + let factory = func_bound .as_any() - .downcast_ref::<ThreadsafeCastableFactory<Interface, Self>>() + .downcast_ref::<ThreadsafeCastableFunction<Interface, Self>>() .ok_or_else(|| AsyncDIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "factory", @@ -360,48 +360,42 @@ impl AsyncDIContainer Ok(SomePtr::ThreadsafeFactory(factory.call(self).into())) } - #[cfg(feature = "factory")] - AsyncProvidable::DefaultFactory(binding) => { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - use crate::ptr::TransientPtr; - - type DefaultFactoryFn<Interface> = ThreadsafeCastableFactory< + AsyncProvidable::Function(func_bound, ProvidableFunctionKind::Instant) => { + type Func<Interface> = ThreadsafeCastableFunction< dyn Fn() -> TransientPtr<Interface> + Send + Sync, AsyncDIContainer, >; - let default_factory = binding + let dynamic_val_func = func_bound .as_any() - .downcast_ref::<DefaultFactoryFn<Interface>>() + .downcast_ref::<Func<Interface>>() .ok_or_else(|| AsyncDIContainerError::CastFailed { - interface: type_name::<DefaultFactoryFn<Interface>>(), - binding_kind: "default factory", + interface: type_name::<Func<Interface>>(), + binding_kind: "dynamic value func", })?; - Ok(SomePtr::Transient(default_factory.call(self)())) + Ok(SomePtr::Transient(dynamic_val_func.call(self)())) } - #[cfg(feature = "factory")] - AsyncProvidable::AsyncDefaultFactory(binding) => { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - use crate::future::BoxFuture; - use crate::ptr::TransientPtr; - - type AsyncDefaultFactoryFn<Interface> = ThreadsafeCastableFactory< - dyn Fn<(), Output = BoxFuture<'static, TransientPtr<Interface>>> - + Send - + Sync, + AsyncProvidable::Function( + func_bound, + ProvidableFunctionKind::AsyncInstant, + ) => { + type Func<Interface> = ThreadsafeCastableFunction< + dyn Fn() -> BoxFuture<'static, TransientPtr<Interface>> + Send + Sync, AsyncDIContainer, >; - let async_default_factory = binding + let async_dynamic_value_func = func_bound .as_any() - .downcast_ref::<AsyncDefaultFactoryFn<Interface>>() + .downcast_ref::<Func<Interface>>() .ok_or_else(|| AsyncDIContainerError::CastFailed { - interface: type_name::<AsyncDefaultFactoryFn<Interface>>(), - binding_kind: "async default factory", + interface: type_name::<Func<Interface>>(), + binding_kind: "async dynamic value function", })?; - Ok(SomePtr::Transient(async_default_factory.call(self)().await)) + Ok(SomePtr::Transient( + async_dynamic_value_func.call(self)().await, + )) } } } @@ -652,7 +646,10 @@ mod tests } } - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; + use std::sync::Arc; + + use crate::castable_function::threadsafe::ThreadsafeCastableFunction; + use crate::provider::r#async::ProvidableFunctionKind; type IUserManagerFactory = dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager> + Send + Sync; @@ -672,10 +669,9 @@ mod tests }; inner_mock_provider.expect_provide().returning(|_, _| { - Ok(AsyncProvidable::Factory( - crate::ptr::ThreadsafeFactoryPtr::new( - ThreadsafeCastableFactory::new(factory_func), - ), + Ok(AsyncProvidable::Function( + Arc::new(ThreadsafeCastableFunction::new(factory_func)), + ProvidableFunctionKind::UserCalled, )) }); @@ -734,7 +730,10 @@ mod tests } } - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; + use std::sync::Arc; + + use crate::castable_function::threadsafe::ThreadsafeCastableFunction; + use crate::provider::r#async::ProvidableFunctionKind; type IUserManagerFactory = dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager> + Send + Sync; @@ -754,10 +753,9 @@ mod tests }; inner_mock_provider.expect_provide().returning(|_, _| { - Ok(AsyncProvidable::Factory( - crate::ptr::ThreadsafeFactoryPtr::new( - ThreadsafeCastableFactory::new(factory_func), - ), + Ok(AsyncProvidable::Function( + Arc::new(ThreadsafeCastableFunction::new(factory_func)), + ProvidableFunctionKind::UserCalled, )) }); diff --git a/src/di_container/asynchronous/binding/mod.rs b/src/di_container/asynchronous/binding.rs index 6a09bff..6a09bff 100644 --- a/src/di_container/asynchronous/binding/mod.rs +++ b/src/di_container/asynchronous/binding.rs diff --git a/src/di_container/asynchronous/binding/builder.rs b/src/di_container/asynchronous/binding/builder.rs index f42e6a1..db1b576 100644 --- a/src/di_container/asynchronous/binding/builder.rs +++ b/src/di_container/asynchronous/binding/builder.rs @@ -1,13 +1,17 @@ //! Binding builder for types inside of a [`AsyncDIContainer`]. use std::any::type_name; use std::marker::PhantomData; +use std::sync::Arc; +use crate::castable_function::threadsafe::ThreadsafeCastableFunction; use crate::di_container::asynchronous::binding::scope_configurator::AsyncBindingScopeConfigurator; -#[cfg(feature = "factory")] use crate::di_container::asynchronous::binding::when_configurator::AsyncBindingWhenConfigurator; use crate::di_container::BindingOptions; use crate::errors::async_di_container::AsyncBindingBuilderError; +use crate::future::BoxFuture; use crate::interfaces::async_injectable::AsyncInjectable; +use crate::provider::r#async::{AsyncFunctionProvider, ProvidableFunctionKind}; +use crate::ptr::TransientPtr; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); @@ -173,8 +177,10 @@ where Interface: Fn<Args, Output = Return> + Send + Sync, FactoryFunc: Fn(&AsyncDIContainer) -> BoxFn<Args, Return> + Send + Sync, { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - use crate::provider::r#async::AsyncFactoryVariant; + use std::sync::Arc; + + use crate::castable_function::threadsafe::ThreadsafeCastableFunction; + use crate::provider::r#async::ProvidableFunctionKind; if self .di_container @@ -186,13 +192,13 @@ where ))); } - let factory_impl = ThreadsafeCastableFactory::new(factory_func); + let factory_impl = ThreadsafeCastableFunction::new(factory_func); self.di_container.set_binding::<Interface>( BindingOptions::new(), - Box::new(crate::provider::r#async::AsyncFactoryProvider::new( - crate::ptr::ThreadsafeFactoryPtr::new(factory_impl), - AsyncFactoryVariant::Normal, + Box::new(crate::provider::r#async::AsyncFunctionProvider::new( + Arc::new(factory_impl), + ProvidableFunctionKind::UserCalled, )), ); @@ -270,9 +276,6 @@ where + Send + Sync, { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - use crate::provider::r#async::AsyncFactoryVariant; - if self .di_container .has_binding::<Interface>(BindingOptions::new()) @@ -283,21 +286,21 @@ where ))); } - let factory_impl = ThreadsafeCastableFactory::new(factory_func); + let factory_impl = ThreadsafeCastableFunction::new(factory_func); self.di_container.set_binding::<Interface>( BindingOptions::new(), - Box::new(crate::provider::r#async::AsyncFactoryProvider::new( - crate::ptr::ThreadsafeFactoryPtr::new(factory_impl), - AsyncFactoryVariant::Normal, + Box::new(AsyncFunctionProvider::new( + Arc::new(factory_impl), + ProvidableFunctionKind::UserCalled, )), ); Ok(AsyncBindingWhenConfigurator::new(self.di_container)) } - /// Creates a binding of type `Interface` to a factory that takes no arguments - /// inside of the associated [`AsyncDIContainer`]. + /// Creates a binding of type `Interface` to a value resolved using the given + /// function. /// /// # Errors /// Will return Err if the associated [`AsyncDIContainer`] already have a binding @@ -325,7 +328,7 @@ where /// # { /// # let mut di_container = AsyncDIContainer::new(); /// # - /// di_container.bind::<dyn Foo>().to_default_factory(&|_| { + /// di_container.bind::<dyn Foo>().to_dynamic_value(&|_| { /// Box::new(|| { /// let bar = TransientPtr::new(Bar { /// num: 42, @@ -339,24 +342,20 @@ where /// # Ok(()) /// # } /// ``` - #[cfg(feature = "factory")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] - pub fn to_default_factory<Return, FactoryFunc>( + pub fn to_dynamic_value<Func>( self, - factory_func: &'static FactoryFunc, + func: &'static Func, ) -> Result< AsyncBindingWhenConfigurator<'di_container, Interface>, AsyncBindingBuilderError, > where - Return: 'static + ?Sized, - FactoryFunc: Fn(&AsyncDIContainer) -> BoxFn<(), crate::ptr::TransientPtr<Return>> + Func: Fn( + &AsyncDIContainer, + ) -> Box<dyn Fn() -> TransientPtr<Interface> + Send + Sync> + Send + Sync, { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - use crate::provider::r#async::AsyncFactoryVariant; - if self .di_container .has_binding::<Interface>(BindingOptions::new()) @@ -367,21 +366,21 @@ where ))); } - let factory_impl = ThreadsafeCastableFactory::new(factory_func); + let castable_func = ThreadsafeCastableFunction::new(func); self.di_container.set_binding::<Interface>( BindingOptions::new(), - Box::new(crate::provider::r#async::AsyncFactoryProvider::new( - crate::ptr::ThreadsafeFactoryPtr::new(factory_impl), - AsyncFactoryVariant::Default, + Box::new(AsyncFunctionProvider::new( + Arc::new(castable_func), + ProvidableFunctionKind::Instant, )), ); Ok(AsyncBindingWhenConfigurator::new(self.di_container)) } - /// Creates a binding of factory type `Interface` to a async factory inside of the - /// associated [`AsyncDIContainer`]. + /// Creates a binding of type `Interface` to a value resolved using the given + /// async function. /// /// # Errors /// Will return Err if the associated [`AsyncDIContainer`] already have a binding @@ -412,7 +411,7 @@ where /// # /// di_container /// .bind::<dyn Foo>() - /// .to_async_default_factory(&|_| { + /// .to_async_dynamic_value(&|_| { /// Box::new(|| { /// Box::pin(async { /// let bar = TransientPtr::new(Bar { @@ -430,24 +429,21 @@ where /// # Ok(()) /// # } /// ``` - #[cfg(feature = "factory")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] - pub fn to_async_default_factory<Return, FactoryFunc>( + pub fn to_async_dynamic_value<Func>( self, - factory_func: &'static FactoryFunc, + func: &'static Func, ) -> Result< AsyncBindingWhenConfigurator<'di_container, Interface>, AsyncBindingBuilderError, > where - Return: 'static + ?Sized, - FactoryFunc: Fn(&AsyncDIContainer) -> BoxFn<(), crate::future::BoxFuture<'static, Return>> - + Send + Func: Fn( + &AsyncDIContainer, + ) -> Box< + dyn Fn() -> BoxFuture<'static, TransientPtr<Interface>> + Send + Sync, + > + Send + Sync, { - use crate::castable_factory::threadsafe::ThreadsafeCastableFactory; - use crate::provider::r#async::AsyncFactoryVariant; - if self .di_container .has_binding::<Interface>(BindingOptions::new()) @@ -458,13 +454,13 @@ where ))); } - let factory_impl = ThreadsafeCastableFactory::new(factory_func); + let castable_func = ThreadsafeCastableFunction::new(func); self.di_container.set_binding::<Interface>( BindingOptions::new(), - Box::new(crate::provider::r#async::AsyncFactoryProvider::new( - crate::ptr::ThreadsafeFactoryPtr::new(factory_impl), - AsyncFactoryVariant::AsyncDefault, + Box::new(AsyncFunctionProvider::new( + Arc::new(castable_func), + ProvidableFunctionKind::AsyncInstant, )), ); @@ -599,8 +595,7 @@ mod tests } #[tokio::test] - #[cfg(feature = "factory")] - async fn can_bind_to_default_factory() + async fn can_bind_to_dynamic_value() { use crate::ptr::TransientPtr; @@ -625,7 +620,7 @@ mod tests ); binding_builder - .to_default_factory(&|_| { + .to_dynamic_value(&|_| { Box::new(|| { let user_manager: TransientPtr<dyn subjects_async::IUserManager> = TransientPtr::new(subjects_async::UserManager::new()); @@ -637,8 +632,7 @@ mod tests } #[tokio::test] - #[cfg(feature = "factory")] - async fn can_bind_to_async_default_factory() + async fn can_bind_to_async_dynamic_value() { use crate::ptr::TransientPtr; use crate::test_utils::async_closure; @@ -664,7 +658,7 @@ mod tests ); binding_builder - .to_async_default_factory(&|_| { + .to_async_dynamic_value(&|_| { async_closure!(|| { let user_manager: TransientPtr<dyn subjects_async::IUserManager> = TransientPtr::new(subjects_async::UserManager::new()); diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking.rs index d9efe94..0c464df 100644 --- a/src/di_container/blocking/mod.rs +++ b/src/di_container/blocking.rs @@ -51,14 +51,15 @@ //! ``` use std::any::type_name; +use crate::castable_function::CastableFunction; use crate::di_container::binding_storage::DIContainerBindingStorage; use crate::di_container::blocking::binding::builder::BindingBuilder; use crate::di_container::BindingOptions; use crate::errors::di_container::DIContainerError; use crate::private::cast::boxed::CastBox; use crate::private::cast::rc::CastRc; -use crate::provider::blocking::{IProvider, Providable}; -use crate::ptr::SomePtr; +use crate::provider::blocking::{IProvider, Providable, ProvidableFunctionKind}; +use crate::ptr::{SomePtr, TransientPtr}; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); @@ -284,12 +285,10 @@ impl DIContainer })?, )), #[cfg(feature = "factory")] - Providable::Factory(factory_binding) => { - use crate::castable_factory::CastableFactory; - - let factory = factory_binding + Providable::Function(func_bound, ProvidableFunctionKind::UserCalled) => { + let factory = func_bound .as_any() - .downcast_ref::<CastableFactory<Interface, Self>>() + .downcast_ref::<CastableFunction<Interface, Self>>() .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "factory", @@ -297,23 +296,19 @@ impl DIContainer Ok(SomePtr::Factory(factory.call(self).into())) } - #[cfg(feature = "factory")] - Providable::DefaultFactory(factory_binding) => { - use crate::castable_factory::CastableFactory; - use crate::ptr::TransientPtr; - - type DefaultFactoryFn<Interface> = - CastableFactory<dyn Fn() -> TransientPtr<Interface>, DIContainer>; + Providable::Function(func_bound, ProvidableFunctionKind::Instant) => { + type Func<Interface> = + CastableFunction<dyn Fn() -> TransientPtr<Interface>, DIContainer>; - let default_factory = factory_binding + let dynamic_val_func = func_bound .as_any() - .downcast_ref::<DefaultFactoryFn<Interface>>() + .downcast_ref::<Func<Interface>>() .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::<Interface>(), - binding_kind: "default factory", + binding_kind: "dynamic value function", })?; - Ok(SomePtr::Transient(default_factory.call(self)())) + Ok(SomePtr::Transient(dynamic_val_func.call(self)())) } } } @@ -517,7 +512,10 @@ mod tests #[cfg(feature = "factory")] fn can_get_factory() { - use crate::castable_factory::CastableFactory; + use std::rc::Rc; + + use crate::castable_function::CastableFunction; + use crate::provider::blocking::ProvidableFunctionKind; use crate::ptr::FactoryPtr; trait IUserManager @@ -572,9 +570,10 @@ mod tests let mut mock_provider = MockIProvider::new(); mock_provider.expect_provide().returning_st(|_, _| { - Ok(Providable::Factory(FactoryPtr::new(CastableFactory::new( - factory_func, - )))) + Ok(Providable::Function( + Rc::new(CastableFunction::new(factory_func)), + ProvidableFunctionKind::UserCalled, + )) }); di_container @@ -592,8 +591,10 @@ mod tests #[cfg(feature = "factory")] fn can_get_factory_named() { - use crate::castable_factory::CastableFactory; - use crate::ptr::FactoryPtr; + use std::rc::Rc; + + use crate::castable_function::CastableFunction; + use crate::provider::blocking::ProvidableFunctionKind; trait IUserManager { @@ -647,9 +648,10 @@ mod tests let mut mock_provider = MockIProvider::new(); mock_provider.expect_provide().returning_st(|_, _| { - Ok(Providable::Factory(FactoryPtr::new(CastableFactory::new( - factory_func, - )))) + Ok(Providable::Function( + Rc::new(CastableFunction::new(factory_func)), + ProvidableFunctionKind::UserCalled, + )) }); di_container.binding_storage.set::<IUserManagerFactory>( diff --git a/src/di_container/blocking/binding/mod.rs b/src/di_container/blocking/binding.rs index 6a09bff..6a09bff 100644 --- a/src/di_container/blocking/binding/mod.rs +++ b/src/di_container/blocking/binding.rs diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index 9f7f6f9..596a2aa 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -1,13 +1,16 @@ //! Binding builder for types inside of a [`DIContainer`]. use std::any::type_name; use std::marker::PhantomData; +use std::rc::Rc; +use crate::castable_function::CastableFunction; 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::BindingOptions; use crate::errors::di_container::BindingBuilderError; use crate::interfaces::injectable::Injectable; +use crate::provider::blocking::{FunctionProvider, ProvidableFunctionKind}; +use crate::ptr::TransientPtr; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); @@ -181,8 +184,6 @@ where Interface: Fn<Args, Output = crate::ptr::TransientPtr<Return>>, Func: Fn(&DIContainer) -> Box<Interface>, { - use crate::castable_factory::CastableFactory; - if self .di_container .has_binding::<Interface>(BindingOptions::new()) @@ -192,21 +193,21 @@ where >())); } - let factory_impl = CastableFactory::new(factory_func); + let factory_impl = CastableFunction::new(factory_func); self.di_container.set_binding::<Interface>( BindingOptions::new(), - Box::new(crate::provider::blocking::FactoryProvider::new( - crate::ptr::FactoryPtr::new(factory_impl), - false, + Box::new(FunctionProvider::new( + Rc::new(factory_impl), + ProvidableFunctionKind::UserCalled, )), ); Ok(BindingWhenConfigurator::new(self.di_container)) } - /// Creates a binding of type `Interface` to a factory that takes no arguments - /// inside of the associated [`DIContainer`]. + /// Creates a binding of type `Interface` to a value resolved using the given + /// function. /// /// # Errors /// Will return Err if the associated [`DIContainer`] already have a binding for @@ -244,33 +245,20 @@ where /// # { /// # let mut di_container = DIContainer::new(); /// # - /// di_container.bind::<dyn IBuffer>().to_default_factory(&|_| { - /// Box::new(|| { - /// let buffer = TransientPtr::new(Buffer::<BUFFER_SIZE>::new()); - /// - /// buffer as TransientPtr<dyn IBuffer> - /// }) + /// di_container.bind::<dyn IBuffer>().to_dynamic_value(&|_| { + /// Box::new(|| TransientPtr::new(Buffer::<BUFFER_SIZE>::new())) /// }); /// # /// # Ok(()) /// # } /// ``` - #[cfg(feature = "factory")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] - pub fn to_default_factory<Return, FactoryFunc>( + pub fn to_dynamic_value<Func>( self, - factory_func: &'static FactoryFunc, + func: &'static Func, ) -> Result<BindingWhenConfigurator<'di_container, Interface>, BindingBuilderError> where - Return: 'static + ?Sized, - FactoryFunc: Fn( - &DIContainer, - ) -> crate::ptr::TransientPtr< - dyn Fn<(), Output = crate::ptr::TransientPtr<Return>>, - >, + Func: Fn(&DIContainer) -> TransientPtr<dyn Fn() -> TransientPtr<Interface>>, { - use crate::castable_factory::CastableFactory; - if self .di_container .has_binding::<Interface>(BindingOptions::new()) @@ -280,13 +268,13 @@ where >())); } - let factory_impl = CastableFactory::new(factory_func); + let castable_func = CastableFunction::new(func); self.di_container.set_binding::<Interface>( BindingOptions::new(), - Box::new(crate::provider::blocking::FactoryProvider::new( - crate::ptr::FactoryPtr::new(factory_impl), - true, + Box::new(FunctionProvider::new( + Rc::new(castable_func), + ProvidableFunctionKind::Instant, )), ); @@ -370,8 +358,7 @@ mod tests } #[test] - #[cfg(feature = "factory")] - fn can_bind_to_default_factory() + fn can_bind_to_dynamic_value() { use crate::ptr::TransientPtr; @@ -395,7 +382,7 @@ mod tests ); binding_builder - .to_default_factory(&|_| { + .to_dynamic_value(&|_| { Box::new(move || { let user_manager: TransientPtr<dyn subjects::IUserManager> = TransientPtr::new(subjects::UserManager::new()); diff --git a/src/di_container/mod.rs b/src/di_container/mod.rs deleted file mode 100644 index 4e60505..0000000 --- a/src/di_container/mod.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! Dependency injection container types. - -#[cfg(feature = "async")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] -pub mod asynchronous; - -pub mod blocking; - -/// DI container binding options. -/// -/// # Examples -/// ``` -/// # use syrette::di_container::BindingOptions; -/// # -/// BindingOptions::new().name("foo"); -/// ``` -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] -pub struct BindingOptions<'a> -{ - name: Option<&'a str>, -} - -impl<'a> BindingOptions<'a> -{ - /// Returns a new `BindingOptions`. - #[must_use] - pub const fn new() -> Self - { - Self { name: None } - } - - /// Returns `Self` with the specified name set. - #[must_use] - pub const fn name(mut self, name: &'a str) -> Self - { - self.name = Some(name); - - self - } -} - -// Private. -pub(crate) mod binding_storage; |