refactor: full generic DIAdapter workflow & universalRegistration abstraction

- Made UniversalChainBenchmark and UniversalChainAsyncBenchmark fully generic with strong typing for DIAdapter<TContainer>
- Moved all universalRegistration logic inside adapters; removed global function and typedef
- Replaced dynamic/object-based registration with type-safe generic contracts end-to-end
- Updated CLI and usage: all DI and scenarios are invoked via type-safe generics
- Fixed all analysis errors, Riverpod async/future usages, and imports for full Dart 3 compatibility
- All benchmarks fully pass for Cherrypick, GetIt, and Riverpod adapters
This commit is contained in:
Sergey Penkovsky
2025-08-07 14:11:29 +03:00
parent 54446868e4
commit 56bdb3946e
8 changed files with 223 additions and 204 deletions

View File

@@ -1,7 +1,7 @@
import 'package:cherrypick/cherrypick.dart';
import 'di_adapter.dart';
import '../scenarios/universal_chain_module.dart';
/// Универсальный DIAdapter для CherryPick с поддержкой subScope без дублирования логики.
class CherrypickDIAdapter extends DIAdapter<Scope> {
Scope? _scope;
final bool _isSubScope;
@@ -16,6 +16,28 @@ class CherrypickDIAdapter extends DIAdapter<Scope> {
registration(_scope!);
}
@override
Registration<Scope> universalRegistration<S extends Enum>({
required S scenario,
required int chainCount,
required int nestingDepth,
required UniversalBindingMode bindingMode,
}) {
if (scenario is UniversalScenario) {
return (scope) {
scope.installModules([
UniversalChainModule(
chainCount: chainCount,
nestingDepth: nestingDepth,
bindingMode: bindingMode,
scenario: scenario,
),
]);
};
}
throw UnsupportedError('Scenario $scenario not supported by CherrypickDIAdapter');
}
@override
T resolve<T extends Object>({String? named}) =>
named == null ? _scope!.resolve<T>() : _scope!.resolve<T>(named: named);