diff --git a/ferrunix-macros/src/inject.rs b/ferrunix-macros/src/inject.rs index 679fbe3..14f13cd 100644 --- a/ferrunix-macros/src/inject.rs +++ b/ferrunix-macros/src/inject.rs @@ -143,6 +143,8 @@ fn registration_fields( let dependency_tuple = into_dependency_tuple(&fields); let dependency_idents = into_dependency_idents(&fields); let constructor = type_ctor(registered_ty, input, &fields)?; + let constructor = box_if_required(&constructor); + let ifawait = await_if_needed(); let tokens = match (dependency_tuple, dependency_idents) { (Some(types), Some(idents)) => { @@ -151,7 +153,7 @@ fn registration_fields( .with_deps::<#registered_ty, #types>() .#dependency_type(|#idents| { #constructor - }); + })#ifawait; } } @@ -159,7 +161,7 @@ fn registration_fields( quote! { registry.#dependency_type::<#registered_ty>(|| { #constructor - }); + })#ifawait; } } }; diff --git a/ferrunix/tests/it/derive_async.rs b/ferrunix/tests/it/derive_async.rs index ef40633..381958d 100644 --- a/ferrunix/tests/it/derive_async.rs +++ b/ferrunix/tests/it/derive_async.rs @@ -2,9 +2,9 @@ use ferrunix::{Inject, RegistrationFunc, Registry}; -#[derive(Inject)] -#[provides(transient)] -struct Empty {} +// #[derive(Inject)] +// #[provides(transient)] +// struct Empty {} // #[automatically_derived] // impl Empty { @@ -25,11 +25,19 @@ struct Empty {} // } // } -ferrunix::autoregister!(RegistrationFunc::new(Empty::register)); +// ferrunix::autoregister!(RegistrationFunc::new(Empty::register)); + +#[derive(Inject)] +#[provides(transient = "StringTemplate")] +struct StringTemplate { + #[inject(ctor = r#""The Magic Number is ""#)] + raw: &'static str, +} + #[tokio::test] async fn simple_derive() { let registry = Registry::autoregistered().await; - let _obj = registry.get_transient::().await.unwrap(); + // let _obj = registry.get_transient::().await.unwrap(); }