Skip to content

Commit

Permalink
Merge pull request #355 from tpucci/tpucci-getall
Browse files Browse the repository at this point in the history
fix: fix and test getAll
  • Loading branch information
escamoteur committed Mar 23, 2024
2 parents 6f539f4 + 8efccb6 commit 8d745af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/get_it_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ class _GetItImplementation implements GetIt {
}

final typeRegistration = registrationScope.typeRegistrations
.putIfAbsent(T, () => _TypeRegistration());
.putIfAbsent(T, () => _TypeRegistration<T>());

final serviceFactory = _ServiceFactory<T, P1, P2>(
this,
Expand Down
25 changes: 25 additions & 0 deletions test/get_it_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,31 @@ void main() {
GetIt.I.reset();
});

test('get all registered instances of the same type', () {
final getIt = GetIt.instance;
GetIt.allowRegisterMultipleImplementationsOfoneType = true;
constructorCounter = 0;

getIt.registerLazySingleton<TestBaseClass>(
() => TestClass(),
);
getIt.registerLazySingleton<TestBaseClass>(
() => TestClass(),
);

expect(constructorCounter, 0);

final Iterable<TestBaseClass> instances = getIt.getAll<TestBaseClass>();

expect(instances.length, 2);
expect(instances.first is TestClass, true);
expect(instances.last is TestClass, true);
expect(constructorCounter, 2);

GetIt.I.reset();
GetIt.allowRegisterMultipleImplementationsOfoneType = false;
});

test('reset lazy Singleton when the disposing function is a future',
() async {
final getIt = GetIt.instance;
Expand Down

0 comments on commit 8d745af

Please sign in to comment.