Skip to content

Commit bf5b030

Browse files
committed
update documentation
1 parent 1929065 commit bf5b030

File tree

81 files changed

+1329
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1329
-199
lines changed

Arbiter.sln

Lines changed: 0 additions & 62 deletions
This file was deleted.

Arbiter.slnx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Solution>
2+
<Folder Name="/Build/">
3+
<File Path=".github/workflows/dotnet.yml" />
4+
<File Path="README.md" />
5+
<File Path="src/Directory.Build.props" />
6+
</Folder>
7+
<Folder Name="/Tests/">
8+
<Project Path="test/Arbiter.Benchmarks/Arbiter.Benchmarks.csproj" />
9+
<Project Path="test/Arbiter.Tests/Arbiter.Tests.csproj" />
10+
</Folder>
11+
<Project Path="src/Arbiter.CommandQuery.Endpoints/Arbiter.CommandQuery.Endpoints.csproj" />
12+
<Project Path="src/Arbiter.CommandQuery.EntityFramework/Arbiter.CommandQuery.EntityFramework.csproj" />
13+
<Project Path="src/Arbiter.CommandQuery.MongoDB/Arbiter.CommandQuery.MongoDB.csproj" />
14+
<Project Path="src/Arbiter.CommandQuery/Arbiter.CommandQuery.csproj" />
15+
<Project Path="src/Arbiter/Arbiter.csproj" />
16+
</Solution>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Arbiter.CommandQuery\Arbiter.CommandQuery.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
15+
</ItemGroup>
16+
</Project>

src/Arbiter.CommandQuery.EntityFramework/DomainServiceExtensions.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@
1212

1313
namespace Arbiter.CommandQuery.EntityFramework;
1414

15+
/// <summary>
16+
/// Extensions for adding Entity Framework Core support to the command/query pipeline.
17+
/// </summary>
1518
public static class DomainServiceExtensions
1619
{
20+
/// <summary>
21+
/// Registers entity queries with pipeline behaviors in the service collection.
22+
/// </summary>
23+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
24+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
25+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
26+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
27+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
28+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
1729
public static IServiceCollection AddEntityQueries<TContext, TEntity, TKey, TReadModel>(this IServiceCollection services)
1830
where TContext : DbContext
1931
where TEntity : class, IHaveIdentifier<TKey>, new()
@@ -35,6 +47,17 @@ public static IServiceCollection AddEntityQueries<TContext, TEntity, TKey, TRead
3547
}
3648

3749

50+
/// <summary>
51+
/// Registers entity create, update and delete commands with pipeline behaviors in the service collection.
52+
/// </summary>
53+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
54+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
55+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
56+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
57+
/// <typeparam name="TCreateModel">The type of the create model</typeparam>
58+
/// <typeparam name="TUpdateModel">The type of the update model</typeparam>
59+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
60+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
3861
public static IServiceCollection AddEntityCommands<TContext, TEntity, TKey, TReadModel, TCreateModel, TUpdateModel>(this IServiceCollection services)
3962
where TContext : DbContext
4063
where TEntity : class, IHaveIdentifier<TKey>, new()
@@ -58,6 +81,16 @@ public static IServiceCollection AddEntityCommands<TContext, TEntity, TKey, TRea
5881
}
5982

6083

84+
/// <summary>
85+
/// Registers entity create command with pipeline behaviors in the service collection.
86+
/// </summary>
87+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
88+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
89+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
90+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
91+
/// <typeparam name="TCreateModel">The type of the create model</typeparam>
92+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
93+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
6194
public static IServiceCollection AddEntityCreateCommand<TContext, TEntity, TKey, TReadModel, TCreateModel>(this IServiceCollection services)
6295
where TContext : DbContext
6396
where TEntity : class, IHaveIdentifier<TKey>, new()
@@ -73,6 +106,16 @@ public static IServiceCollection AddEntityCreateCommand<TContext, TEntity, TKey,
73106
return services;
74107
}
75108

109+
/// <summary>
110+
/// Registers entity update command with pipeline behaviors in the service collection.
111+
/// </summary>
112+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
113+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
114+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
115+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
116+
/// <typeparam name="TUpdateModel">The type of the update model</typeparam>
117+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
118+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
76119
public static IServiceCollection AddEntityUpdateCommand<TContext, TEntity, TKey, TReadModel, TUpdateModel>(this IServiceCollection services)
77120
where TContext : DbContext
78121
where TEntity : class, IHaveIdentifier<TKey>, new()
@@ -92,6 +135,16 @@ public static IServiceCollection AddEntityUpdateCommand<TContext, TEntity, TKey,
92135
return services;
93136
}
94137

