Skip to content

Commit 77f97d9

Browse files
Register LoggingBehaviour
1 parent bb4f72a commit 77f97d9

File tree

8 files changed

+17
-12
lines changed

8 files changed

+17
-12
lines changed

src/Application/Common/Behaviours/AuthorizationBehaviour.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
namespace CleanArchitecture.Application.Common.Behaviours;
77

8-
public class AuthorizationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
8+
public class AuthorizationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
9+
where TRequest : notnull
910
{
1011
private readonly IUser _user;
1112
private readonly IIdentityService _identityService;

src/Application/Common/Behaviours/LoggingBehaviour.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace CleanArchitecture.Application.Common.Behaviours;
66

7-
public class LoggingBehaviour<TRequest> : IRequestPreProcessor<TRequest> where TRequest : notnull
7+
public class LoggingBehaviour<TRequest> : IRequestPreProcessor<TRequest>
8+
where TRequest : notnull
89
{
910
private readonly ILogger _logger;
1011
private readonly IUser _user;

src/Application/Common/Behaviours/PerformanceBehaviour.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace CleanArchitecture.Application.Common.Behaviours;
66

7-
public class PerformanceBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
7+
public class PerformanceBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
8+
where TRequest : notnull
89
{
910
private readonly Stopwatch _timer;
1011
private readonly ILogger<TRequest> _logger;

src/Application/Common/Behaviours/UnhandledExceptionBehaviour.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace CleanArchitecture.Application.Common.Behaviours;
44

5-
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
5+
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
6+
where TRequest : notnull
67
{
78
private readonly ILogger<TRequest> _logger;
89

src/Application/Common/Behaviours/ValidationBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace CleanArchitecture.Application.Common.Behaviours;
44

55
public class ValidationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
6-
where TRequest : notnull
6+
where TRequest : notnull
77
{
88
private readonly IEnumerable<IValidator<TRequest>> _validators;
99

src/Application/DependencyInjection.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)
1414

1515
builder.Services.AddMediatR(cfg => {
1616
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
17-
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
18-
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehaviour<,>));
19-
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
20-
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));
17+
cfg.AddOpenRequestPreProcessor(typeof(LoggingBehaviour<>));
18+
cfg.AddOpenBehavior(typeof(UnhandledExceptionBehaviour<,>));
19+
cfg.AddOpenBehavior(typeof(AuthorizationBehaviour<,>));
20+
cfg.AddOpenBehavior(typeof(ValidationBehaviour<,>));
21+
cfg.AddOpenBehavior(typeof(PerformanceBehaviour<,>));
2122
});
2223
}
2324
}

src/Infrastructure/DependencyInjection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void AddInfrastructureServices(this IHostApplicationBuilder builde
3030
options.UseSqlite(connectionString);
3131
#else
3232
options.UseSqlServer(connectionString);
33-
#endif
33+
#endif
3434
options.ConfigureWarnings(warnings => warnings.Ignore(RelationalEventId.PendingModelChangesWarning));
3535
});
3636

src/Web/Web.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@
6868
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
6969
</PropertyGroup>
7070

71-
<Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' And '$(SkipNSwag)' != 'True' ">
71+
<Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' And '$(SkipNSwag)' != 'True' ">
7272
<Exec ConsoleToMSBuild="true" ContinueOnError="true" WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net90) run config.nswag /variables:Configuration=$(Configuration)">
7373
<Output TaskParameter="ExitCode" PropertyName="NSwagExitCode" />
7474
<Output TaskParameter="ConsoleOutput" PropertyName="NSwagOutput" />
7575
</Exec>
7676

7777
<Message Text="$(NSwagOutput)" Condition="'$(NSwagExitCode)' == '0'" Importance="low" />
7878
<Error Text="$(NSwagOutput)" Condition="'$(NSwagExitCode)' != '0'" />
79-
</Target>
79+
</Target>
8080

8181
<!--#if (!UseApiOnly)-->
8282
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">

0 commit comments

Comments
 (0)