nicolascotton / nject

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

Adding support for modules to export internal shared dependencies #16

Closed nicolascotton closed 1 year ago

nicolascotton commented 1 year ago

Proposal:

mod sub {
    #[injectable]
    struct InternalType( #[inject(123)] i32); // Not visible outside of module.

    #[injectable]
    pub struct Facade<'a> {
        hidden: &'a InternalType
    }

    #[module]
    pub struct Module {
        #[export]
        hidden: InternalType
    }
}

#[provider]
struct Provider {
    #[import]
    subModule: sub::Module
}

fn main() {
    #[provider]
    struct InitProvider;

    let provider = InitProvider.provide::<Provider>();
    let _facade = provider.provide::<sub::Facade>();
}