[][src]Attribute Macro coi_actix_web::inject

#[inject]

The #[inject] proc macro should only be applied to functions that will be passed to actix-web's routing APIs.

Examples

This example is not tested
use coi::inject;
 
#[inject]
async fn get_all(#[inject] service: Arc<dyn IService>) -> Result<impl Responder, ()> {
    ...
}

This proc macro changes the input arguments to the fn that it's applied to. All #[inject] args get collected into a single type and are pattern matched out. This is to take advantage of the coi-actix-web crate's FromResponse impls. By ensuring that all injected types are part of the same type, we can guarantee that all injected types are resolved from the same scoped container. The downside of this is that the signature you see is not what is generated, and this makes manually calling these functions more verbose. Since all of these functions are expected to be passed to actix-web's routing APIs, it's not an issue since those are all generic.