From 0b4232d343e2214ead8fa62583bff2e948173ddf Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 20 Aug 2023 17:01:12 +0200 Subject: feat: expose DI container get_bound methods to public API --- src/di_container/asynchronous/mod.rs | 85 ++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 19 deletions(-) (limited to 'src/di_container/asynchronous/mod.rs') diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous/mod.rs index 2939ddd..e5f7f5d 100644 --- a/src/di_container/asynchronous/mod.rs +++ b/src/di_container/asynchronous/mod.rs @@ -59,6 +59,7 @@ use async_trait::async_trait; 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; @@ -116,14 +117,50 @@ pub trait IAsyncDIContainer: 'a: 'b, Self: 'b; - #[doc(hidden)] - async fn get_bound( - self: &Arc, + /// Returns the type bound with `Interface` where the binding has the specified + /// options. + /// + /// `dependency_history` is passed to the bound type when it is being resolved. + /// + /// # Errors + /// Will return `Err` if: + /// - No binding for `Interface` exists + /// - Resolving the binding for `Interface` fails + /// - Casting the binding for `Interface` fails + /// + /// # Examples + /// ``` + /// # use syrette::di_container::asynchronous::AsyncDIContainer; + /// # use syrette::di_container::asynchronous::IAsyncDIContainer; + /// # use syrette::dependency_history::DependencyHistory; + /// # use syrette::di_container::BindingOptions; + /// # + /// # struct EventHandler {} + /// # struct Button {} + /// # + /// # Box::pin(async { + /// # let di_container = AsyncDIContainer::new(); + /// # + /// let mut dependency_history = DependencyHistory::new(); + /// + /// dependency_history.push::(); + /// + /// di_container + /// .get_bound::