From 93a3a9b83ce864ebd66afb0a2f0c86cfd2bc8fd0 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Mon, 18 Mar 2024 09:50:49 +1300 Subject: [PATCH] Update to change DendencyConfig identity method to member hashing. This also paves the way to a future enhancement where dependency type aliases utilise the hash instead of an incrementing int - which will make them stable across changes to the dependency list --- .../lib/code_builder/builder_utils.dart | 2 +- .../lib/models/dependency_config.dart | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/injectable_generator/lib/code_builder/builder_utils.dart b/injectable_generator/lib/code_builder/builder_utils.dart index 9590878..07fa906 100644 --- a/injectable_generator/lib/code_builder/builder_utils.dart +++ b/injectable_generator/lib/code_builder/builder_utils.dart @@ -93,7 +93,7 @@ extension _InjectedDependencyX on InjectedDependency { @visibleForTesting Set sortDependencies(Iterable it) { // sort dependencies alphabetically by all the various attributes that may make them unique - final deps = it.toList()..sortBy((e) => e.toString()); + final deps = it.toList()..sortBy((e) => e.identityHash); // sort dependencies by their register order final List sorted = []; _sortByDependents(deps, sorted); diff --git a/injectable_generator/lib/models/dependency_config.dart b/injectable_generator/lib/models/dependency_config.dart index ded31e8..8978b84 100644 --- a/injectable_generator/lib/models/dependency_config.dart +++ b/injectable_generator/lib/models/dependency_config.dart @@ -32,7 +32,7 @@ class DependencyConfig { final int orderPosition; final String? scope; - const DependencyConfig({ + DependencyConfig({ required this.type, required this.typeImpl, this.injectableType = InjectableType.factory, @@ -144,6 +144,16 @@ class DependencyConfig { postConstructReturnsSelf.hashCode ^ scope.hashCode; + late final int identityHash = type.identity.hashCode ^ + typeImpl.identity.hashCode ^ + injectableType.hashCode ^ + instanceName.hashCode ^ + orderPosition.hashCode ^ + scope.hashCode ^ + const ListEquality().hash(dependencies) ^ + const ListEquality().hash(dependsOn) ^ + const ListEquality().hash(environments); + factory DependencyConfig.fromJson(Map json) { ModuleConfig? moduleConfig; DisposeFunctionConfig? disposeFunction;