Tutorials
Build a catalog data layer
Assemble a domain Repository, remote and cache DataSources, mapping, observation, and shutdown.
Build a catalog data layer
Declare the domain contract
Put CatalogRepository, CatalogData, and domain entities in the Domain layer. Expose only the current data, its stream, and business operations such as synchronize().
Declare technical source contracts
Create CatalogRemoteDataSource for network records and CatalogCacheDataSource for local records. Keep DTOs beside the technical boundary that owns them.
Implement the concrete Repository
Resolve both source contracts in the constructor. Read the cache for immediate data, fetch the remote representation, map it into domain entities, write the cache, and call setData only with domain data.
Choose a concurrency policy
If two refresh calls may overlap, decide explicitly whether to serialize, cancel older work, compare revisions, or accept last-completion-wins. The base Repository does not guess this policy.
Compose and close the graph
Build the sources, container, and Repository in the Composition Root. Cancel consumers first, close the Repository next, then close the source clients that the outer scope owns.