xdi-macro
Type injection for xdi
Injection
You can inject service as fn constructor
All type ctors will be automatically registered on builder creation
Injection use inventory, so you can add injection from dependency crate
pub struct SomeService {}
trait ISomeService1 {}
impl ISomeService1 for SomeService {}
trait ISomeService2 {}
impl ISomeService2 for SomeService {}
#[xdi_macro::register_constructor(scope = "transient")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
#[xdi_macro::register_constructor(scope = "singleton")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
#[xdi_macro::register_constructor(scope = "thread_local")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
#[xdi_macro::register_constructor(scope = "task_local")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
#[xdi_macro::register_constructor(scope = "transient", map = [ISomeService1, ISomeService2])]
fn some_service_ctor() {
Ok(SomeService{})
}