Skip to content

Commit

Permalink
Cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-libaud committed Apr 1, 2024
1 parent ccdeca4 commit b60f5f4
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 38 deletions.
10 changes: 4 additions & 6 deletions src/One.More.Lib.For.MediatR/FluentValidationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection;
using FluentValidation;

namespace One.More.Lib.For.MediatR;

public partial class MediatRExtensionConfiguration
{
internal bool FluentValidationSupport { get; set; } = false;
internal bool FluentValidationSupport { get; private set; } = false;

internal IEnumerable<Assembly> Assemblies { get; private set; } = new List<Assembly>();

internal Func<AssemblyScanner.AssemblyScanResult, bool> Filter { get; private set; } = null;
internal Func<AssemblyScanner.AssemblyScanResult, bool>? Filter { get; private set; } = null;

internal bool IncludeInternalTypes { get; private set; } = false;

public MediatRExtensionConfiguration AddFluentValidationSupport(IEnumerable<Assembly> assemblies, Func<AssemblyScanner.AssemblyScanResult, bool> filter = null, bool includeInternalTypes = false)
public MediatRExtensionConfiguration AddFluentValidationSupport(IEnumerable<Assembly> assemblies, Func<AssemblyScanner.AssemblyScanResult, bool>? filter = null, bool includeInternalTypes = false)
{
FluentValidationSupport = true;
Assemblies = assemblies;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsyncLinqR;
using AsyncLinqR;
using FluentValidation;
using MediatR;

namespace One.More.Lib.For.MediatR;

internal class FluentValidationPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
internal class FluentValidationPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
{
private readonly IEnumerable<IValidator<TRequest>> _validators;

Expand Down
5 changes: 2 additions & 3 deletions src/One.More.Lib.For.MediatR/MemoryCacheConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Caching.Memory;

namespace One.More.Lib.For.MediatR;

public partial class MediatRExtensionConfiguration
{
public bool MemoryCacheSupport { get; set; } = false;

internal MemoryCacheConfiguration MemoryCacheConfiguration { get; set; } = new();
internal MemoryCacheConfiguration MemoryCacheConfiguration { get; } = new();

public MediatRExtensionConfiguration AddMemoryCacheSupport(
DateTimeOffset? absoluteExpiration = null,
Expand Down
16 changes: 6 additions & 10 deletions src/One.More.Lib.For.MediatR/MemoryCachePipelineBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using MediatR;
using Microsoft.Extensions.Caching.Memory;

Expand All @@ -16,9 +12,9 @@ public class MemoryCacheAttribute : Attribute

internal class MemoryCacheConfiguration
{
internal MemoryCacheItemConfiguration MainConfiguration { get; set; } = new();
internal MemoryCacheItemConfiguration MainConfiguration { get; } = new();

internal Dictionary<Type, MemoryCacheItemConfiguration> OverrideConfigurations { get; set; } = new();
internal Dictionary<Type, MemoryCacheItemConfiguration> OverrideConfigurations { get; } = new();
}

internal class MemoryCacheItemConfiguration
Expand All @@ -32,7 +28,7 @@ internal class MemoryCacheItemConfiguration
internal CacheItemPriority Priority { get; set; }
}

internal class MemoryCachePipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
internal class MemoryCachePipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
{
private readonly IMemoryCache _memoryCache;
private readonly MemoryCacheConfiguration _configuration;
Expand All @@ -50,7 +46,7 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
if (memoryPolicy == null || !memoryPolicy.IsActive)
return await next();

if (!_memoryCache.TryGetValue(request, out TResponse result))
if (!_memoryCache.TryGetValue(request, out TResponse? result))
{
result = await next();

Expand All @@ -65,6 +61,6 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
});
}

return result;
return result!;
}
}
2 changes: 2 additions & 0 deletions src/One.More.Lib.For.MediatR/One.More.Lib.For.MediatR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Description>One more library for MediatR. It allows you to configure the most commonly used PipelineBehaviors in a very simple way.</Description>
<Authors>Pascal LIBAUD</Authors>
<Company></Company>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.Logging;

namespace One.More.Lib.For.MediatR;

internal class PerformanceLoggerConfiguration
{
internal int TriggerThreshold { get; set; }
internal int TriggerThreshold { get; init; }
}

internal class PerformanceLoggerPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
internal class PerformanceLoggerPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
{
private readonly ILogger<PerformanceLoggerPipelineBehavior<TRequest, TResponse>> _logger;
private readonly PerformanceLoggerConfiguration _configuration;
Expand Down
1 change: 0 additions & 1 deletion src/One.More.Lib.For.MediatR/RetryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public partial class MediatRExtensionConfiguration
{

public bool RetrySupport { get; set; } = false;

public int RetryCount { get; set; } = 3;
Expand Down
9 changes: 3 additions & 6 deletions src/One.More.Lib.For.MediatR/RetryPipelineBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.Logging;
using Polly;
Expand All @@ -20,11 +17,11 @@ public class RetryPolicyAttribute : Attribute

internal class RetryConfiguration
{
internal int RetryCount { get; set; }
internal int RetryDelay { get; set; }
internal int RetryCount { get; init; }
internal int RetryDelay { get; init; }
}

internal class RetryPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
internal class RetryPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
{
private readonly ILogger<RetryPipelineBehavior<TRequest, TResponse>> _logger;
private readonly RetryConfiguration _configuration;
Expand Down
3 changes: 1 addition & 2 deletions src/One.More.Lib.For.MediatR/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using FluentValidation;
using FluentValidation;
using MediatR;
using Microsoft.Extensions.DependencyInjection;

Expand Down

0 comments on commit b60f5f4

Please # to comment.