diff --git a/lib/get_it_impl.dart b/lib/get_it_impl.dart index e196c87..f669a58 100644 --- a/lib/get_it_impl.dart +++ b/lib/get_it_impl.dart @@ -1586,7 +1586,9 @@ class _GetItImplementation implements GetIt { ); /// skip double registration - if (skipDoubleRegistration && !allowReassignment) { + if (skipDoubleRegistration && + !allowReassignment && + existingTypeRegistration.namedFactories.containsKey(instanceName)) { return; } } else { diff --git a/test/skip_double_registration_test.dart b/test/skip_double_registration_test.dart index 4413f17..ed1421c 100644 --- a/test/skip_double_registration_test.dart +++ b/test/skip_double_registration_test.dart @@ -38,6 +38,27 @@ void main() { expect(getIt(), isA()); }); + test(' Ignores Double named registration error ', () async { + final getIt = GetIt.instance; + const instanceName = 'named'; + getIt.reset(); + getIt.allowReassignment = false; + getIt.skipDoubleRegistration = true; + getIt.registerSingleton(RemoteDataStore()); + getIt.registerSingleton( + MockDataStore(), + instanceName: instanceName, + ); + getIt.registerSingleton(MockDataStore()); + getIt.registerSingleton( + RemoteDataStore(), + instanceName: instanceName, + ); + + expect(getIt(), isA()); + expect(getIt(instanceName: instanceName), isA()); + }); + test(' does not care about [skipDoubleRegistration] varibale ', () async { final getIt = GetIt.instance; getIt.reset();