Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 10a63b8

Browse files
authored
Merge pull request #17 from AppCoreNet/dev
Release v0.4.1
2 parents 9f5abf6 + f909f19 commit 10a63b8

File tree

4 files changed

+83
-12
lines changed

4 files changed

+83
-12
lines changed

src/AppCore.CommandModel.Logging/Internal/CommandLoggingExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ internal static class CommandLoggingExtensions
1212
LoggerMessage.Define<object>(
1313
LogLevel.Trace,
1414
CommandLoggingBehaviorLogEventIds.CommandHandling,
15-
"Processing command {command} ...");
15+
"Processing command {@command} ...");
1616

1717
private static readonly Action<ILogger, object, long, object?, Exception?> _commandProcessed =
1818
LoggerMessage.Define<object, long, object?>(
1919
LogLevel.Debug,
2020
CommandLoggingBehaviorLogEventIds.CommandHandled,
21-
"Successfully processed command {command} in {commandProcessingTime} ms. Result is {commandResult}.");
21+
"Successfully processed command {@command} in {commandProcessingTime} ms. Result is {@commandResult}.");
2222

2323
private static readonly Action<ILogger, object, Exception?> _commandFailed =
2424
LoggerMessage.Define<object>(
2525
LogLevel.Error,
2626
CommandLoggingBehaviorLogEventIds.CommandFailed,
27-
"Error processing command {command}.");
27+
"Error processing command {@command}.");
2828

