Skip to content

Commit 891fac6

Browse files
committed
improve docs
1 parent 9d531a1 commit 891fac6

File tree

9 files changed

+329
-78
lines changed

9 files changed

+329
-78
lines changed

src/Arbiter.CommandQuery/Commands/EntityCreateCommand.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,58 @@
77
namespace Arbiter.CommandQuery.Commands;
88

99
/// <summary>
10-
/// A command to create a new entity based on the specified <typeparamref name="TCreateModel"/>.
11-
/// <typeparamref name="TReadModel"/> will be the result of the command.
10+
/// Represents a command to create a new entity using the specified <typeparamref name="TCreateModel"/>.
11+
/// The result of the command will be of type <typeparamref name="TReadModel"/>.
1212
/// </summary>
13-
/// <typeparam name="TCreateModel">The type of the create model.</typeparam>
14-
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
13+
/// <typeparam name="TCreateModel">The type of the create model used to provide data for the new entity.</typeparam>
14+
/// <typeparam name="TReadModel">The type of the read model returned as the result of the command.</typeparam>
15+
/// <remarks>
16+
/// This command is typically used in a CQRS (Command Query Responsibility Segregation) pattern to create a new entity
17+
/// and return a read model representing the created entity or a related result.
18+
/// </remarks>
19+
/// <example>
20+
/// The following example demonstrates how to use the <see cref="EntityCreateCommand{TCreateModel, TReadModel}"/>:
21+
/// <code>
22+
/// var createModel = new ProductCreateModel
23+
/// {
24+
/// Name = "New Product",
25+
/// Description = "A description of the new product",
26+
/// Price = 19.99m
27+
/// };
28+
///
29+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
30+
///
31+
/// var command = new EntityCreateCommand&lt;ProductCreateModel, ProductReadModel&gt;(principal, createModel);
32+
///
33+
/// // Pass the command to the mediator for execution
34+
/// var result = await mediator.Send(command);
35+
/// Console.WriteLine($"Created product: {result?.Name}");
36+
/// </code>
37+
/// </example>
1538
public record EntityCreateCommand<TCreateModel, TReadModel>
1639
: EntityModelCommand<TCreateModel, TReadModel>, ICacheExpire
1740
{
1841
/// <summary>
1942
/// Initializes a new instance of the <see cref="EntityCreateCommand{TCreateModel, TReadModel}"/> class.
2043
/// </summary>
21-
/// <param name="principal">The <see cref="ClaimsPrincipal"/> this command is run for</param>
22-
/// <param name="model">The create model for this command.</param>
44+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user for whom this command is executed.</param>
45+
/// <param name="model">The create model containing the data for the new entity.</param>
46+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is <c>null</c>.</exception>
2347
public EntityCreateCommand(ClaimsPrincipal? principal, [NotNull] TCreateModel model)
2448
: base(principal, model)
2549
{
2650
}
2751

28-
/// <inheritdoc />
52+
/// <summary>
53+
/// Gets the cache tag associated with the <typeparamref name="TReadModel"/>.
54+
/// </summary>
55+
/// <returns>The cache tag for the <typeparamref name="TReadModel"/>, or <c>null</c> if no tag is available.</returns>
56+
/// <example>
57+
/// The following example demonstrates how to retrieve the cache tag:
58+
/// <code>
59+
/// var cacheTag = command.GetCacheTag();
60+
/// </code>
61+
/// </example>
2962
string? ICacheExpire.GetCacheTag()
3063
=> CacheTagger.GetTag<TReadModel>();
3164
}

src/Arbiter.CommandQuery/Commands/EntityDeleteCommand.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,48 @@
77
namespace Arbiter.CommandQuery.Commands;
88

