nicolascotton / nject

Simple zero cost dependency injection library made for rust
MIT License
45 stars 3 forks source link

Simplify provider initialisation #53

Open nicolascotton opened 1 week ago

nicolascotton commented 1 week ago

Instead of chaining provider with dependent modules like so:

    #[provider]
    struct InitProvider;

    #[injectable]
    #[provider]
    struct Provider0(#[import] FooModule);

    #[injectable]
    #[provider]
    struct Provider1<'a>(#[import] FooModule, #[import] BarModule<'a>);

    let provider0: Provider0 = InitProvider.provide();
    let provider1: Provider1 = provider0.provide();

We could introduce a macro to simplify the process:

    #[injectable]
    #[provider]
    struct Provider<'a>(#[import] FooModule, #[import] BarModule<'a>);

    let provider: Provider = init!(FooModule, BarModule<'a>);