Learn
DataSource contracts
Define narrow source contracts and resolve exactly one implementation by assignable type.
v0.1.0-dev.1Intermediateark_data_layer
DataSource contracts
Prefer one contract per technical responsibility:
dart
abstract interface class CatalogRemoteDataSource implements DataSource {
Future<CatalogResponseDto> fetchCatalog();
}
abstract interface class CatalogCacheDataSource implements DataSource {
Future<CatalogCacheDto?> readCatalog();
Future<void> writeCatalog(CatalogCacheDto data);
}
DataSourceContainer copies the supplied iterable and resolves by Dart type assignability.
| Matches | Result |
|---|---|
| 0 | DataSourceNotFoundException |
| 1 | the matching object |
| 2 or more | AmbiguousDataSourceException |
Strict ambiguity handling prevents registration order from silently selecting storage behavior. If remote and local sources have different responsibilities, give them different interfaces instead of a runtime string key.