99
/// <summary>
10-
/// A command to delete based on the specified identifier.
11-
/// <typeparamref name="TReadModel"/> will be the result of the command.
10+
/// A command to delete an entity based on the specified identifier.
11+
/// <typeparamref name="TReadModel"/> represents the result of the command.
1212
/// </summary>
13-
/// <typeparam name="TKey">The type of the key.</typeparam>
14-
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
13+
/// <typeparam name="TKey">The type of the key used to identify the entity.</typeparam>
14+
/// <typeparam name="TReadModel">The type of the read model returned after the command execution.</typeparam>
15+
/// <remarks>
16+
/// This command is typically used in a CQRS (Command Query Responsibility Segregation) pattern to delete an entity
17+
/// and optionally return a read model representing the deleted entity or a related result.
18+
/// </remarks>
19+
/// <example>
20+
/// The following example demonstrates how to use the <see cref="EntityDeleteCommand{TKey, TReadModel}"/>:
21+
/// <code>
22+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
23+
/// var command = new EntityDeleteCommand&lt;int, ProductReadModel&gt;(principal, 123);
24+
///
25+
/// // Pass the command to a handler or mediator
26+
/// var result = await mediator.Send(command);
27+
/// </code>
28+
/// </example>
1529
public record EntityDeleteCommand<TKey, TReadModel>
1630
: EntityIdentifierCommand<TKey, TReadModel>, ICacheExpire
1731
{
1832
/// <summary>
1933
/// Initializes a new instance of the <see cref="EntityDeleteCommand{TKey, TReadModel}"/> class.
2034
/// </summary>
21-
/// <param name="principal">the <see cref="ClaimsPrincipal" /> this command is run for</param>
22-
/// <param name="id">The identifier for this command.</param>
35+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the command.</param>
36+
/// <param name="id">The identifier of the entity to be deleted.</param>
37+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="id"/> is null.</exception>
2338
public EntityDeleteCommand(ClaimsPrincipal? principal, [NotNull] TKey id) : base(principal, id)
2439
{
2540
}
2641

27-
/// <inheritdoc />
42+
/// <summary>
43+
/// Gets the cache tag for the entity associated with this command.
44+
/// </summary>
45+
/// <returns>The cache tag for the entity, or <c>null</c> if no tag is available.</returns>
46+
/// <example>
47+
/// The following example demonstrates how to retrieve the cache tag:
48+
/// <code>
49+
/// var cacheTag = command.GetCacheTag();
50+
/// </code>
51+
/// </example>
2852
string? ICacheExpire.GetCacheTag()
2953
=> CacheTagger.GetTag<TReadModel>();
3054
}

src/Arbiter.CommandQuery/Commands/EntityIdentifierCommand.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@
55
namespace Arbiter.CommandQuery.Commands;
66

