diff --git a/example/bin/main_experiment.dart b/example/bin/main_experiment.dart index 4799a1e..fa2b968 100644 --- a/example/bin/main_experiment.dart +++ b/example/bin/main_experiment.dart @@ -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().withName("apiClientMock").toInstance(ApiClientMock()); bind().withName("apiClientImpl").toInstance(ApiClientImpl()); + } +} +class FeatureModule extends Module { + bool isMock; + + FeatureModule({required this.isMock}); + + @override + void builder(Scope currentScope) { bind() .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(); + final subScope = scope + .openSubScope("featureScope") + .installModules([FeatureModule(isMock: true)]); + + final dataBloc = subScope.resolve(); dataBloc.data.listen((d) => print('Received data: $d'), onError: (e) => print('Error: $e'), onDone: () => print('DONE')); diff --git a/lib/experimental/scope.dart b/lib/experimental/scope.dart index fbdd37a..dbf9dbb 100644 --- a/lib/experimental/scope.dart +++ b/lib/experimental/scope.dart @@ -83,6 +83,6 @@ class Scope { } // 2 Поиск зависимостей в родительском скоупе - return _parentScope != null ? _parentScope!.tryResolve() : null; + return _parentScope != null ? _parentScope!.tryResolve(named: named) : null; } }