feat: Add async dependency resolution and enhance example

- Implemented async provider methods `toProvideAsync` and `toProvideAsyncWithParams` in `Binding` class, allowing asynchronous initialization with dynamic parameters.
- Added typedefs `AsyncProvider<T>` and `AsyncProviderWithParams<T>` for better type clarity with async operations.
- Introduced async resolution methods `resolveAsync` and `tryResolveAsync` in `Scope` for resolving asynchronous dependencies.
- Updated example in `main.dart` to demonstrate async dependency resolution capabilities.
  - Modified `FeatureModule` to utilize async providers for `DataRepository` and `DataBloc`.
  - Replaced synchronous resolution with `resolveAsync` where applicable.
  - Handled potential errors in dependency resolution with try-catch.
- Removed unnecessary whitespace for cleaner code formatting.
This commit is contained in:
Sergey Penkovsky
2025-05-06 15:54:35 +03:00
parent de995228a5
commit 7a5880e436

View File

@@ -37,7 +37,8 @@ class FeatureModule extends Module {
}
}
void main() async {
Future<void> main() async {
try {
final scope = openRootScope().installModules([
AppModule(),
]);
@@ -52,13 +53,16 @@ void main() async {
onError: (e) => print('Error: $e'), onDone: () => print('DONE'));
await dataBloc.fetchData();
} catch (e) {
print('Error resolving dependency: $e');
}
}
class DataBloc {
final DataRepository _dataRepository;
Stream<String> get data => _dataController.stream;
final StreamController<String> _dataController = StreamController.broadcast();
Stream<String> get data => _dataController.stream;
DataBloc(this._dataRepository);