77
/// <summary>
8-
/// A base command for commands that use an identifier
8+
/// Represents a base command for operations that require an identifier.
99
/// </summary>
10-
/// <typeparam name="TKey">The type of the key.</typeparam>
11-
/// <typeparam name="TResponse">The type of the response.</typeparam>
10+
/// <typeparam name="TKey">The type of the key used to identify the entity.</typeparam>
11+
/// <typeparam name="TResponse">The type of the response returned by the command.</typeparam>
12+
/// <remarks>
13+
/// This class is typically used in a CQRS (Command Query Responsibility Segregation) pattern to define commands
14+
/// that operate on a specific entity identified by a key.
15+
/// </remarks>
16+
/// <example>
17+
/// The following example demonstrates how to use the <see cref="EntityIdentifierCommand{TKey, TResponse}"/>:
18+
/// <code>
19+
/// public record GetEntityByIdCommand : EntityIdentifierCommand&lt;int, ProductReadModel&gt;
20+
/// {
21+
/// public GetEntityByIdCommand(ClaimsPrincipal principal, int id)
22+
/// : base(principal, id)
23+
/// {
24+
/// }
25+
/// }
26+
///
27+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
28+
/// var command = new GetEntityByIdCommand(principal, 123);
29+
///
30+
/// // Pass the command to a handler or mediator
31+
/// var result = await mediator.Send(command);
32+
/// Console.WriteLine($"Entity Name: {result?.Name}");
33+
/// </code>
34+
/// </example>
1235
public abstract record EntityIdentifierCommand<TKey, TResponse>
1336
: PrincipalCommandBase<TResponse>
1437
{
1538
/// <summary>
1639
/// Initializes a new instance of the <see cref="EntityIdentifierCommand{TKey, TResponse}"/> class.
1740
/// </summary>
18-
/// <param name="principal">the <see cref="ClaimsPrincipal"/> this command is run for</param>
19-
/// <param name="id">The identifier for this command.</param>
20-
/// <exception cref="ArgumentNullException">When <paramref name="id"/> is null</exception>
41+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the command.</param>
42+
/// <param name="id">The identifier of the entity for this command.</param>
43+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="id"/> is <see langword="null"/>.</exception>
2144
protected EntityIdentifierCommand(ClaimsPrincipal? principal, [NotNull] TKey id)
2245
: base(principal)
2346
{
@@ -30,7 +53,7 @@ protected EntityIdentifierCommand(ClaimsPrincipal? principal, [NotNull] TKey id)
3053
/// Gets the identifier for this command.
3154
/// </summary>
3255
/// <value>
33-
/// The identifier for this command.
56+
/// The identifier of the entity for this command.
3457
/// </value>
3558
[NotNull]
3659
[JsonPropertyName("id")]

src/Arbiter.CommandQuery/Commands/EntityIdentifiersCommand.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@
55
namespace Arbiter.CommandQuery.Commands;
66

77
/// <summary>
8-
/// A base command for commands that use a list of identifiers
8+
/// Represents a base command for operations that require a list of identifiers.
99
/// </summary>
10-
/// <typeparam name="TKey">The type of the key.</typeparam>
11-
/// <typeparam name="TResponse">The type of the response.</typeparam>
10+
/// <typeparam name="TKey">The type of the key used to identify the entities.</typeparam>
11+
/// <typeparam name="TResponse">The type of the response returned by the command.</typeparam>
12+
/// <remarks>
13+
/// This class is typically used in a CQRS (Command Query Responsibility Segregation) pattern to define commands
14+
/// that operate on multiple entities identified by a collection of keys.
15+
/// </remarks>
16+
/// <example>
17+
/// The following example demonstrates how to use the <see cref="EntityIdentifiersCommand{TKey, TResponse}"/>:
18+
/// <code>
19+
/// public record DeleteEntitiesCommand : EntityIdentifiersCommand&lt;int, ProductReadModel&gt;
20+
/// {
21+
/// public DeleteEntitiesCommand(ClaimsPrincipal principal, IReadOnlyCollection&lt;int&gt; ids)
22+
/// : base(principal, ids)
23+
/// {
24+
/// }
25+
/// }
26+
///
27+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
28+
/// var command = new DeleteEntitiesCommand(principal, new List&lt;int&gt; { 1, 2, 3 });
29+
///
30+
/// // Pass the command to a handler or mediator
31+
/// var result = await mediator.Send(command);
32+
/// Console.WriteLine($"Entities deleted: {result}");
33+
/// </code>
34+
/// </example>
1235
public abstract record EntityIdentifiersCommand<TKey, TResponse>
1336
: PrincipalCommandBase<TResponse>
1437
{
1538
/// <summary>
1639
/// Initializes a new instance of the <see cref="EntityIdentifiersCommand{TKey, TResponse}"/> class.
1740
/// </summary>
18-
/// <param name="principal">the <see cref="ClaimsPrincipal"/> this command is run for</param>
19-
/// <param name="ids">The list of identifiers for this command.</param>
20-
/// <exception cref="ArgumentNullException">When <paramref name="ids"/> is null</exception>
41+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the command.</param>
42+
/// <param name="ids">The collection of identifiers for this command.</param>
43+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ids"/> is <c>null</c>.</exception>
2144
protected EntityIdentifiersCommand(ClaimsPrincipal? principal, [NotNull] IReadOnlyCollection<TKey> ids)
2245
: base(principal)
2346
{
@@ -27,10 +50,10 @@ protected EntityIdentifiersCommand(ClaimsPrincipal? principal, [NotNull] IReadOn
2750
}
2851

2952
/// <summary>
30-
/// Gets the list of identifiers for this command.
53+
/// Gets the collection of identifiers for this command.
3154
/// </summary>
3255
/// <value>
33-
/// The list of identifiers for this command.
56+
/// The collection of identifiers for this command.
3457
/// </value>
3558
[JsonPropertyName("ids")]
3659
public IReadOnlyCollection<TKey> Ids { get; }

src/Arbiter.CommandQuery/Commands/EntityModelCommand.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,49 @@
55
namespace Arbiter.CommandQuery.Commands;
66

77
/// <summary>
8-
/// Base class for using a view model for the command
8+
/// Represents a base command that uses a view model to perform an operation.
99
/// </summary>
10-
/// <typeparam name="TEntityModel">The type of the model for this command.</typeparam>
11-
/// <typeparam name="TReadModel">The type of the read model to return.</typeparam>
10+
/// <typeparam name="TEntityModel">The type of the model used as input for the command.</typeparam>
11+
/// <typeparam name="TReadModel">The type of the read model returned as the result of the command.</typeparam>
12+
/// <remarks>
13+
/// This class is typically used in a CQRS (Command Query Responsibility Segregation) pattern to define commands
14+
/// that operate on an entity using a model and return a read model as the result.
15+
/// </remarks>
16+
/// <example>
17+
/// The following example demonstrates how to use the <see cref="EntityModelCommand{TEntityModel, TReadModel}"/>:
18+
/// <code>
19+
/// public record CreateProductCommand : EntityModelCommand&lt;ProductCreateModel, ProductReadModel&gt;
20+
/// {
21+
/// public CreateProductCommand(ClaimsPrincipal principal, ProductCreateModel model)
22+
/// : base(principal, model)
23+
/// {
24+
/// }
25+
/// }
26+
///
27+
/// var createModel = new ProductCreateModel
28+
/// {
29+
/// Name = "New Product",
30+
/// Description = "A description of the new product",
31+
/// Price = 19.99m
32+
/// };
33+
///
34+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
35+
/// var command = new CreateProductCommand(principal, createModel);
36+
///
37+
/// // Pass the command to a handler or mediator
38+
/// var result = await mediator.Send(command);
39+
/// Console.WriteLine($"Created product: {result?.Name}");
40+
/// </code>
41+
/// </example>
1242
public abstract record EntityModelCommand<TEntityModel, TReadModel>
1343
: PrincipalCommandBase<TReadModel>
1444
{
1545
/// <summary>
1646
/// Initializes a new instance of the <see cref="EntityModelCommand{TEntityModel, TReadModel}"/> class.
1747
/// </summary>
18-
/// <param name="principal">the <see cref="ClaimsPrincipal"/> this command is run for</param>
19-
/// <param name="model">The model to use for this command.</param>
48+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the command.</param>
49+
/// <param name="model">The model containing the data for the operation.</param>
50+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is <c>null</c>.</exception>
2051
protected EntityModelCommand(ClaimsPrincipal? principal, [NotNull] TEntityModel model)
2152
: base(principal)
2253
{
@@ -26,10 +57,10 @@ protected EntityModelCommand(ClaimsPrincipal? principal, [NotNull] TEntityModel
2657
}
2758

2859
/// <summary>
29-
/// Gets the view model to use for this command.
60+
/// Gets the view model used for this command.
3061
/// </summary>
3162
/// <value>
32-
/// The view model to use for this command.
63+
/// The view model containing the data for the operation.
3364
/// </value>
3465
[NotNull]
3566
[JsonPropertyName("model")]

src/Arbiter.CommandQuery/Commands/EntityPatchCommand.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,39 @@
1010
namespace Arbiter.CommandQuery.Commands;
1111

1212
/// <summary>
13-
/// A command to apply a JSON patch to the entity with the specified identifier.
14-
/// <typeparamref name="TReadModel"/> will be the result of the command.
13+
/// Represents a command to apply a JSON patch to an entity identified by a specific key.
14+
/// The result of the command will be of type <typeparamref name="TReadModel"/>.
1515
/// </summary>
16-
/// <typeparam name="TKey">The type of the key.</typeparam>
17-
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
16+
/// <typeparam name="TKey">The type of the key used to identify the entity.</typeparam>
17+
/// <typeparam name="TReadModel">The type of the read model returned as the result of the command.</typeparam>
18+
/// <remarks>
19+
/// This command is typically used in a CQRS (Command Query Responsibility Segregation) pattern to apply partial updates
20+
/// to an entity using a JSON patch document.
21+
/// </remarks>
22+
/// <example>
23+
/// The following example demonstrates how to use the <see cref="EntityPatchCommand{TKey, TReadModel}"/>:
24+
/// <code>
25+
/// var patchDocument = new JsonPatchDocument();
26+
/// patchDocument.Replace("/Name", "Updated Name");
27+
///
28+
/// var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
29+
/// var command = new EntityPatchCommand&lt;int, ProductReadModel&gt;(principal, 123, patchDocument);
30+
///
31+
/// // Pass the command to a handler or mediator
32+
/// var result = await mediator.Send(command);
33+
/// Console.WriteLine($"Updated product name: {result?.Name}");
34+
/// </code>
35+
/// </example>
1836
public record EntityPatchCommand<TKey, TReadModel>
1937
: EntityIdentifierCommand<TKey, TReadModel>, ICacheExpire
2038
{
2139
/// <summary>
2240
/// Initializes a new instance of the <see cref="EntityPatchCommand{TKey, TReadModel}"/> class.
2341
/// </summary>
24-
/// <param name="principal">the <see cref="ClaimsPrincipal" /> this command is run for</param>
25-
/// <param name="id">The identifier to apply JSON patch to.</param>
26-
/// <param name="patch">The JSON patch to apply.</param>
27-
/// <exception cref="ArgumentNullException">When <paramref name="id"/> or <paramref name="patch"/> is null</exception>
42+
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user executing the command.</param>
43+
/// <param name="id">The identifier of the entity to which the JSON patch will be applied.</param>
44+
/// <param name="patch">The JSON patch document containing the updates to apply.</param>
45+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="id"/> or <paramref name="patch"/> is <c>null</c>.</exception>
2846
public EntityPatchCommand(ClaimsPrincipal? principal, [NotNull] TKey id, [NotNull] JsonPatchDocument patch)
2947
: base(principal, id)
3048
{
@@ -34,15 +52,24 @@ public EntityPatchCommand(ClaimsPrincipal? principal, [NotNull] TKey id, [NotNul
3452
}
3553

3654
/// <summary>
37-
/// Gets the JSON patch to apply to the entity with the specified identifier.
55+
/// Gets the JSON patch document to apply to the entity with the specified identifier.
3856
/// </summary>
3957
/// <value>
40-
/// The patch.
58+
/// The JSON patch document containing the updates.
4159
/// </value>
4260
[JsonPropertyName("patch")]
4361
public JsonPatchDocument Patch { get; }
4462

45-
/// <inheritdoc />
63+
/// <summary>
64+
/// Gets the cache tag associated with the <typeparamref name="TReadModel"/>.
65+
/// </summary>
66+
/// <returns>The cache tag for the <typeparamref name="TReadModel"/>, or <c>null</c> if no tag is available.</returns>
67+
/// <example>
68+
/// The following example demonstrates how to retrieve the cache tag:
69+
/// <code>
70+
/// var cacheTag = command.GetCacheTag();
71+
/// </code>
72+
/// </example>
4673
string? ICacheExpire.GetCacheTag()
4774
=> CacheTagger.GetTag<TReadModel>();
4875
}

0 commit comments

Comments
 (0)