mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 05:25:19 +00:00
refactor(structure): move benchmarks, scenarios, adapters, utils to dedicated folders; update imports/project layout
This commit is contained in:
9
benchmark_cherrypick/lib/scenarios/app_module.dart
Normal file
9
benchmark_cherrypick/lib/scenarios/app_module.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
import 'foo_service.dart';
|
||||
|
||||
class AppModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<FooService>().toProvide(() => FooService());
|
||||
}
|
||||
}
|
||||
20
benchmark_cherrypick/lib/scenarios/async_chain_module.dart
Normal file
20
benchmark_cherrypick/lib/scenarios/async_chain_module.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
class AsyncA {}
|
||||
class AsyncB {
|
||||
final AsyncA a;
|
||||
AsyncB(this.a);
|
||||
}
|
||||
class AsyncC {
|
||||
final AsyncB b;
|
||||
AsyncC(this.b);
|
||||
}
|
||||
|
||||
class AsyncChainModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<AsyncA>().toProvideAsync(() async => AsyncA()).singleton();
|
||||
bind<AsyncB>().toProvideAsync(() async => AsyncB(await currentScope.resolveAsync<AsyncA>())).singleton();
|
||||
bind<AsyncC>().toProvideAsync(() async => AsyncC(await currentScope.resolveAsync<AsyncB>())).singleton();
|
||||
}
|
||||
}
|
||||
42
benchmark_cherrypick/lib/scenarios/chain_factory_module.dart
Normal file
42
benchmark_cherrypick/lib/scenarios/chain_factory_module.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
// === DI graph: A -> B -> C (factory/no singleton) ===
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
import 'service.dart';
|
||||
import 'service_impl.dart';
|
||||
|
||||
class ChainFactoryModule extends Module {
|
||||
// количество независимых цепочек
|
||||
final int chainCount;
|
||||
|
||||
// глубина вложенности
|
||||
final int nestingDepth;
|
||||
|
||||
ChainFactoryModule({
|
||||
required this.chainCount,
|
||||
required this.nestingDepth,
|
||||
});
|
||||
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
for (var chainIndex = 0; chainIndex < chainCount; chainIndex++) {
|
||||
for (var levelIndex = 0; levelIndex < nestingDepth; levelIndex++) {
|
||||
final chain = chainIndex + 1;
|
||||
final level = levelIndex + 1;
|
||||
|
||||
final prevDepName = '${chain.toString()}_${(level - 1).toString()}';
|
||||
final depName = '${chain.toString()}_${level.toString()}';
|
||||
|
||||
bind<Service>()
|
||||
.toProvide(
|
||||
() => ServiceImpl(
|
||||
value: depName,
|
||||
dependency: currentScope.tryResolve<Service>(
|
||||
named: prevDepName,
|
||||
),
|
||||
),
|
||||
)
|
||||
.withName(depName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
import 'service.dart';
|
||||
import 'service_impl.dart';
|
||||
|
||||
class ChainSingletonModule extends Module {
|
||||
// количество независимых цепочек
|
||||
final int chainCount;
|
||||
|
||||
// глубина вложенности
|
||||
final int nestingDepth;
|
||||
|
||||
ChainSingletonModule({
|
||||
required this.chainCount,
|
||||
required this.nestingDepth,
|
||||
});
|
||||
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
for (var chainIndex = 0; chainIndex < chainCount; chainIndex++) {
|
||||
for (var levelIndex = 0; levelIndex < nestingDepth; levelIndex++) {
|
||||
final chain = chainIndex + 1;
|
||||
final level = levelIndex + 1;
|
||||
|
||||
final prevDepName = '${chain.toString()}_${(level - 1).toString()}';
|
||||
final depName = '${chain.toString()}_${level.toString()}';
|
||||
|
||||
bind<Service>()
|
||||
.toProvide(
|
||||
() => ServiceImpl(
|
||||
value: depName,
|
||||
dependency: currentScope.tryResolve<Service>(
|
||||
named: prevDepName,
|
||||
),
|
||||
),
|
||||
)
|
||||
.withName(depName)
|
||||
.singleton();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
benchmark_cherrypick/lib/scenarios/child_impl.dart
Normal file
2
benchmark_cherrypick/lib/scenarios/child_impl.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
import 'shared.dart';
|
||||
class ChildImpl extends Shared {}
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
import 'child_impl.dart';
|
||||
import 'shared.dart';
|
||||
|
||||
class ChildOverrideModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<Shared>().toProvide(() => ChildImpl()).singleton();
|
||||
}
|
||||
}
|
||||
1
benchmark_cherrypick/lib/scenarios/foo_service.dart
Normal file
1
benchmark_cherrypick/lib/scenarios/foo_service.dart
Normal file
@@ -0,0 +1 @@
|
||||
class FooService {}
|
||||
12
benchmark_cherrypick/lib/scenarios/named_module.dart
Normal file
12
benchmark_cherrypick/lib/scenarios/named_module.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
class Impl1 {}
|
||||
class Impl2 {}
|
||||
|
||||
class NamedModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<Object>().toProvide(() => Impl1()).withName('impl1');
|
||||
bind<Object>().toProvide(() => Impl2()).withName('impl2');
|
||||
}
|
||||
}
|
||||
2
benchmark_cherrypick/lib/scenarios/parent_impl.dart
Normal file
2
benchmark_cherrypick/lib/scenarios/parent_impl.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
import 'shared.dart';
|
||||
class ParentImpl extends Shared {}
|
||||
10
benchmark_cherrypick/lib/scenarios/parent_module.dart
Normal file
10
benchmark_cherrypick/lib/scenarios/parent_module.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
import 'parent_impl.dart';
|
||||
import 'shared.dart';
|
||||
|
||||
class ParentModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<Shared>().toProvide(() => ParentImpl()).singleton();
|
||||
}
|
||||
}
|
||||
5
benchmark_cherrypick/lib/scenarios/service.dart
Normal file
5
benchmark_cherrypick/lib/scenarios/service.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
abstract class Service {
|
||||
final dynamic value;
|
||||
final Service? dependency;
|
||||
Service({required this.value, this.dependency});
|
||||
}
|
||||
5
benchmark_cherrypick/lib/scenarios/service_impl.dart
Normal file
5
benchmark_cherrypick/lib/scenarios/service_impl.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
import 'service.dart';
|
||||
|
||||
class ServiceImpl extends Service {
|
||||
ServiceImpl({required super.value, super.dependency});
|
||||
}
|
||||
1
benchmark_cherrypick/lib/scenarios/shared.dart
Normal file
1
benchmark_cherrypick/lib/scenarios/shared.dart
Normal file
@@ -0,0 +1 @@
|
||||
class Shared {}
|
||||
Reference in New Issue
Block a user