Skip to content

Commit

Permalink
fix: skipDoubleRegistration with instanceName
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightOfBlackLily committed Oct 6, 2024
1 parent 14a177f commit a0d3612
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/get_it_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,9 @@ class _GetItImplementation implements GetIt {
);

/// skip double registration
if (skipDoubleRegistration && !allowReassignment) {
if (skipDoubleRegistration &&
!allowReassignment &&
existingTypeRegistration.namedFactories.containsKey(instanceName)) {
return;
}
} else {
Expand Down
21 changes: 21 additions & 0 deletions test/skip_double_registration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ void main() {
expect(getIt<DataStore>(), isA<MockDataStore>());
});

test(' Ignores Double named registration error ', () async {
final getIt = GetIt.instance;
const instanceName = 'named';
getIt.reset();
getIt.allowReassignment = false;
getIt.skipDoubleRegistration = true;
getIt.registerSingleton<DataStore>(RemoteDataStore());
getIt.registerSingleton<DataStore>(
MockDataStore(),
instanceName: instanceName,
);
getIt.registerSingleton<DataStore>(MockDataStore());
getIt.registerSingleton<DataStore>(
RemoteDataStore(),
instanceName: instanceName,
);

expect(getIt<DataStore>(), isA<RemoteDataStore>());
expect(getIt<DataStore>(instanceName: instanceName), isA<MockDataStore>());
});

test(' does not care about [skipDoubleRegistration] varibale ', () async {
final getIt = GetIt.instance;
getIt.reset();
Expand Down

0 comments on commit a0d3612

Please sign in to comment.