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

When generating code, errors occur due to disordered sequencing. #458

Open
kerneltea opened this issue May 8, 2024 · 4 comments
Open

When generating code, errors occur due to disordered sequencing. #458

kerneltea opened this issue May 8, 2024 · 4 comments

Comments

@kerneltea
Copy link

kerneltea commented May 8, 2024

  • injectable: 2.4.1
  • injectable_generator: 2.6.1

Step 1 : In the code, I defined a structure like this.

@dev
@Singleton(as: EnvConfig)
class EnvConfigDev extends EnvConfig {
  EnvConfigDev() : super(Env.dev);

  @override
  String get apiUrl => Constants.saasApiDevHost;
}

@prod
@Singleton(as: EnvConfig)
class EnvConfigProd extends EnvConfig {
  EnvConfigProd() : super(Env.prod);

  @override
  String get apiUrl => Constants.saasApiHost;
}

@test
@Singleton(as: EnvConfig)
class EnvConfigTest extends EnvConfig {
  EnvConfigTest() : super(Env.test);

  @override
  String get apiUrl => Constants.saasApiHost;
}

Step 2 : use flutter packages pub run build_runner build --delete-conflicting-outputs to generate injectable.config.dart

_i1.GetIt init({
    String? environment,
    _i2.EnvironmentFilter? environmentFilter,
  }) {
    final gh = _i2.GetItHelper(
      this,
      environment,
      environmentFilter,
    );
    final registerModule = _$RegisterModule();
    .....
    /// line: 237
    gh.singleton<_i61.EnvConfig>(
      () => _i61.EnvConfigTest(),
      registerFor: {_test},
    );
    .....

    /// line: 274
    gh.singleton<_i61.EnvConfig>(
      () => _i61.EnvConfigDev(),
      registerFor: {_dev},
    );
   .....

    /// line: 288
    gh.singleton<_i75.ApiMethods>(
        () => _i75.ApiMethods.create(gh<_i61.EnvConfig>()));
   
    ....

    /// line: 342
    gh.singleton<_i61.EnvConfig>(
      () => _i61.EnvConfigProd(),
      registerFor: {_prod},
    );
     ....
    return this;
  }

Please take a look at the code. On line 288, the ApiMethods requires the EnvConfig parameter. However, if I use the prod environment parameter here, ApiMethods will not be generated. This is because the prod version of EnvConfig is defined only on line 342, which will cause an error here.

Previously, with version 2.3.2 of injectable and 2.4.1 of injectable_generator, everything worked normally.

The latest versions being used are:

  • injectable: 2.4.1
  • injectable_generator: 2.6.1
@ciprig
Copy link

ciprig commented May 10, 2024

I have noticed a similar issue in 2.6.1.@Adam-Langley, works in <=2.6.0 with a workaround to have the same dependencies for all environments even if not needed.

@akaegi
Copy link

akaegi commented Jun 17, 2024

Can confirm this issue: With version 2.6.1 of injectable_generator I get a wrong order of getIt registrations where in 2.6.0 it was still correct. Does it have something to do with use of environements? Cause in dev environment services everything was fine in my config, but maybe that was just pure luck...

@mariomka
Copy link

We’re experiencing the same issue. For now, we are downgrading to 2.6.0 as a workaround.

@ciprig
Copy link

ciprig commented Aug 23, 2024

Same issue on 2.6.2, is related with multiple enviroments

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

4 participants