diff --git a/CHANGELOG.md b/CHANGELOG.md index e09ddcd..63de036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +## [8.0.0-pre-3] - 31.05.2024 releaseInstance will now throw if the instance isn't registered ## [8.0.0-pre-2] - 29.05.2024 fixing negitiv reference count ## [8.0.0-pre-1] - 26.05.2024 * `getAll()` and `getAllAsync()` now have a `fromAllScopes` parameter. diff --git a/lib/get_it_impl.dart b/lib/get_it_impl.dart index 648789a..bc7eecc 100644 --- a/lib/get_it_impl.dart +++ b/lib/get_it_impl.dart @@ -857,15 +857,13 @@ class _GetItImplementation implements GetIt { /// it will immediately unregister and dispose the object @override void releaseInstance(Object instance) { - final registerdFactory = _findFirstFactoryByInstanceOrNull(instance); - if (registerdFactory != null) { - if (registerdFactory._refenceCount < 1) { - assert(registerdFactory._refenceCount == 0, - 'GetIt: releaseInstance was called on an object that was already released'); - unregister(instance: instance); - } else { - registerdFactory._refenceCount--; - } + final registerdFactory = _findFactoryByInstance(instance); + if (registerdFactory._refenceCount < 1) { + assert(registerdFactory._refenceCount == 0, + 'GetIt: releaseInstance was called on an object that was already released'); + unregister(instance: instance); + } else { + registerdFactory._refenceCount--; } } @@ -1087,9 +1085,8 @@ class _GetItImplementation implements GetIt { ); _ServiceFactory? _findFirstFactoryByInstanceOrNull(Object instance) { - final registeredFactories = - _allFactories.where((x) => identical(x.instance, instance)); - return registeredFactories.isEmpty ? null : registeredFactories.first; + return _allFactories + .firstWhereOrNull((x) => identical(x.instance, instance)); } _ServiceFactory _findFactoryByInstance(Object instance) { diff --git a/pubspec.yaml b/pubspec.yaml index 5cfebb2..26bda3e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: get_it description: Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App" -version: 8.0.0-pre-2 +version: 8.0.0-pre-3 maintainer: Thomas Burkhart (@escamoteur) homepage: https://github.com/fluttercommunity/get_it funding: