diff options
author | HampusM <hampus@hampusmat.com> | 2023-08-20 17:01:12 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-08-20 17:01:12 +0200 |
commit | 0b4232d343e2214ead8fa62583bff2e948173ddf (patch) | |
tree | f809051c9933a132971ab91244e83d1f9d387ad6 /macros/src | |
parent | be2c39b452b8b1e024300caff1ce8f11d54b27ce (diff) |
feat: expose DI container get_bound methods to public API
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/injectable/implementation.rs | 34 |
1 files changed, 25 insertions, 9 deletions
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<Dep: IDependency> InjectableImpl<Dep> let method_call = parse_str::<ExprMethodCall>( 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::<Expr>(output)?, parse2::<Expr>(quote! { #di_container_var_ident - .get_bound::<Foo>(#dep_history_var_ident.clone(), None) + .get_bound::<Foo>( + #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::<Expr>(output)?, parse2::<Expr>(quote! { #di_container_var_ident - .get_bound::<Foo>(#dep_history_var_ident.clone(), Some("special")) + .get_bound::<Foo>( + #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::<Expr>(output)?, parse2::<Expr>(quote! { #di_container_var_ident - .get_bound::<Foo>(#dep_history_var_ident.clone(), None) + .get_bound::<Foo>( + #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::<Expr>(output)?, parse2::<Expr>(quote! { #di_container_var_ident - .get_bound::<Foo>(#dep_history_var_ident.clone(), Some("foobar")) + .get_bound::<Foo>( + #dep_history_var_ident.clone(), + syrette::di_container::BindingOptions::new().name("foobar") + ) .await .map_err(|err| InjectableError::AsyncResolveFailed { reason: Box::new(err), |