138+
/// <summary>
139+
/// Registers entity update or insert command with pipeline behaviors in the service collection.
140+
/// </summary>
141+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
142+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
143+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
144+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
145+
/// <typeparam name="TUpdateModel">The type of the update model</typeparam>
146+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
147+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
95148
public static IServiceCollection AddEntityUpsertCommand<TContext, TEntity, TKey, TReadModel, TUpdateModel>(this IServiceCollection services)
96149
where TContext : DbContext
97150
where TEntity : class, IHaveIdentifier<TKey>, new()
@@ -107,6 +160,15 @@ public static IServiceCollection AddEntityUpsertCommand<TContext, TEntity, TKey,
107160
return services;
108161
}
109162

163+
/// <summary>
164+
/// Registers entity patch command with pipeline behaviors in the service collection.
165+
/// </summary>
166+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
167+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
168+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
169+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
170+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
171+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
110172
public static IServiceCollection AddEntityPatchCommand<TContext, TEntity, TKey, TReadModel>(this IServiceCollection services)
111173
where TContext : DbContext
112174
where TEntity : class, IHaveIdentifier<TKey>, new()
@@ -121,6 +183,15 @@ public static IServiceCollection AddEntityPatchCommand<TContext, TEntity, TKey,
121183
return services;
122184
}
123185

186+
/// <summary>
187+
/// Registers entity delete command with pipeline behaviors in the service collection.
188+
/// </summary>
189+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
190+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
191+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
192+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
193+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
194+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
124195
public static IServiceCollection AddEntityDeleteCommand<TContext, TEntity, TKey, TReadModel>(this IServiceCollection services)
125196
where TContext : DbContext
126197
where TEntity : class, IHaveIdentifier<TKey>, new()

src/Arbiter.CommandQuery.EntityFramework/Handlers/DataContextHandlerBase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,37 @@
66

77
namespace Arbiter.CommandQuery.EntityFramework.Handlers;
88

9+
/// <summary>
10+
/// A base handler for a request that requires the specified <see cref="DbContext"/>.
11+
/// </summary>
12+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
13+
/// <typeparam name="TRequest">The type of request being handled.</typeparam>
14+
/// <typeparam name="TResponse">The type of response from the handler.</typeparam>
915
public abstract class DataContextHandlerBase<TContext, TRequest, TResponse>
1016
: RequestHandlerBase<TRequest, TResponse>
1117
where TContext : DbContext
1218
where TRequest : IRequest<TResponse>
1319
{
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="DataContextHandlerBase{TContext, TRequest, TResponse}"/> class.
22+
/// </summary>
23+
/// <param name="loggerFactory">The logger factory to create an <see cref="ILogger"/> for this handler.</param>
24+
/// <param name="dataContext">The <see cref="DbContext"/> for this handler.</param>
25+
/// <param name="mapper"> The <see cref="IMapper"/> for this handler.</param>
1426
protected DataContextHandlerBase(ILoggerFactory loggerFactory, TContext dataContext, IMapper mapper)
1527
: base(loggerFactory)
1628
{
1729
DataContext = dataContext ?? throw new ArgumentNullException(nameof(dataContext));
1830
Mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
1931
}
2032

33+
/// <summary>
34+
/// Gets the <see cref="DbContext"/> for this handler.
35+
/// </summary>
2136
protected TContext DataContext { get; }
2237

38+
/// <summary>
39+
/// Gets the <see cref="IMapper"/> for this handler.
40+
/// </summary>
2341
protected IMapper Mapper { get; }
2442
}

src/Arbiter.CommandQuery.EntityFramework/Handlers/EntityCreateCommandHandler.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,28 @@
66

77
namespace Arbiter.CommandQuery.EntityFramework.Handlers;
88

9+
/// <summary>
10+
/// A handler for a request that creates an entity in the specified <see cref="DbContext"/>.
11+
/// </summary>
12+
/// <inheritdoc/>
913
public class EntityCreateCommandHandler<TContext, TEntity, TKey, TCreateModel, TReadModel>
1014
: EntityDataContextHandlerBase<TContext, TEntity, TKey, TReadModel, EntityCreateCommand<TCreateModel, TReadModel>, TReadModel>
1115
where TContext : DbContext
1216
where TEntity : class, IHaveIdentifier<TKey>, new()
1317
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="EntityCreateCommandHandler{TContext, TEntity, TKey, TCreateModel, TReadModel}"/> class.
20+
/// </summary>
21+
/// <inheritdoc/>
1422
public EntityCreateCommandHandler(ILoggerFactory loggerFactory, TContext dataContext, IMapper mapper)
1523
: base(loggerFactory, dataContext, mapper)
1624
{
1725
}
1826

