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

bug: Order annotation doesn't move dependent instances #454

Open
jamontes79 opened this issue May 2, 2024 · 4 comments
Open

bug: Order annotation doesn't move dependent instances #454

jamontes79 opened this issue May 2, 2024 · 4 comments

Comments

@jamontes79
Copy link
Contributor

If I have the following code

@singleton
@Order(-1)
class InitFeatureTogglesUseCase {
  InitFeatureTogglesUseCase(
    this._buildConfig,
    this._hiddenSettingsRepository,
    this._featureToggleRepository,
  );

The generated code is the following:

gh.singleton<_i3.InitFeatureTogglesUseCase>(_i3.InitFeatureTogglesUseCase(
      gh<_i4.BuildConfig>(),
      gh<_i5.HiddenSettingsRepository>(),
      gh<_i6.FeatureToggleRepository>(),
    )

But the instances of BuildConfig, HiddenSettingsRepository and FeatureToggleRepository are not instantiated because they have no order.

Any way of doing this without reordering manually all the instances?

Thanks in advance

@vicenterusso
Copy link

Same problem. Did you find any solution? My code is heavily based on this structure

@jamontes79
Copy link
Contributor Author

Same problem. Did you find any solution? My code is heavily based on this structure

I've made a workaround using scopes and grouped some specific classes.

It's not the best approach, but it work for us.

@equescodebelike
Copy link

equescodebelike commented Dec 26, 2024

same there, solution with scopes is the best
but i found something pricky

@singleton
Future<FooInterface> bar(FooRepository repository, IJohn john, IDoe doe) async {
...
// returns implementation of FooInterface
}

and the point, that I do not use IJohn john and IDoe doe fields in this singleton, but they init first. And i need such order of init

@LordOfTheApples123
Copy link

@jamontes79, late reply, but nevertheless
Swapping annotations seems to fix the problem

@Order(-1)
@singleton
class InitFeatureTogglesUseCase {
  InitFeatureTogglesUseCase(
    this._buildConfig,
    this._hiddenSettingsRepository,
    this._featureToggleRepository,
  );

allthough you wiil need to register objects you use in constructor before this.

  @Order(-2)
  BuildConfig get config => <...>,
  @Order(-2)
  HiddenSettingsRepository get repo1 => <...>,
  @Order(-2)
  FeatureToggleRepository get repo2 => <...>,

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