mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 13:47:24 +00:00
docs: update README (en/ru) to reflect adapter-based universalRegistration pattern
- Show type-safe DIAdapter-centric registration for all scenarios - Document new way to add scenarios/DI via universalRegistration<S extends Enum> - Remove legacy function-based registration/manual switching from guide - Provide examples for Dart and CLI usage with all DI adapters
This commit is contained in:
@@ -88,11 +88,97 @@ Switch DI with the CLI option: `--di`
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Universal DI registration: Adapter-centric approach
|
||||||
|
|
||||||
|
Starting from vX.Y.Z, all DI registration scenarios and logic are encapsulated in the adapter itself via the `universalRegistration` method.
|
||||||
|
|
||||||
|
### How to use (in Dart code):
|
||||||
|
|
||||||
|
```dart
|
||||||
|
final di = CherrypickDIAdapter(); // or GetItAdapter(), RiverpodAdapter(), etc
|
||||||
|
|
||||||
|
di.setupDependencies(
|
||||||
|
di.universalRegistration(
|
||||||
|
scenario: UniversalScenario.chain,
|
||||||
|
chainCount: 10,
|
||||||
|
nestingDepth: 5,
|
||||||
|
bindingMode: UniversalBindingMode.singletonStrategy,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
```
|
||||||
|
- There is **no more need to use any global function or switch**: each adapter provides its own type-safe implementation.
|
||||||
|
|
||||||
|
### How to add a new scenario or DI:
|
||||||
|
- Implement `universalRegistration<S extends Enum>(...)` in your adapter
|
||||||
|
- Use your own Enum if you want adapter-specific scenarios!
|
||||||
|
- Benchmarks and CLI become automatically extensible for custom DI and scenarios.
|
||||||
|
|
||||||
|
### CLI usage (runs all universal scenarios for Cherrypick, GetIt, Riverpod):
|
||||||
|
|
||||||
|
```
|
||||||
|
dart run bin/main.dart --di=cherrypick --benchmark=all
|
||||||
|
dart run bin/main.dart --di=getit --benchmark=all
|
||||||
|
dart run bin/main.dart --di=riverpod --benchmark=all
|
||||||
|
```
|
||||||
|
|
||||||
|
See the `benchmark_di/lib/di_adapters/` folder for ready-to-use adapters.
|
||||||
|
|
||||||
|
---
|
||||||
|
## Advantages
|
||||||
|
|
||||||
|
- **Type-safe:** Zero dynamic/object usage in DI flows.
|
||||||
|
- **Extensible:** New scenarios are just new Enum values and a method extension.
|
||||||
|
- **No global registration logic:** All DI-related logic is where it belongs: in the adapter.
|
||||||
|
|
||||||
|
=======
|
||||||
## How to Add Your Own DI
|
## How to Add Your Own DI
|
||||||
|
|
||||||
1. Implement a class extending `DIAdapter` (`lib/di_adapters/your_adapter.dart`)
|
1. Implement a class extending `DIAdapter` (`lib/di_adapters/your_adapter.dart`)
|
||||||
2. Register it in CLI (see `cli/benchmark_cli.dart`)
|
2. Implement the `universalRegistration<S extends Enum>(...)` method directly in your adapter for type-safe and scenario-specific registration
|
||||||
3. Add registration logic to `di_universal_registration.dart` to build chains for your DI
|
3. Register your adapter in CLI (see `cli/benchmark_cli.dart`)
|
||||||
|
4. No global function needed — all logic is within the adapter!
|
||||||
|
|
||||||
|
---
|
||||||
|
## Universal DI registration: Adapter-centric approach
|
||||||
|
|
||||||
|
Starting from vX.Y.Z, all DI registration scenarios and logic are encapsulated in the adapter itself via the `universalRegistration` method.
|
||||||
|
|
||||||
|
### How to use (in Dart code):
|
||||||
|
|
||||||
|
```dart
|
||||||
|
final di = CherrypickDIAdapter(); // or GetItAdapter(), RiverpodAdapter(), etc
|
||||||
|
|
||||||
|
di.setupDependencies(
|
||||||
|
di.universalRegistration(
|
||||||
|
scenario: UniversalScenario.chain,
|
||||||
|
chainCount: 10,
|
||||||
|
nestingDepth: 5,
|
||||||
|
bindingMode: UniversalBindingMode.singletonStrategy,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
```
|
||||||
|
- There is **no more need to use any global function or switch**: each adapter provides its own type-safe implementation.
|
||||||
|
|
||||||
|
### How to add a new scenario or DI:
|
||||||
|
- Implement `universalRegistration<S extends Enum>(...)` in your adapter
|
||||||
|
- Use your own Enum if you want adapter-specific scenarios!
|
||||||
|
- Benchmarks and CLI become automatically extensible for custom DI and scenarios.
|
||||||
|
|
||||||
|
### CLI usage (runs all universal scenarios for Cherrypick, GetIt, Riverpod):
|
||||||
|
|
||||||
|
```
|
||||||
|
dart run bin/main.dart --di=cherrypick --benchmark=all
|
||||||
|
dart run bin/main.dart --di=getit --benchmark=all
|
||||||
|
dart run bin/main.dart --di=riverpod --benchmark=all
|
||||||
|
```
|
||||||
|
|
||||||
|
See the `benchmark_di/lib/di_adapters/` folder for ready-to-use adapters.
|
||||||
|
|
||||||
|
## Advantages
|
||||||
|
|
||||||
|
- **Type-safe:** Zero dynamic/object usage in DI flows.
|
||||||
|
- **Extensible:** New scenarios are just new Enum values and a method extension.
|
||||||
|
- **No global registration logic:** All DI-related logic is where it belongs: in the adapter.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -88,11 +88,48 @@ benchmark_di — это современный фреймворк для изм
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Как добавить свой DI
|
## Универсальная регистрация зависимостей: теперь через adapter
|
||||||
|
|
||||||
|
В версии X.Y.Z вся логика сценариев регистрации DI-инфраструктуры локализована в adapter через метод `universalRegistration`.
|
||||||
|
|
||||||
|
### Использование в Dart:
|
||||||
|
|
||||||
|
```dart
|
||||||
|
final di = CherrypickDIAdapter(); // или GetItAdapter(), RiverpodAdapter() и т.д.
|
||||||
|
|
||||||
|
di.setupDependencies(
|
||||||
|
di.universalRegistration(
|
||||||
|
scenario: UniversalScenario.chain,
|
||||||
|
chainCount: 10,
|
||||||
|
nestingDepth: 5,
|
||||||
|
bindingMode: UniversalBindingMode.singletonStrategy,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
```
|
||||||
|
- **Теперь нет необходимости вызывать глобальные функции или switch-case по типу DI!** Каждый adapter сам предоставляет типобезопасную функцию регистрации.
|
||||||
|
|
||||||
|
### Как добавить новый сценарий или DI:
|
||||||
|
|
||||||
|
- Реализуйте метод `universalRegistration<S extends Enum>(...)` в своём adapter.
|
||||||
|
- Можно использовать как UniversalScenario, так и собственные enum-сценарии!
|
||||||
|
- Бенчмарки CLI автоматически расширяются под ваш DI и ваши сценарии, если реализован метод-расширение.
|
||||||
|
|
||||||
|
### Запуск CLI (все сценарии DI Cherrypick, GetIt, Riverpod):
|
||||||
|
|
||||||
|
```
|
||||||
|
dart run bin/main.dart --di=cherrypick --benchmark=all
|
||||||
|
dart run bin/main.dart --di=getit --benchmark=all
|
||||||
|
dart run bin/main.dart --di=riverpod --benchmark=all
|
||||||
|
```
|
||||||
|
|
||||||
|
Смотрите примеры готовых adapters в `benchmark_di/lib/di_adapters/`.
|
||||||
|
|
||||||
|
## Преимущества
|
||||||
|
|
||||||
|
- **Type-safe:** Исключено использование dynamic/object в стороне DI.
|
||||||
|
- **Масштабируемость:** Новый сценарий — просто enum + метод в adapter.
|
||||||
|
- **Вся логика регистрации теперь только в adapter:** Добавление или изменение не затрагивает глобальные функции.
|
||||||
|
|
||||||
1. Реализуйте класс-адаптер, реализующий `DIAdapter` (`lib/di_adapters/ваш_adapter.dart`)
|
|
||||||
2. Зарегистрируйте его в CLI (`cli/benchmark_cli.dart`)
|
|
||||||
3. Дополните универсальную функцию регистрации (`di_universal_registration.dart`), чтобы строить цепочки для вашего DI
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user