| Crates.io | xdi-macro |
| lib.rs | xdi-macro |
| version | 0.1.0 |
| created_at | 2025-08-01 14:48:01.582109+00 |
| updated_at | 2025-08-01 14:48:01.582109+00 |
| description | Rust di containers system |
| homepage | https://github.com/Vidrochka/xdi |
| repository | https://github.com/Vidrochka/xdi |
| max_upload_size | |
| id | 1776903 |
| size | 10,659 |
Type injection for xdi
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 {}
// As transient (for transient scope param can be omitted)
#[xdi_macro::register_constructor(scope = "transient")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
// As singleton
#[xdi_macro::register_constructor(scope = "singleton")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
// As thread local
#[xdi_macro::register_constructor(scope = "thread_local")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
// As task local
#[xdi_macro::register_constructor(scope = "task_local")]
fn some_service_ctor(_sp: ServiceProvider) -> ServiceBuildResult<SomeService> {
Ok(SomeService{})
}
// For every scope you can define multiple trait map
#[xdi_macro::register_constructor(scope = "transient", map = [ISomeService1, ISomeService2])]
fn some_service_ctor() {
Ok(SomeService{})
}