bug: Order annotation doesn't move dependent instances
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
Same problem. Did you find any solution? My code is heavily based on this structure
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.
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
@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 => <...>,
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
I do not recommend to use my solution, instead try using scopes