19-
protected override async ValueTask<TReadModel?> Process(EntityCreateCommand<TCreateModel, TReadModel> request, CancellationToken cancellationToken = default)
27+
/// <inheritdoc/>
28+
protected override async ValueTask<TReadModel?> Process(
29+
EntityCreateCommand<TCreateModel, TReadModel> request,
30+
CancellationToken cancellationToken = default)
2031
{
2132
ArgumentNullException.ThrowIfNull(request);
2233

src/Arbiter.CommandQuery.EntityFramework/Handlers/EntityDataContextHandlerBase.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,51 @@
77

88
namespace Arbiter.CommandQuery.EntityFramework.Handlers;
99

10+
/// <summary>
11+
/// A base handler for a request that requires the specified <see cref="DbContext"/>.
12+
/// </summary>
13+
/// <typeparam name="TContext">The type of <see cref="DbContext"/>.</typeparam>
14+
/// <typeparam name="TEntity">The type of entity being operated on by the <see cref="DbContext"/></typeparam>
15+
/// <typeparam name="TKey">The key type for the data context entity</typeparam>
16+
/// <typeparam name="TReadModel">The type of the read model.</typeparam>
17+
/// <typeparam name="TRequest">The type of request being handled.</typeparam>
18+
/// <typeparam name="TResponse">The type of response from the handler.</typeparam>
1019
public abstract class EntityDataContextHandlerBase<TContext, TEntity, TKey, TReadModel, TRequest, TResponse>
1120
: DataContextHandlerBase<TContext, TRequest, TResponse>
1221
where TContext : DbContext
1322
where TEntity : class, IHaveIdentifier<TKey>, new()
1423
where TRequest : IRequest<TResponse>
1524
{
25+
26+
private static readonly string _contextName = typeof(TContext).Name;
27+
private static readonly string _entityName = typeof(TEntity).Name;
28+
private static readonly string _modelName = typeof(TReadModel).Name;
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="EntityDataContextHandlerBase{TContext, TEntity, TKey, TReadModel, TRequest, TResponse}"/> class.
32+
/// </summary>
33+
/// <inheritdoc/>
1634
protected EntityDataContextHandlerBase(ILoggerFactory loggerFactory, TContext dataContext, IMapper mapper)
1735
: base(loggerFactory, dataContext, mapper)
1836
{
1937
}
2038

39+
/// <summary>
40+
/// Reads the entity from the data context.
41+
/// </summary>
42+
/// <param name="key">The entity key to read</param>
43+
/// <param name="cancellationToken">The cancellation token</param>
44+
/// <returns>Awaitable task returning the <typeparamref name="TReadModel"/></returns>
45+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="key"/> is null</exception>
2146
protected virtual async ValueTask<TReadModel?> Read([NotNull] TKey key, CancellationToken cancellationToken = default)
2247
{
23-
if (key == null)
48+
if (key is null)
2449
throw new ArgumentNullException(nameof(key));
2550

2651
var query = DataContext
2752
.Set<TEntity>()
2853
.AsNoTracking()
29-
.TagWith($"EntityDataContextHandlerBase; Context:{typeof(TContext).Name}, Entity:{typeof(TEntity).Name}, Model:{typeof(TReadModel).Name}")
54+
.TagWith($"Read(); Context:{_contextName}, Entity:{_entityName}, Model:{_modelName}")
3055
.TagWithCallSite()
3156
.Where(p => Equals(p.Id, key));
3257

src/Arbiter.CommandQuery.EntityFramework/Handlers/EntityDeleteCommandHandler.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,28 @@
66

77
namespace Arbiter.CommandQuery.EntityFramework.Handlers;
88

9+
/// <summary>
10+
/// A handler for a request that deletes an entity in the specified <see cref="DbContext"/>.
11+
/// </summary>
12+
/// <inheritdoc/>
913
public class EntityDeleteCommandHandler<TContext, TEntity, TKey, TReadModel>
1014
: EntityDataContextHandlerBase<TContext, TEntity, TKey, TReadModel, EntityDeleteCommand<TKey, TReadModel>, TReadModel>
1115
where TContext : DbContext
1216
where TEntity : class, IHaveIdentifier<TKey>, new()
1317
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="EntityDeleteCommandHandler{TContext, TEntity, TKey, TReadModel}"/> class.
20+
/// </summary>
21+
/// <inheritdoc/>
1422
public EntityDeleteCommandHandler(ILoggerFactory loggerFactory, TContext dataContext, IMapper mapper)
1523
: base(loggerFactory, dataContext, mapper)
1624
{
1725
}
1826

19-
protected override async ValueTask<TReadModel?> Process(EntityDeleteCommand<TKey, TReadModel> request, CancellationToken cancellationToken = default)
27+
/// <inheritdoc/>
28+
protected override async ValueTask<TReadModel?> Process(
29+
EntityDeleteCommand<TKey, TReadModel> request,
30+
CancellationToken cancellationToken = default)
2031
{
2132
ArgumentNullException.ThrowIfNull(request);
2233

0 commit comments

Comments
 (0)