Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove module public exports ordering limitation #37

Open
nicolascotton opened this issue Feb 18, 2024 · 2 comments
Open

Remove module public exports ordering limitation #37

nicolascotton opened this issue Feb 18, 2024 · 2 comments

Comments

@nicolascotton
Copy link
Owner

nicolascotton commented Feb 18, 2024

Could be fixed by: rust-lang/rust#44034

@majkrzak
Copy link

majkrzak commented Aug 31, 2024

Do I understand correctly that this is the reason why following code does not work?

use bar::BarModule;
use foo::FooModule;
use nject::{injectable, provider};

mod foo {
    use nject::{injectable, module};

    pub struct Foo;

    #[injectable]
    #[module]
    pub struct FooModule(
        #[inject(|| Foo)]
        #[export]
        Foo,
    );
}
mod bar {
    use nject::{injectable, module};

    use crate::foo::Foo;
    #[injectable]
    pub struct Bar {
        foo: Foo,
    }

    #[injectable]
    #[module]
    pub struct BarModule(#[export] Bar);
}

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

    #[injectable]
    #[provider]
    struct Provider(#[import] FooModule, #[import] BarModule);

    let provider: Provider = InitProvider.provide();
}

I have encountered this why trying divide my code into multiple dependent modules. Not exactly sure if it is my bad understanding of how modules should be used, or an issue.

I can work it around by "staging" providers which leads to ridiculous code like bellow:

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

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

    #[injectable]
    #[provider]
    struct Provider1(#[import] FooModule, #[import] BarModule);

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

@nicolascotton
Copy link
Owner Author

Hi @majkrzak,

Unfortunately, this issue won't solve your problem.

The only way to make it work right now is by staging like you mentioned or manually injecting modules in the provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants