Table of Contents

Class EntityPatchCommand<TKey, TReadModel>

Namespace
Arbiter.CommandQuery.Commands
Assembly
Arbiter.CommandQuery.dll

Represents a command to apply a JSON patch to an entity identified by a specific key. The result of the command will be of type TReadModel.

public record EntityPatchCommand<TKey, TReadModel> : EntityIdentifierCommand<TKey, TReadModel>, IRequest<TReadModel>, IRequest, IEquatable<PrincipalCommandBase<TReadModel>>, IEquatable<EntityIdentifierCommand<TKey, TReadModel>>, ICacheExpire, IEquatable<EntityPatchCommand<TKey, TReadModel>>

Type Parameters

TKey

The type of the key used to identify the entity.

TReadModel

The type of the read model returned as the result of the command.

Inheritance
EntityIdentifierCommand<TKey, TReadModel>
EntityPatchCommand<TKey, TReadModel>
Implements
IRequest<TReadModel>
IEquatable<EntityPatchCommand<TKey, TReadModel>>
Inherited Members

Examples

The following example demonstrates how to use the EntityPatchCommand<TKey, TReadModel>:

var patchDocument = new JsonPatchDocument();
patchDocument.Replace("/Name", "Updated Name");

var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var command = new EntityPatchCommand<int, ProductReadModel>(principal, 123, patchDocument);

// Pass the command to a handler or mediator
var result = await mediator.Send(command);
Console.WriteLine($"Updated product name: {result?.Name}");

Remarks

This command is typically used in a CQRS (Command Query Responsibility Segregation) pattern to apply partial updates to an entity using a JSON patch document.

Constructors

EntityPatchCommand(ClaimsPrincipal?, TKey, JsonPatchDocument)

Initializes a new instance of the EntityPatchCommand<TKey, TReadModel> class.

public EntityPatchCommand(ClaimsPrincipal? principal, TKey id, JsonPatchDocument patch)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the command.

id TKey

The identifier of the entity to which the JSON patch will be applied.

patch JsonPatchDocument

The JSON patch document containing the updates to apply.

Exceptions

ArgumentNullException

Thrown when id or patch is null.

Properties

Patch

Gets the JSON patch document to apply to the entity with the specified identifier.

[JsonPropertyName("patch")]
public JsonPatchDocument Patch { get; }

Property Value

JsonPatchDocument

The JSON patch document containing the updates.