Inject read models from non-Chronicle providers into the command pipeline - #2423
Closed
woksin wants to merge 7 commits into
Closed
Inject read models from non-Chronicle providers into the command pipeline#2423woksin wants to merge 7 commits into
woksin wants to merge 7 commits into
Conversation
Introduce ICanResolveReadModelForCommand so any backing provider can contribute a command-scoped, by-key read model resolver, and lift the read model injection support out of Chronicle into Arc.Core: - ICanResolveReadModelForCommand abstraction and AddReadModelsForCommand registration that registers a scoped by-key factory per read model type and keeps an additive union of registered types across providers. - A provider-neutral resolved key on the command context (CommandContextKeys plus a GetResolvedKey accessor). - RegisteredReadModelTypes, the unresolvable-dependency classifier, and the ReadModelDoesNotExistForCommand / UnableToResolveReadModelFromCommandContext validation failures, now keyed off the neutral resolved key.
Chronicle now contributes its read model types through the Arc.Core ICanResolveReadModelForCommand seam instead of owning the registration and classification itself: - ChronicleReadModelForCommandResolver wraps the existing by-key resolution through IReadModels; AddReadModels registers it via AddReadModelsForCommand. No change to how Chronicle resolves or releases read models. - EventSourceValuesProvider also writes the provider-neutral resolved key alongside the event source id, so non-Chronicle providers can resolve by the same key. Existing event-source-id behavior is unchanged. - The moved RegisteredReadModelTypes, classifier, and validation failures are consumed from Arc.Core.
Add EntityFrameworkReadModelForCommandResolver, which resolves a [ReadModel] entity from its owning ReadOnlyDbContext by the command's resolved key. It discovers the read model entity -> DbContext map from the registered read model contexts, converts the resolved key string to the entity's primary key type (Guid, int, long, string, or a ConceptAs of those), and loads the instance with DbContext.Find, returning null when it does not exist. The resolver is registered automatically when read model DbContexts are added.
- Arc.Core: registration behavior (scoped factory + additive type union across two providers), by-key resolution present/absent, and the unresolvable-dependency classifier keyed off the neutral resolved key. - EF Core (SQLite in-memory): read model type discovery, by-key resolve present/absent, missing-key validation failure, and injection of an EF [ReadModel] through the command DI resolution seam.
Explain that EF Core [ReadModel] entities are injectable into a command validator, Provide(), or Handle() by key, with the same nullable rules, and that Chronicle-backed and EF-backed read models coexist.
- Await DbContext.FindAsync instead of the blocking Find (CA1849/MA0042) - Add missing param docs to the test resolver context (RCS1141)
Contributor
Author
|
Consolidated into #2425 so the open work ships as one release. Every commit from this branch is contained in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the design proposed in #2303 so an EF Core-backed
[ReadModel]can be injected by key into a command, not just Chronicle-backed ones.Added
Handle(),Provide(), andCommandValidator<>, through a provider-agnostic resolver abstraction; Chronicle and EF-backed read models coexist without either claiming the other's types, and nullable/non-nullable resolution behaves exactly as before (Support injecting read models from non-Chronicle providers into the command pipeline #2303)Generated by Claude Code