Skip to content

Commit

Permalink
update version and changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Milad-Akarie committed Mar 6, 2024
1 parent 1758048 commit 05d8f0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
20 changes: 6 additions & 14 deletions injectable/lib/src/get_it_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ class GetItHelper {
late final EnvironmentFilter _environmentFilter;

/// creates a new instance of GetItHelper
GetItHelper(this.getIt,
[String? environment, EnvironmentFilter? environmentFilter])
GetItHelper(this.getIt, [String? environment, EnvironmentFilter? environmentFilter])
: assert(environmentFilter == null || environment == null) {
// register current EnvironmentsFilter as lazy singleton
if (!getIt.isRegistered<EnvironmentFilter>(
instanceName: kEnvironmentsFilterName)) {
if (!getIt.isRegistered<EnvironmentFilter>(instanceName: kEnvironmentsFilterName)) {
_environmentFilter = environmentFilter ?? NoEnvOrContains(environment);
getIt.registerLazySingleton<EnvironmentFilter>(
() => _environmentFilter,
instanceName: kEnvironmentsFilterName,
);
} else {
_environmentFilter =
getIt<EnvironmentFilter>(instanceName: kEnvironmentsFilterName);
_environmentFilter = getIt<EnvironmentFilter>(instanceName: kEnvironmentsFilterName);
}

// register current Environments as lazy singleton
Expand Down Expand Up @@ -215,12 +212,10 @@ class GetItHelper {
if (_canRegister(registerFor)) {
if (preResolve) {
return factoryFunc().then(
(instance) => singleton(
(instance) => getIt.registerSingleton(
() => instance,
instanceName: instanceName,
signalsReady: signalsReady,
registerFor: registerFor,
dispose: dispose,
),
);
} else {
Expand Down Expand Up @@ -260,8 +255,7 @@ class GetItHelper {
/// a helper method to push a new scope and init it's dependencies
/// asynchronously inside of [GetIt]
Future<GetIt> initScopeAsync(String name,
{required Future<void> Function(GetItHelper gh) init,
ScopeDisposeFunc? dispose}) {
{required Future<void> Function(GetItHelper gh) init, ScopeDisposeFunc? dispose}) {
final completer = Completer<GetIt>();
getIt.pushNewScope(
scopeName: name,
Expand All @@ -276,9 +270,7 @@ class GetItHelper {

/// a helper method to push a new scope and init it's dependencies
/// inside of [GetIt]
GetIt initScope(String name,
{required void Function(GetItHelper gh) init,
ScopeDisposeFunc? dispose}) {
GetIt initScope(String name, {required void Function(GetItHelper gh) init, ScopeDisposeFunc? dispose}) {
getIt.pushNewScope(
scopeName: name,
init: (_) => init(this),
Expand Down
14 changes: 7 additions & 7 deletions injectable_generator/test/code_builder/eager_singleton_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
type: ImportableType(name: 'Demo'),
typeImpl: ImportableType(name: 'Demo'),
)),
'gh.singleton<Demo>(Demo());');
'gh.singleton<Demo>(() => Demo());');
});

test("Singleton generator abstract", () {
Expand All @@ -26,7 +26,7 @@ void main() {
type: ImportableType(name: 'AbstractType'),
typeImpl: ImportableType(name: 'Demo'),
)),
'gh.singleton<AbstractType>(Demo());',
'gh.singleton<AbstractType>(() => Demo());',
);
});

Expand All @@ -38,7 +38,7 @@ void main() {
typeImpl: ImportableType(name: 'Demo'),
instanceName: 'MyDemo',
)),
"gh.singleton<Demo>(Demo(), instanceName: 'MyDemo', );",
"gh.singleton<Demo>(() => Demo(), instanceName: 'MyDemo', );",
);
});

Expand Down Expand Up @@ -98,7 +98,7 @@ void main() {
)
],
)),
'gh.singleton<Demo>(Demo(gh<Storage>()));');
'gh.singleton<Demo>(() => Demo(gh<Storage>()));');
});

test("Singleton generator with async Positional dependencies", () {
Expand Down Expand Up @@ -143,7 +143,7 @@ void main() {
)
],
)),
'gh.singleton<Demo>(Demo(storage: gh<Storage>()));');
'gh.singleton<Demo>(() => Demo(storage: gh<Storage>()));');
});

test("Singleton generator with async named dependencies", () {
Expand Down Expand Up @@ -201,7 +201,7 @@ void main() {
),
];
expect(generate(dep, allDeps: allDeps),
'gh.singleton<Demo>(Demo(storage: gh<Storage>(instanceName: \'storageImpl\')));');
'gh.singleton<Demo>(() => Demo(storage: gh<Storage>(instanceName: \'storageImpl\')));');
});
});
}
Expand All @@ -219,4 +219,4 @@ String generate(DependencyConfig input, {List<DependencyConfig>? allDeps}) {
useNullSafetySyntax: false,
);
return statement.accept(emitter).toString();
}
}

0 comments on commit 05d8f0a

Please sign in to comment.