mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
fixed resolve method
This commit is contained in:
@@ -4,15 +4,20 @@ import 'package:dart_di/experimental/scope.dart';
|
||||
import 'package:dart_di/experimental/module.dart';
|
||||
|
||||
class AppModule extends Module {
|
||||
bool isMock;
|
||||
|
||||
AppModule({required this.isMock});
|
||||
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<ApiClient>().withName("apiClientMock").toInstance(ApiClientMock());
|
||||
bind<ApiClient>().withName("apiClientImpl").toInstance(ApiClientImpl());
|
||||
}
|
||||
}
|
||||
|
||||
class FeatureModule extends Module {
|
||||
bool isMock;
|
||||
|
||||
FeatureModule({required this.isMock});
|
||||
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<DataRepository>()
|
||||
.withName("networkRepo")
|
||||
.toProvide(
|
||||
@@ -33,10 +38,14 @@ class AppModule extends Module {
|
||||
|
||||
void main() async {
|
||||
final scope = openRootScope().installModules([
|
||||
AppModule(isMock: false),
|
||||
AppModule(),
|
||||
]);
|
||||
|
||||
final dataBloc = scope.resolve<DataBloc>();
|
||||
final subScope = scope
|
||||
.openSubScope("featureScope")
|
||||
.installModules([FeatureModule(isMock: true)]);
|
||||
|
||||
final dataBloc = subScope.resolve<DataBloc>();
|
||||
dataBloc.data.listen((d) => print('Received data: $d'),
|
||||
onError: (e) => print('Error: $e'), onDone: () => print('DONE'));
|
||||
|
||||
|
||||
@@ -83,6 +83,6 @@ class Scope {
|
||||
}
|
||||
|
||||
// 2 Поиск зависимостей в родительском скоупе
|
||||
return _parentScope != null ? _parentScope!.tryResolve() : null;
|
||||
return _parentScope != null ? _parentScope!.tryResolve(named: named) : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user