mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 21:57:58 +00:00
Add complex DI benchmarks, main runner, and English README with summarized results for cherrypick core
This commit is contained in:
43
benchmark_cherrypick/lib/scope_override_benchmark.dart
Normal file
43
benchmark_cherrypick/lib/scope_override_benchmark.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:benchmark_harness/benchmark_harness.dart';
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
class Shared {}
|
||||
class ParentImpl extends Shared {}
|
||||
class ChildImpl extends Shared {}
|
||||
|
||||
class ParentModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<Shared>().toProvide(() => ParentImpl()).singleton();
|
||||
}
|
||||
}
|
||||
|
||||
class ChildOverrideModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<Shared>().toProvide(() => ChildImpl()).singleton();
|
||||
}
|
||||
}
|
||||
|
||||
class ScopeOverrideBenchmark extends BenchmarkBase {
|
||||
ScopeOverrideBenchmark() : super('ScopeOverride (child overrides parent)');
|
||||
late Scope parent;
|
||||
late Scope child;
|
||||
@override
|
||||
void setup() {
|
||||
parent = CherryPick.openRootScope();
|
||||
parent.installModules([ParentModule()]);
|
||||
child = parent.openSubScope('child');
|
||||
child.installModules([ChildOverrideModule()]);
|
||||
}
|
||||
@override
|
||||
void teardown() {
|
||||
CherryPick.closeRootScope();
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
// Должен возвращать ChildImpl, а не ParentImpl
|
||||
final resolved = child.resolve<Shared>();
|
||||
assert(resolved is ChildImpl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user