Class MongoDBReadModelForCommandResolver

Namespace
Cratis.Arc.MongoDB
Assembly
Cratis.Arc.MongoDB.dll

Represents an ICanResolveReadModelForCommand that resolves read models held in MongoDB through the collection for the read model, keyed by the command's resolved key.

public class MongoDBReadModelForCommandResolver : ICanResolveReadModelForCommand
Inheritance
MongoDBReadModelForCommandResolver
Implements
Inherited Members
Extension Methods

Remarks

MongoDB holds a document per read model instance, keyed by _id, so the command's resolved key is the document id. Nothing in an application declares that a read model is stored in MongoDB, which is why this claims its types as a Fallback: a provider that does own a read model — Chronicle for one it projects, Entity Framework Core for one carried by a read model context — keeps it.

Constructors

MongoDBReadModelForCommandResolver(IEnumerable<Type>)

Represents an ICanResolveReadModelForCommand that resolves read models held in MongoDB through the collection for the read model, keyed by the command's resolved key.

public MongoDBReadModelForCommandResolver(IEnumerable<Type> readModelTypes)

Parameters

readModelTypes IEnumerable<Type>

The read model types this resolver can resolve by key.

Remarks

MongoDB holds a document per read model instance, keyed by _id, so the command's resolved key is the document id. Nothing in an application declares that a read model is stored in MongoDB, which is why this claims its types as a Fallback: a provider that does own a read model — Chronicle for one it projects, Entity Framework Core for one carried by a read model context — keeps it.

Properties

Ownership

Gets how strongly this provider claims the read model types it reports.

public ReadModelForCommandOwnership Ownership { get; }

Property Value

ReadModelForCommandOwnership

Remarks

Claiming as a fallback means a read model another provider owns is resolved by that provider instead — and therefore materialized across that provider's serialization boundary rather than the driver's. MongoDB serialization customization reaches a command-side read model only where this resolver is the one that claimed it, which in an application whose read models are Chronicle- or Entity Framework Core-owned is nowhere.

ReadModelTypes

Gets the read model types this provider can resolve by key for a command.

public IEnumerable<Type> ReadModelTypes { get; }

Property Value

IEnumerable<Type>

Methods

DiscoverReadModelTypes(IEnumerable<Type>)

Discovers the read model types MongoDB can resolve by key from the types of the application.

public static IEnumerable<Type> DiscoverReadModelTypes(IEnumerable<Type> types)

Parameters

types IEnumerable<Type>

The types to inspect.

Returns

IEnumerable<Type>

The read model types MongoDB can hold a document per.

Remarks

Every [ReadModel] is a candidate, because the MongoDB integration serves a collection for any read model type without being told about it up front. Claiming them as a fallback is what keeps that breadth from taking a read model away from the provider that owns it.

Resolve(Type, CommandContext)

Resolves the read model of the given type for the current command context, keyed by the command's resolved key.

public Task<object?> Resolve(Type readModelType, CommandContext commandContext)

Parameters

readModelType Type

The type of read model to resolve.

commandContext CommandContext

The CommandContext to resolve from.

Returns

Task<object>

The resolved read model instance, or null when no instance exists for the command's key.

Exceptions

UnableToResolveReadModelFromCommandContext

Thrown when the command carries no usable key to resolve the read model by; it surfaces as a validation failure (HTTP 400).

MissingIdMapping

Thrown when the read model has no member mapped to the document id to resolve by.