2929
public static void CommandProcessing(this ILogger logger, ICommandContext context)
3030
{

src/AppCore.CommandModel/DependencyInjection/CommandModelBuilderExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class CommandModelBuilderExtensions
2020
/// Registers the <see cref="ICommandContextAccessor"/> with the DI container.
2121
/// </summary>
2222
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
23-
public static ICommandModelBuilder WithCommandContext(this ICommandModelBuilder builder)
23+
public static ICommandModelBuilder AddCommandContext(this ICommandModelBuilder builder)
2424
{
2525
Ensure.Arg.NotNull(builder);
2626

@@ -36,7 +36,7 @@ public static ICommandModelBuilder WithCommandContext(this ICommandModelBuilder
3636
/// <param name="lifetime">The lifetime of the handler.</param>
3737
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
3838
/// <exception cref="ArgumentNullException">Argument <paramref name="handlerType"/> is <c>null</c>.</exception>
39-
public static ICommandModelBuilder WithHandler(
39+
public static ICommandModelBuilder AddHandler(
4040
this ICommandModelBuilder builder,
4141
Type handlerType,
4242
ServiceLifetime lifetime = ServiceLifetime.Transient)
@@ -58,7 +58,7 @@ public static ICommandModelBuilder WithHandler(
5858
/// <param name="defaultLifetime">The default handler lifetime.</param>
5959
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
6060
/// <exception cref="ArgumentNullException">Argument <paramref name="configure"/> is <c>null</c>.</exception>
61-
public static ICommandModelBuilder WithHandlersFrom(
61+
public static ICommandModelBuilder AddHandlersFrom(
6262
this ICommandModelBuilder builder,
6363
Action<IServiceDescriptorReflectionBuilder> configure,
6464
ServiceLifetime defaultLifetime = ServiceLifetime.Transient)
@@ -85,7 +85,7 @@ public static ICommandModelBuilder WithHandlersFrom(
8585
/// <param name="lifetime">The lifetime of the handler.</param>
8686
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
8787
/// <exception cref="ArgumentNullException">Argument <paramref name="handlerType"/> is <c>null</c>.</exception>
88-
public static ICommandModelBuilder WithPreHandler(
88+
public static ICommandModelBuilder AddPreHandler(
8989
this ICommandModelBuilder builder,
9090
Type handlerType,
9191
ServiceLifetime lifetime = ServiceLifetime.Transient)
@@ -107,7 +107,7 @@ public static ICommandModelBuilder WithPreHandler(
107107
/// <param name="defaultLifetime">The default handler lifetime.</param>
108108
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
109109
/// <exception cref="ArgumentNullException">Argument <paramref name="configure"/> is <c>null</c>.</exception>
110-
public static ICommandModelBuilder WithPreHandlersFrom(
110+
public static ICommandModelBuilder AddPreHandlersFrom(
111111
this ICommandModelBuilder builder,
112112
Action<IServiceDescriptorReflectionBuilder> configure,
113113
ServiceLifetime defaultLifetime = ServiceLifetime.Transient)
@@ -134,7 +134,7 @@ public static ICommandModelBuilder WithPreHandlersFrom(
134134
/// <param name="lifetime">The lifetime of the handler.</param>
135135
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
136136
/// <exception cref="ArgumentNullException">Argument <paramref name="handlerType"/> is <c>null</c>.</exception>
137-
public static ICommandModelBuilder WithPostHandler(
137+
public static ICommandModelBuilder AddPostHandler(
138138
this ICommandModelBuilder builder,
139139
Type handlerType,
140140
ServiceLifetime lifetime = ServiceLifetime.Transient)
@@ -156,7 +156,7 @@ public static ICommandModelBuilder WithPostHandler(
156156
/// <param name="defaultLifetime">The default handler lifetime.</param>
157157
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
158158
/// <exception cref="ArgumentNullException">Argument <paramref name="configure"/> is <c>null</c>.</exception>
159-
public static ICommandModelBuilder WithPostHandlersFrom(
159+
public static ICommandModelBuilder AddPostHandlersFrom(
160160
this ICommandModelBuilder builder,
161161
Action<IServiceDescriptorReflectionBuilder> configure,
162162
ServiceLifetime defaultLifetime = ServiceLifetime.Transient)
@@ -183,7 +183,7 @@ public static ICommandModelBuilder WithPostHandlersFrom(
183183
/// <param name="lifetime">The lifetime of the handler.</param>
184184
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
185185
/// <exception cref="ArgumentNullException">Argument <paramref name="handlerType"/> is <c>null</c>.</exception>
186-
public static ICommandModelBuilder WithBehavior(
186+
public static ICommandModelBuilder AddBehavior(
187187
this ICommandModelBuilder builder,
188188
Type handlerType,
189189
ServiceLifetime lifetime = ServiceLifetime.Transient)
@@ -205,7 +205,7 @@ public static ICommandModelBuilder WithBehavior(
205205
/// <param name="defaultLifetime">The default handler lifetime.</param>
206206
/// <returns>The <see cref="ICommandModelBuilder"/>.</returns>
207207
/// <exception cref="ArgumentNullException">Argument <paramref name="configure"/> is <c>null</c>.</exception>
208-
public static ICommandModelBuilder WithBehaviorsFrom(
208+
public static ICommandModelBuilder AddBehaviorsFrom(
209209
this ICommandModelBuilder builder,
210210
Action<IServiceDescriptorReflectionBuilder> configure,
211211
ServiceLifetime defaultLifetime = ServiceLifetime.Transient)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using AppCore.CommandModel.Metadata;
2+
using AppCore.CommandModel.Pipeline;
3+
using AppCore.Extensions.DependencyInjection;
4+
using FluentAssertions;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Xunit;
7+
8+
namespace AppCore.CommandModel;
9+
10+
public class CommandModelRegistrationTests
11+
{
12+
[Fact]
13+
public void AddCommandModelRegistersCoreServices()
14+
{
15+
var services = new ServiceCollection();
16+
17+
services.AddAppCore()
18+
.AddCommandModel();
19+
20+
services.Should()
21+
.ContainEquivalentOf(ServiceDescriptor.Transient<ICommandProcessor, CommandProcessor>());
22+
23+
services.Should()
24+
.ContainEquivalentOf(
25+
ServiceDescriptor.Singleton<ICommandDescriptorFactory, CommandDescriptorFactory>());
26+
27+
services.Should()
28+
.ContainEquivalentOf(
29+
ServiceDescriptor.Singleton<ICommandMetadataProvider, CancelableCommandMetadataProvider>());
30+
31+
services.Should()
32+
.ContainEquivalentOf(
33+
ServiceDescriptor.Singleton(
34+
typeof(ICommandPipelineBehavior<,>),
35+
typeof(CancelableCommandBehavior<,>)));
36+
37+
services.Should()
38+
.ContainEquivalentOf(
39+
ServiceDescriptor.Transient(
40+
typeof(ICommandPipelineBehavior<,>),
41+
typeof(PreCommandHandlerBehavior<,>)));
42+
43+
services.Should()
44+
.ContainEquivalentOf(
45+
ServiceDescriptor.Transient(
46+
typeof(ICommandPipelineBehavior<,>),
47+
typeof(PostCommandHandlerBehavior<,>)));
48+
}
49+
50+
[Fact]
51+
public void WithCommandContextRegistersContextAccessor()
52+
{
53+
var services = new ServiceCollection();
54+
55+
services.AddAppCore()
56+
.AddCommandModel(c => c.AddCommandContext());
57+
58+
services.Should()
59+
.ContainEquivalentOf(ServiceDescriptor.Singleton<ICommandContextAccessor, CommandContextAccessor>());
60+
}
61+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace AppCore.CommandModel;
5+
6+
#nullable disable
7+
public class ServiceCollection : List<ServiceDescriptor>, IServiceCollection
8+
{
9+
}
10+
#nullable restore

0 commit comments

Comments
 (0)