From 001e97beaaf7de5aec63369f7421b0feb8607774 Mon Sep 17 00:00:00 2001 From: Mohsen Rajabi Date: Thu, 16 May 2024 15:46:54 +0330 Subject: [PATCH] feat: update pkg --- Directory.Build.props | 22 ++++++--- MediatR.Useful.Behavior.sln | 7 --- .../Controllers/WeatherForecastController.cs | 5 +- example/Example/Example.csproj | 9 ++-- example/Example/Program.cs | 4 +- .../Controllers/WeatherForecastController.cs | 37 -------------- example/Example3.1/Example3.1.csproj | 17 ------- example/Example3.1/Program.cs | 18 ------- .../Example3.1/Properties/launchSettings.json | 30 ------------ example/Example3.1/Startup.cs | 49 ------------------- example/Example3.1/WeatherForecast.cs | 13 ----- .../Example3.1/appsettings.Development.json | 9 ---- example/Example3.1/appsettings.json | 10 ---- .../MediatR.Useful.Behavior.csproj | 48 +++++++----------- test/UnitTest/Behavior/CachingBehaviorTest.cs | 4 +- test/UnitTest/UnitTest.csproj | 8 ++- 16 files changed, 49 insertions(+), 241 deletions(-) delete mode 100644 example/Example3.1/Controllers/WeatherForecastController.cs delete mode 100644 example/Example3.1/Example3.1.csproj delete mode 100644 example/Example3.1/Program.cs delete mode 100644 example/Example3.1/Properties/launchSettings.json delete mode 100644 example/Example3.1/Startup.cs delete mode 100644 example/Example3.1/WeatherForecast.cs delete mode 100644 example/Example3.1/appsettings.Development.json delete mode 100644 example/Example3.1/appsettings.json diff --git a/Directory.Build.props b/Directory.Build.props index f800ddc..11b9bf0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,8 +15,14 @@ CA1054: Change the type of parameter of the method to allow a Uri to be passed as a 'System.Uri' object CA1055: Change the return type of method from 'string' to 'System.Uri' --> - $(NoWarn);SCS0004;MA0016;MA0048;MA0039;MA0025;MA0055;MA0002 - $(NoError);SCS0004;MA0016;MA0048;MA0039;MA0025;MA0055;MA0002 + + $(NoWarn);SCS0004;MA0016;MA0048;MA0039;MA0025;MA0055;MA0002;CA1002;CA1031; + CA1724;CA1822;CA1860;CA2227 + + + $(NoError);SCS0004;MA0016;MA0048;MA0039;MA0025;MA0055;MA0002;CA1002;CA1031; + CA1724;CA1822;CA1860;CA2227 + true All true @@ -37,12 +43,12 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -52,22 +58,22 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MediatR.Useful.Behavior.sln b/MediatR.Useful.Behavior.sln index 7f044e3..e47de35 100644 --- a/MediatR.Useful.Behavior.sln +++ b/MediatR.Useful.Behavior.sln @@ -30,8 +30,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Example", "Example", "{0428 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "example\Example\Example.csproj", "{3587539F-8313-434A-A9A4-BAAC93BC0DB1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example3.1", "example\Example3.1\Example3.1.csproj", "{6A646743-82A9-4958-83A4-E69006FDC145}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,10 +48,6 @@ Global {3587539F-8313-434A-A9A4-BAAC93BC0DB1}.Debug|Any CPU.Build.0 = Debug|Any CPU {3587539F-8313-434A-A9A4-BAAC93BC0DB1}.Release|Any CPU.ActiveCfg = Release|Any CPU {3587539F-8313-434A-A9A4-BAAC93BC0DB1}.Release|Any CPU.Build.0 = Release|Any CPU - {6A646743-82A9-4958-83A4-E69006FDC145}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6A646743-82A9-4958-83A4-E69006FDC145}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6A646743-82A9-4958-83A4-E69006FDC145}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6A646743-82A9-4958-83A4-E69006FDC145}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -63,7 +57,6 @@ Global {3B157CBA-46AB-41EB-9E9C-EE6470E2C159} = {9034ACAE-6D26-4B4A-B8E1-6E5C610550E6} {04282C3C-A3F4-4C71-B391-CC3ADF68F76E} = {EB67E851-A2EA-4731-A3A5-01D615A3AAA2} {3587539F-8313-434A-A9A4-BAAC93BC0DB1} = {04282C3C-A3F4-4C71-B391-CC3ADF68F76E} - {6A646743-82A9-4958-83A4-E69006FDC145} = {04282C3C-A3F4-4C71-B391-CC3ADF68F76E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5AEA13C4-9243-49C3-B054-D4EDC6898F50} diff --git a/example/Example/Controllers/WeatherForecastController.cs b/example/Example/Controllers/WeatherForecastController.cs index c7617a3..8e4e9d8 100644 --- a/example/Example/Controllers/WeatherForecastController.cs +++ b/example/Example/Controllers/WeatherForecastController.cs @@ -1,6 +1,7 @@ using Example.Command; using MediatR; using Microsoft.AspNetCore.Mvc; +using System.Security.Cryptography; namespace Example.Controllers; [ApiController] @@ -27,8 +28,8 @@ public IEnumerable Get() return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] + TemperatureC = RandomNumberGenerator.GetInt32(-20, 55), + Summary = Summaries[RandomNumberGenerator.GetInt32(Summaries.Length)] }) .ToArray(); } diff --git a/example/Example/Example.csproj b/example/Example/Example.csproj index 57ad692..8edf420 100644 --- a/example/Example/Example.csproj +++ b/example/Example/Example.csproj @@ -1,20 +1,23 @@  - net7.0 + net8.0 enable enable - - + + + + + diff --git a/example/Example/Program.cs b/example/Example/Program.cs index 8723ccb..daed5d6 100644 --- a/example/Example/Program.cs +++ b/example/Example/Program.cs @@ -1,5 +1,3 @@ - -using MediatR; using MediatR.Useful.Behavior.DependencyInjection; namespace Example; @@ -12,7 +10,7 @@ public static void Main(string[] args) // Add services to the container. - builder.Services.AddMediatR(typeof(Program).Assembly); + builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly)); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); diff --git a/example/Example3.1/Controllers/WeatherForecastController.cs b/example/Example3.1/Controllers/WeatherForecastController.cs deleted file mode 100644 index 487175b..0000000 --- a/example/Example3.1/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Example3._1.Controllers; -[ApiController] -[Route("[controller]")] -public class WeatherForecastController : ControllerBase -{ - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } -} diff --git a/example/Example3.1/Example3.1.csproj b/example/Example3.1/Example3.1.csproj deleted file mode 100644 index accf590..0000000 --- a/example/Example3.1/Example3.1.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - netcoreapp3.1 - Example3._1 - - - - - - - - - - - - diff --git a/example/Example3.1/Program.cs b/example/Example3.1/Program.cs deleted file mode 100644 index 84cf933..0000000 --- a/example/Example3.1/Program.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; - -namespace Example3._1; -public static class Program -{ - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); -} diff --git a/example/Example3.1/Properties/launchSettings.json b/example/Example3.1/Properties/launchSettings.json deleted file mode 100644 index 3f1f6a6..0000000 --- a/example/Example3.1/Properties/launchSettings.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:14725", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Example3._1": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "applicationUrl": "http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/example/Example3.1/Startup.cs b/example/Example3.1/Startup.cs deleted file mode 100644 index 9263c35..0000000 --- a/example/Example3.1/Startup.cs +++ /dev/null @@ -1,49 +0,0 @@ -using MediatR; -using MediatR.Useful.Behavior.DependencyInjection; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace Example3._1; -public class Startup -{ - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddMediatR(typeof(Program).Assembly); - services.AddControllers(); - services.AddMemoryCache(); - services.AddDistributedMemoryCache(); - - - // add AddAllBehaviors (cache, validation, unhandled log, performance log) - services.AddAllBehaviors(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } -} diff --git a/example/Example3.1/WeatherForecast.cs b/example/Example3.1/WeatherForecast.cs deleted file mode 100644 index c0d506a..0000000 --- a/example/Example3.1/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Example3._1; -public class WeatherForecast -{ - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } -} diff --git a/example/Example3.1/appsettings.Development.json b/example/Example3.1/appsettings.Development.json deleted file mode 100644 index 8983e0f..0000000 --- a/example/Example3.1/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/example/Example3.1/appsettings.json b/example/Example3.1/appsettings.json deleted file mode 100644 index d9d9a9b..0000000 --- a/example/Example3.1/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -} diff --git a/src/MediatR.Useful.Behavior/MediatR.Useful.Behavior.csproj b/src/MediatR.Useful.Behavior/MediatR.Useful.Behavior.csproj index 7db95bf..a390b9f 100644 --- a/src/MediatR.Useful.Behavior/MediatR.Useful.Behavior.csproj +++ b/src/MediatR.Useful.Behavior/MediatR.Useful.Behavior.csproj @@ -8,36 +8,18 @@ In this repository; I tried to write and save the best popular behaviors that we use in mediatr in a professional way. And they will be added and improved over time. The best library to complete mediatr - 1.0.5 - 1.0.5 - 1.0.5 + 1.0.6 + 1.0.6 + 1.0.6 mediatr;mediator;behavior;response;cache;validation;behaviors;distributedcache;fluent;fluentvalidation;distributecache;MediatR Useful Behavior; enrich;enrichmediatr MediatR.Useful.Behavior - v1.0.5 - Breaking changes - - change packages - v1.0.4 - Breaking changes - - add UnhandledExceptionBehaviour - - add PerformanceBehaviour - v1.0.3 - Breaking changes - - update doc - - add example - v1.0.2 - Breaking changes - - add Scrutor for automatic validator added - v1.0.1 - Breaking changes - - clean up dependency - v1.0.0 - Breaking changes - - add cache behavior - - add valdiation behavior + v1.0.6 + - update net 8 + - add rate limit Behavior MediatR Useful Behavior icon.png @@ -56,13 +38,17 @@ - - - - - - - + + + + + + + + + + + diff --git a/test/UnitTest/Behavior/CachingBehaviorTest.cs b/test/UnitTest/Behavior/CachingBehaviorTest.cs index 234004d..a556c68 100644 --- a/test/UnitTest/Behavior/CachingBehaviorTest.cs +++ b/test/UnitTest/Behavior/CachingBehaviorTest.cs @@ -52,9 +52,9 @@ public async Task CheckDistributeCache(GetUserPointCommandRes resultBehaviour, G //Assert _behaviourDelegate.Verify(r => r.Invoke(), Times.Exactly(countBehaviurCall)); _cahce.Verify(r => r.GetAsync( - It.Is(r => r.Equals(requestCommandRq.CacheKey)), default), Times.Exactly(callGetCache)); + It.Is(r => r.Equals(requestCommandRq.CacheKey, StringComparison.OrdinalIgnoreCase)), default), Times.Exactly(callGetCache)); - _cahce.Verify(r => r.SetAsync(It.Is(r => r.Equals(requestCommandRq.CacheKey)), + _cahce.Verify(r => r.SetAsync(It.Is(r => r.Equals(requestCommandRq.CacheKey, StringComparison.OrdinalIgnoreCase)), resultBehaviour.ToJsonUtf8Bytes(), It.Is(r => Math.Abs((r.AbsoluteExpiration.Value - requestCommandRq.ConditionExpiration(resultBehaviour)).TotalSeconds) < 10), default), Times.Exactly(callSetCache)); diff --git a/test/UnitTest/UnitTest.csproj b/test/UnitTest/UnitTest.csproj index 5d41a0e..cd4656e 100644 --- a/test/UnitTest/UnitTest.csproj +++ b/test/UnitTest/UnitTest.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 false @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -24,4 +24,8 @@ + + + + \ No newline at end of file