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 --- macros/src/injectable/implementation.rs | 34 ++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'macros/src/injectable') diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs index bf168a4..9e97f45 100644 --- a/macros/src/injectable/implementation.rs +++ b/macros/src/injectable/implementation.rs @@ -420,14 +420,18 @@ impl InjectableImpl let method_call = parse_str::( format!( - "{}.get_bound::<{}>({}.clone(), {})", + concat!( + "{}.get_bound::<{}>({}.clone(), ", + "syrette::di_container::BindingOptions::new(){})" + ), DI_CONTAINER_VAR_NAME, dep_interface_str, DEPENDENCY_HISTORY_VAR_NAME, - dependency.get_name().as_ref().map_or_else( - || "None".to_string(), - |name| format!("Some(\"{}\")", name.value()) - ) + dependency + .get_name() + .as_ref() + .map(|name| format!(".name(\"{}\")", name.value())) + .unwrap_or_default() ) .as_str(), )?; @@ -900,7 +904,10 @@ mod tests parse2::(output)?, parse2::(quote! { #di_container_var_ident - .get_bound::(#dep_history_var_ident.clone(), None) + .get_bound::( + #dep_history_var_ident.clone(), + syrette::di_container::BindingOptions::new() + ) .map_err(|err| InjectableError::ResolveFailed { reason: Box::new(err), affected: self_type_name @@ -948,7 +955,10 @@ mod tests parse2::(output)?, parse2::(quote! { #di_container_var_ident - .get_bound::(#dep_history_var_ident.clone(), Some("special")) + .get_bound::( + #dep_history_var_ident.clone(), + syrette::di_container::BindingOptions::new().name("special") + ) .map_err(|err| InjectableError::ResolveFailed { reason: Box::new(err), affected: self_type_name @@ -994,7 +1004,10 @@ mod tests parse2::(output)?, parse2::(quote! { #di_container_var_ident - .get_bound::(#dep_history_var_ident.clone(), None) + .get_bound::( + #dep_history_var_ident.clone(), + syrette::di_container::BindingOptions::new() + ) .await .map_err(|err| InjectableError::AsyncResolveFailed { reason: Box::new(err), @@ -1044,7 +1057,10 @@ mod tests parse2::(output)?, parse2::(quote! { #di_container_var_ident - .get_bound::(#dep_history_var_ident.clone(), Some("foobar")) + .get_bound::( + #dep_history_var_ident.clone(), + syrette::di_container::BindingOptions::new().name("foobar") + ) .await .map_err(|err| InjectableError::AsyncResolveFailed { reason: Box::new(err), -- cgit v1.2.3-18-g5258