From 247db5d1d3ff7366e775f772121d04c823f9be5f Mon Sep 17 00:00:00 2001 From: Khanbala Rashidov <50279392+KhanbalaRashidov@users.noreply.github.com> Date: Wed, 17 Jul 2024 20:38:42 +0400 Subject: [PATCH 1/2] Update Benchmark project --- src/Benchmarks/Configuration/ConsoleArgs.cs | 9 ++------ .../ConsoleHostScenariosConfiguration.cs | 9 ++------ .../Configuration/EnabledScenario.cs | 12 +++-------- src/Benchmarks/Configuration/Scenarios.cs | 5 +---- src/Benchmarks/Controllers/HomeController.cs | 15 +++---------- .../Controllers/MultipleQueriesController.cs | 15 +++---------- .../Controllers/MultipleUpdatesController.cs | 15 +++---------- .../Controllers/SingleQueryController.cs | 15 +++---------- src/Benchmarks/Data/DapperDb.cs | 21 ++++++------------- src/Benchmarks/Data/EfDb.cs | 13 +++--------- src/Benchmarks/Data/Fortune.cs | 12 +++-------- src/Benchmarks/Data/Random.cs | 5 +---- src/Benchmarks/Data/RawDb.cs | 15 ++++--------- .../Middleware/AutoShutdownMiddleware.cs | 15 ++++--------- .../Middleware/CopyToAsyncMiddleware.cs | 15 ++++--------- .../Middleware/FortunesDapperMiddleware.cs | 18 +++++----------- .../Middleware/FortunesEfMiddleware.cs | 18 +++++----------- .../Middleware/FortunesRawMiddleware.cs | 18 +++++----------- .../Middleware/FortunesRawSyncMiddleware.cs | 18 +++++----------- src/Benchmarks/Middleware/JsonMiddleware.cs | 9 ++------ .../MemoryCachePlaintextMiddleware.cs | 18 +++++----------- ...MemoryCachePlaintextSetRemoveMiddleware.cs | 18 +++++----------- .../MultipleQueriesDapperMiddleware.cs | 15 ++++--------- .../Middleware/MultipleQueriesEfMiddleware.cs | 15 ++++--------- .../MultipleQueriesRawMiddleware.cs | 15 ++++--------- .../MultipleUpdatesDapperMiddleware.cs | 15 ++++--------- .../Middleware/MultipleUpdatesEfMiddleware.cs | 14 +++---------- .../MultipleUpdatesRawMiddleware.cs | 15 ++++--------- .../Middleware/PlaintextMiddleware.cs | 15 ++++--------- ...esponseCachingPlaintextCachedMiddleware.cs | 15 ++++--------- ...achingPlaintextRequestNoCacheMiddleware.cs | 15 ++++--------- ...chingPlaintextResponseNoCacheMiddleware.cs | 15 ++++--------- ...eCachingPlaintextVaryByCachedMiddleware.cs | 15 ++++--------- .../Middleware/SingleQueryDapperMiddleware.cs | 15 ++++--------- .../Middleware/SingleQueryEfMiddleware.cs | 15 ++++--------- .../Middleware/SingleQueryRawMiddleware.cs | 15 ++++--------- 36 files changed, 132 insertions(+), 385 deletions(-) diff --git a/src/Benchmarks/Configuration/ConsoleArgs.cs b/src/Benchmarks/Configuration/ConsoleArgs.cs index 1ad394f9b..7f0b76b01 100644 --- a/src/Benchmarks/Configuration/ConsoleArgs.cs +++ b/src/Benchmarks/Configuration/ConsoleArgs.cs @@ -3,13 +3,8 @@ namespace Benchmarks.Configuration { - public class ConsoleArgs + public class ConsoleArgs(string[] args) { - public ConsoleArgs(string[] args) - { - Args = args; - } - - public string[] Args { get; } + public string[] Args { get; } = args; } } diff --git a/src/Benchmarks/Configuration/ConsoleHostScenariosConfiguration.cs b/src/Benchmarks/Configuration/ConsoleHostScenariosConfiguration.cs index b60ff1a9d..ca0d01bd9 100644 --- a/src/Benchmarks/Configuration/ConsoleHostScenariosConfiguration.cs +++ b/src/Benchmarks/Configuration/ConsoleHostScenariosConfiguration.cs @@ -8,14 +8,9 @@ namespace Benchmarks.Configuration { - public class ConsoleHostScenariosConfiguration : IScenariosConfiguration + public class ConsoleHostScenariosConfiguration(ConsoleArgs args) : IScenariosConfiguration { - private readonly string[] _args; - - public ConsoleHostScenariosConfiguration(ConsoleArgs args) - { - _args = args.Args; - } + private readonly string[] _args = args.Args; public void ConfigureScenarios(Scenarios scenarios) { diff --git a/src/Benchmarks/Configuration/EnabledScenario.cs b/src/Benchmarks/Configuration/EnabledScenario.cs index 14dd6d7f0..0cb90af9e 100644 --- a/src/Benchmarks/Configuration/EnabledScenario.cs +++ b/src/Benchmarks/Configuration/EnabledScenario.cs @@ -5,16 +5,10 @@ namespace Benchmarks.Configuration { - public class EnabledScenario + public class EnabledScenario(string name, IEnumerable paths) { - public EnabledScenario(string name, IEnumerable paths) - { - Name = name; - Paths = paths; - } + public string Name { get; } = name; - public string Name { get; } - - public IEnumerable Paths { get; } + public IEnumerable Paths { get; } = paths; } } diff --git a/src/Benchmarks/Configuration/Scenarios.cs b/src/Benchmarks/Configuration/Scenarios.cs index 15b4f2e26..3ecc1c7e7 100644 --- a/src/Benchmarks/Configuration/Scenarios.cs +++ b/src/Benchmarks/Configuration/Scenarios.cs @@ -13,10 +13,7 @@ namespace Benchmarks.Configuration { public class Scenarios { - public Scenarios(IScenariosConfiguration scenariosConfiguration) - { - scenariosConfiguration.ConfigureScenarios(this); - } + public Scenarios(IScenariosConfiguration scenariosConfiguration) => scenariosConfiguration.ConfigureScenarios(this); [ScenarioPath("/plaintext")] public bool Plaintext { get; set; } diff --git a/src/Benchmarks/Controllers/HomeController.cs b/src/Benchmarks/Controllers/HomeController.cs index 7532a3440..f00864925 100644 --- a/src/Benchmarks/Controllers/HomeController.cs +++ b/src/Benchmarks/Controllers/HomeController.cs @@ -50,17 +50,11 @@ public class HomeController : Controller }).ToList(); [HttpGet("plaintext")] - public IActionResult Plaintext() - { - return new PlainTextActionResult(); - } + public IActionResult Plaintext() => new PlainTextActionResult(); [HttpGet("json")] [Produces("application/json")] - public object Json() - { - return new { message = "Hello, World!" }; - } + public object Json() => new { message = "Hello, World!" }; // Note that this produces 4kb data. We're leaving the misnamed scenario as is to avoid loosing historical context [HttpGet("json2k")] @@ -76,10 +70,7 @@ public object Json() public ActionResult JsonInput([FromBody] List entry) => Ok(); [HttpGet("view")] - public ViewResult Index() - { - return View(); - } + public ViewResult Index() => View(); private class PlainTextActionResult : IActionResult { diff --git a/src/Benchmarks/Controllers/MultipleQueriesController.cs b/src/Benchmarks/Controllers/MultipleQueriesController.cs index b1a2fbdf2..948f87f5c 100644 --- a/src/Benchmarks/Controllers/MultipleQueriesController.cs +++ b/src/Benchmarks/Controllers/MultipleQueriesController.cs @@ -13,24 +13,15 @@ public class MultipleQueriesController : Controller { [HttpGet("raw")] [Produces("application/json")] - public Task Raw(int queries = 1) - { - return ExecuteQuery(queries); - } + public Task Raw(int queries = 1) => ExecuteQuery(queries); [HttpGet("dapper")] [Produces("application/json")] - public Task Dapper(int queries = 1) - { - return ExecuteQuery(queries); - } + public Task Dapper(int queries = 1) => ExecuteQuery(queries); [HttpGet("ef")] [Produces("application/json")] - public Task Ef(int queries = 1) - { - return ExecuteQuery(queries); - } + public Task Ef(int queries = 1) => ExecuteQuery(queries); private Task ExecuteQuery(int queries) where T : IDb { diff --git a/src/Benchmarks/Controllers/MultipleUpdatesController.cs b/src/Benchmarks/Controllers/MultipleUpdatesController.cs index 59a980914..c2bdfcea1 100644 --- a/src/Benchmarks/Controllers/MultipleUpdatesController.cs +++ b/src/Benchmarks/Controllers/MultipleUpdatesController.cs @@ -13,24 +13,15 @@ public class MultipleUpdatesController : Controller { [HttpGet("raw")] [Produces("application/json")] - public Task Raw(int queries = 1) - { - return ExecuteQuery(queries); - } + public Task Raw(int queries = 1) => ExecuteQuery(queries); [HttpGet("dapper")] [Produces("application/json")] - public Task Dapper(int queries = 1) - { - return ExecuteQuery(queries); - } + public Task Dapper(int queries = 1) => ExecuteQuery(queries); [HttpGet("ef")] [Produces("application/json")] - public Task Ef(int queries = 1) - { - return ExecuteQuery(queries); - } + public Task Ef(int queries = 1) => ExecuteQuery(queries); private Task ExecuteQuery(int queries) where T : IDb { diff --git a/src/Benchmarks/Controllers/SingleQueryController.cs b/src/Benchmarks/Controllers/SingleQueryController.cs index 5546f84af..484bcc18f 100644 --- a/src/Benchmarks/Controllers/SingleQueryController.cs +++ b/src/Benchmarks/Controllers/SingleQueryController.cs @@ -13,24 +13,15 @@ public class SingleQueryController : Controller { [HttpGet("raw")] [Produces("application/json")] - public Task Raw() - { - return ExecuteQuery(); - } + public Task Raw() => ExecuteQuery(); [HttpGet("dapper")] [Produces("application/json")] - public Task Dapper() - { - return ExecuteQuery(); - } + public Task Dapper() => ExecuteQuery(); [HttpGet("ef")] [Produces("application/json")] - public Task Ef() - { - return ExecuteQuery(); - } + public Task Ef() => ExecuteQuery(); private Task ExecuteQuery() where T : IDb { diff --git a/src/Benchmarks/Data/DapperDb.cs b/src/Benchmarks/Data/DapperDb.cs index 99f326627..8b2d88208 100644 --- a/src/Benchmarks/Data/DapperDb.cs +++ b/src/Benchmarks/Data/DapperDb.cs @@ -12,20 +12,13 @@ namespace Benchmarks.Data { - public class DapperDb : IDb + public class DapperDb(IRandom random, DbProviderFactory dbProviderFactory, IOptions appSettings) : IDb { private static readonly Comparison WorldSortComparison = (a, b) => a.Id.CompareTo(b.Id); - private readonly IRandom _random; - private readonly DbProviderFactory _dbProviderFactory; - private readonly string _connectionString; - - public DapperDb(IRandom random, DbProviderFactory dbProviderFactory, IOptions appSettings) - { - _random = random; - _dbProviderFactory = dbProviderFactory; - _connectionString = appSettings.Value.ConnectionString; - } + private readonly IRandom _random = random; + private readonly DbProviderFactory _dbProviderFactory = dbProviderFactory; + private readonly string _connectionString = appSettings.Value.ConnectionString; public async Task LoadSingleQueryRow() { @@ -38,12 +31,10 @@ public async Task LoadSingleQueryRow() } } - Task ReadSingleRow(DbConnection db) - { - return db.QueryFirstOrDefaultAsync( + Task ReadSingleRow(DbConnection db) => + db.QueryFirstOrDefaultAsync( "SELECT id, randomnumber FROM world WHERE id = @Id", new { Id = _random.Next(1, 10001) }); - } public async Task LoadMultipleQueriesRows(int count) { diff --git a/src/Benchmarks/Data/EfDb.cs b/src/Benchmarks/Data/EfDb.cs index 23ec5dd3b..1fe58eabf 100644 --- a/src/Benchmarks/Data/EfDb.cs +++ b/src/Benchmarks/Data/EfDb.cs @@ -13,17 +13,10 @@ namespace Benchmarks.Data { - public class EfDb : IDb + public class EfDb(IRandom random, ApplicationDbContext dbContext, IOptions appSettings) : IDb { - private readonly IRandom _random; - private readonly ApplicationDbContext _dbContext; - - public EfDb(IRandom random, ApplicationDbContext dbContext, IOptions appSettings) - { - _random = random; - _dbContext = dbContext; - } - + private readonly IRandom _random = random; + private readonly ApplicationDbContext _dbContext = dbContext; private static readonly Func> _firstWorldQuery = EF.CompileAsyncQuery((ApplicationDbContext context, int id) => context.World.First(w => w.Id == id)); diff --git a/src/Benchmarks/Data/Fortune.cs b/src/Benchmarks/Data/Fortune.cs index 475c8fd73..48cd22dad 100644 --- a/src/Benchmarks/Data/Fortune.cs +++ b/src/Benchmarks/Data/Fortune.cs @@ -23,15 +23,9 @@ public class Fortune : IComparable, IComparable [IgnoreDataMember] [Required] public string Message { get; set; } - - public int CompareTo(object obj) - { - return CompareTo((Fortune)obj); - } - public int CompareTo(Fortune other) - { - return String.CompareOrdinal(Message, other.Message); - } + public int CompareTo(object obj) => CompareTo((Fortune)obj); + + public int CompareTo(Fortune other) => String.CompareOrdinal(Message, other.Message); } } diff --git a/src/Benchmarks/Data/Random.cs b/src/Benchmarks/Data/Random.cs index 569b49a43..9a7bb460a 100644 --- a/src/Benchmarks/Data/Random.cs +++ b/src/Benchmarks/Data/Random.cs @@ -24,9 +24,6 @@ private static Random CreateRandom() return _random; } - public int Next(int minValue, int maxValue) - { - return Random.Next(minValue, maxValue); - } + public int Next(int minValue, int maxValue) => Random.Next(minValue, maxValue); } } diff --git a/src/Benchmarks/Data/RawDb.cs b/src/Benchmarks/Data/RawDb.cs index 7f924558a..7b0a6c340 100644 --- a/src/Benchmarks/Data/RawDb.cs +++ b/src/Benchmarks/Data/RawDb.cs @@ -11,20 +11,13 @@ namespace Benchmarks.Data { - public class RawDb : IDb + public class RawDb(IRandom random, DbProviderFactory dbProviderFactory, IOptions appSettings) : IDb { private static readonly Comparison WorldSortComparison = (a, b) => a.Id.CompareTo(b.Id); - private readonly IRandom _random; - private readonly DbProviderFactory _dbProviderFactory; - private readonly string _connectionString; - - public RawDb(IRandom random, DbProviderFactory dbProviderFactory, IOptions appSettings) - { - _random = random; - _dbProviderFactory = dbProviderFactory; - _connectionString = appSettings.Value.ConnectionString; - } + private readonly IRandom _random = random; + private readonly DbProviderFactory _dbProviderFactory = dbProviderFactory; + private readonly string _connectionString = appSettings.Value.ConnectionString; public async Task LoadSingleQueryRow() { diff --git a/src/Benchmarks/Middleware/AutoShutdownMiddleware.cs b/src/Benchmarks/Middleware/AutoShutdownMiddleware.cs index f8a7f9846..74fa3ee40 100644 --- a/src/Benchmarks/Middleware/AutoShutdownMiddleware.cs +++ b/src/Benchmarks/Middleware/AutoShutdownMiddleware.cs @@ -13,17 +13,12 @@ namespace Benchmarks.Middleware { - public class AutoShutdownMiddleware + public class AutoShutdownMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString("/shutdown"); - private readonly RequestDelegate _next; + private readonly RequestDelegate _next = next; - public AutoShutdownMiddleware(RequestDelegate next) - { - _next = next; - } - public async Task Invoke(HttpContext httpContext) { if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) @@ -42,9 +37,7 @@ public async Task Invoke(HttpContext httpContext) public static class AutoShutdownMiddlewareExtensions { - public static IApplicationBuilder UseAutoShutdown(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseAutoShutdown(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/CopyToAsyncMiddleware.cs b/src/Benchmarks/Middleware/CopyToAsyncMiddleware.cs index 9681d8e84..d18518c24 100644 --- a/src/Benchmarks/Middleware/CopyToAsyncMiddleware.cs +++ b/src/Benchmarks/Middleware/CopyToAsyncMiddleware.cs @@ -10,16 +10,11 @@ namespace Benchmarks.Middleware { - public class CopyToAsyncMiddleware + public class CopyToAsyncMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.CopyToAsync)); - private readonly RequestDelegate _next; - - public CopyToAsyncMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -47,9 +42,7 @@ public async Task Invoke(HttpContext httpContext) public static class CopyToAsyncMiddlewareMiddlewareExtensions { - public static IApplicationBuilder UseCopyToAsync(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseCopyToAsync(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs b/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs index d745a975d..dc0fb4cdf 100644 --- a/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesDapperMiddleware.cs @@ -12,18 +12,12 @@ namespace Benchmarks.Middleware { - public class FortunesDapperMiddleware + public class FortunesDapperMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbFortunesDapper)); - private readonly RequestDelegate _next; - private readonly HtmlEncoder _htmlEncoder; - - public FortunesDapperMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) - { - _next = next; - _htmlEncoder = htmlEncoder; - } + private readonly RequestDelegate _next = next; + private readonly HtmlEncoder _htmlEncoder = htmlEncoder; public async Task Invoke(HttpContext httpContext) { @@ -43,9 +37,7 @@ public async Task Invoke(HttpContext httpContext) public static class FortunesDapperMiddlewareExtensions { - public static IApplicationBuilder UseFortunesDapper(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseFortunesDapper(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/FortunesEfMiddleware.cs b/src/Benchmarks/Middleware/FortunesEfMiddleware.cs index d7ae26da9..f6dc82258 100644 --- a/src/Benchmarks/Middleware/FortunesEfMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesEfMiddleware.cs @@ -12,18 +12,12 @@ namespace Benchmarks.Middleware { - public class FortunesEfMiddleware + public class FortunesEfMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbFortunesEf)); - private readonly RequestDelegate _next; - private readonly HtmlEncoder _htmlEncoder; - - public FortunesEfMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) - { - _next = next; - _htmlEncoder = htmlEncoder; - } + private readonly RequestDelegate _next = next; + private readonly HtmlEncoder _htmlEncoder = htmlEncoder; public async Task Invoke(HttpContext httpContext) { @@ -43,9 +37,7 @@ public async Task Invoke(HttpContext httpContext) public static class FortunesEfMiddlewareExtensions { - public static IApplicationBuilder UseFortunesEf(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseFortunesEf(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } \ No newline at end of file diff --git a/src/Benchmarks/Middleware/FortunesRawMiddleware.cs b/src/Benchmarks/Middleware/FortunesRawMiddleware.cs index 096c1673c..85bb0f793 100644 --- a/src/Benchmarks/Middleware/FortunesRawMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesRawMiddleware.cs @@ -12,18 +12,12 @@ namespace Benchmarks.Middleware { - public class FortunesRawMiddleware + public class FortunesRawMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbFortunesRaw)); - private readonly RequestDelegate _next; - private readonly HtmlEncoder _htmlEncoder; - - public FortunesRawMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) - { - _next = next; - _htmlEncoder = htmlEncoder; - } + private readonly RequestDelegate _next = next; + private readonly HtmlEncoder _htmlEncoder = htmlEncoder; public async Task Invoke(HttpContext httpContext) { @@ -43,9 +37,7 @@ public async Task Invoke(HttpContext httpContext) public static class FortunesRawMiddlewareExtensions { - public static IApplicationBuilder UseFortunesRaw(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseFortunesRaw(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs b/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs index a88540203..aa3e248c0 100644 --- a/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs +++ b/src/Benchmarks/Middleware/FortunesRawSyncMiddleware.cs @@ -12,18 +12,12 @@ namespace Benchmarks.Middleware { - public class FortunesRawSyncMiddleware + public class FortunesRawSyncMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbFortunesRawSync)); - private readonly RequestDelegate _next; - private readonly HtmlEncoder _htmlEncoder; - - public FortunesRawSyncMiddleware(RequestDelegate next, HtmlEncoder htmlEncoder) - { - _next = next; - _htmlEncoder = htmlEncoder; - } + private readonly RequestDelegate _next = next; + private readonly HtmlEncoder _htmlEncoder = htmlEncoder; public Task Invoke(HttpContext httpContext) { @@ -41,9 +35,7 @@ public Task Invoke(HttpContext httpContext) public static class FortunesRawMiddlewareSyncExtensions { - public static IApplicationBuilder UseFortunesRawSync(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseFortunesRawSync(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/JsonMiddleware.cs b/src/Benchmarks/Middleware/JsonMiddleware.cs index 63cb5e455..29debbebe 100644 --- a/src/Benchmarks/Middleware/JsonMiddleware.cs +++ b/src/Benchmarks/Middleware/JsonMiddleware.cs @@ -16,16 +16,11 @@ namespace Benchmarks.Middleware { - public class JsonMiddleware + public class JsonMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.Json)); private const int _bufferSize = 27; - private readonly RequestDelegate _next; - - public JsonMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public Task Invoke(HttpContext httpContext) { diff --git a/src/Benchmarks/Middleware/MemoryCachePlaintextMiddleware.cs b/src/Benchmarks/Middleware/MemoryCachePlaintextMiddleware.cs index 62245d40e..082fe4fdc 100644 --- a/src/Benchmarks/Middleware/MemoryCachePlaintextMiddleware.cs +++ b/src/Benchmarks/Middleware/MemoryCachePlaintextMiddleware.cs @@ -11,19 +11,13 @@ namespace Benchmarks.Middleware { - public class MemoryCachePlaintextMiddleware + public class MemoryCachePlaintextMiddleware(RequestDelegate next, IMemoryCache memoryCache) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.MemoryCachePlaintext)); private static readonly object _key = new object(); - private readonly RequestDelegate _next; - private readonly IMemoryCache _memoryCache; - - public MemoryCachePlaintextMiddleware(RequestDelegate next, IMemoryCache memoryCache) - { - _next = next; - _memoryCache = memoryCache; - } + private readonly RequestDelegate _next = next; + private readonly IMemoryCache _memoryCache = memoryCache; public Task Invoke(HttpContext httpContext) { @@ -54,9 +48,7 @@ public Task Invoke(HttpContext httpContext) public static class MemoryCachePlaintextMiddlewareExtensions { - public static IApplicationBuilder UseMemoryCachePlaintext(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMemoryCachePlaintext(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/MemoryCachePlaintextSetRemoveMiddleware.cs b/src/Benchmarks/Middleware/MemoryCachePlaintextSetRemoveMiddleware.cs index d9c2adbc9..7f2f1b0de 100644 --- a/src/Benchmarks/Middleware/MemoryCachePlaintextSetRemoveMiddleware.cs +++ b/src/Benchmarks/Middleware/MemoryCachePlaintextSetRemoveMiddleware.cs @@ -11,20 +11,14 @@ namespace Benchmarks.Middleware { - public class MemoryCachePlaintextSetRemoveMiddleware + public class MemoryCachePlaintextSetRemoveMiddleware(RequestDelegate next, IMemoryCache memoryCache) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.MemoryCachePlaintext)); private static readonly object _key = new object(); private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!"); - private readonly RequestDelegate _next; - private readonly IMemoryCache _memoryCache; - - public MemoryCachePlaintextSetRemoveMiddleware(RequestDelegate next, IMemoryCache memoryCache) - { - _next = next; - _memoryCache = memoryCache; - } + private readonly RequestDelegate _next = next; + private readonly IMemoryCache _memoryCache = memoryCache; public Task Invoke(HttpContext httpContext) { @@ -48,9 +42,7 @@ public Task Invoke(HttpContext httpContext) public static class MemoryCachePlaintextSetRemoveMiddlewareExtensions { - public static IApplicationBuilder UseMemoryCachePlaintextSetRemove(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMemoryCachePlaintextSetRemove(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/MultipleQueriesDapperMiddleware.cs b/src/Benchmarks/Middleware/MultipleQueriesDapperMiddleware.cs index 19701c25f..53cd6b1d1 100644 --- a/src/Benchmarks/Middleware/MultipleQueriesDapperMiddleware.cs +++ b/src/Benchmarks/Middleware/MultipleQueriesDapperMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class MultipleQueriesDapperMiddleware + public class MultipleQueriesDapperMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiQueryDapper)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class MultipleQueriesDapperMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public MultipleQueriesDapperMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -54,9 +49,7 @@ public async Task Invoke(HttpContext httpContext) public static class MultipleQueriesDapperMiddlewareExtensions { - public static IApplicationBuilder UseMultipleQueriesDapper(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMultipleQueriesDapper(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/MultipleQueriesEfMiddleware.cs b/src/Benchmarks/Middleware/MultipleQueriesEfMiddleware.cs index f677b2028..35c220488 100644 --- a/src/Benchmarks/Middleware/MultipleQueriesEfMiddleware.cs +++ b/src/Benchmarks/Middleware/MultipleQueriesEfMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class MultipleQueriesEfMiddleware + public class MultipleQueriesEfMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiQueryEf)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class MultipleQueriesEfMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public MultipleQueriesEfMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -54,9 +49,7 @@ public async Task Invoke(HttpContext httpContext) public static class MultipleQueriesEfMiddlewareExtensions { - public static IApplicationBuilder UseMultipleQueriesEf(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMultipleQueriesEf(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } \ No newline at end of file diff --git a/src/Benchmarks/Middleware/MultipleQueriesRawMiddleware.cs b/src/Benchmarks/Middleware/MultipleQueriesRawMiddleware.cs index fc196d838..99c700546 100644 --- a/src/Benchmarks/Middleware/MultipleQueriesRawMiddleware.cs +++ b/src/Benchmarks/Middleware/MultipleQueriesRawMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class MultipleQueriesRawMiddleware + public class MultipleQueriesRawMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiQueryRaw)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class MultipleQueriesRawMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public MultipleQueriesRawMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -54,9 +49,7 @@ public async Task Invoke(HttpContext httpContext) public static class MultipleQueriesRawMiddlewareExtensions { - public static IApplicationBuilder UseMultipleQueriesRaw(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMultipleQueriesRaw(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/MultipleUpdatesDapperMiddleware.cs b/src/Benchmarks/Middleware/MultipleUpdatesDapperMiddleware.cs index d30bbec61..b1c0a0797 100644 --- a/src/Benchmarks/Middleware/MultipleUpdatesDapperMiddleware.cs +++ b/src/Benchmarks/Middleware/MultipleUpdatesDapperMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class MultipleUpdatesDapperMiddleware + public class MultipleUpdatesDapperMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiUpdateDapper)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class MultipleUpdatesDapperMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public MultipleUpdatesDapperMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -54,9 +49,7 @@ public async Task Invoke(HttpContext httpContext) public static class MultipleUpdatesDapperMiddlewareExtensions { - public static IApplicationBuilder UseMultipleUpdatesDapper(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMultipleUpdatesDapper(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/MultipleUpdatesEfMiddleware.cs b/src/Benchmarks/Middleware/MultipleUpdatesEfMiddleware.cs index c60b7a493..ae1901dce 100644 --- a/src/Benchmarks/Middleware/MultipleUpdatesEfMiddleware.cs +++ b/src/Benchmarks/Middleware/MultipleUpdatesEfMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class MultipleUpdatesEfMiddleware + public class MultipleUpdatesEfMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiUpdateEf)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class MultipleUpdatesEfMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public MultipleUpdatesEfMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -54,9 +49,6 @@ public async Task Invoke(HttpContext httpContext) public static class MultipleUpdatesEfMiddlewareExtensions { - public static IApplicationBuilder UseMultipleUpdatesEf(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMultipleUpdatesEf(this IApplicationBuilder builder) => builder.UseMiddleware(); } } \ No newline at end of file diff --git a/src/Benchmarks/Middleware/MultipleUpdatesRawMiddleware.cs b/src/Benchmarks/Middleware/MultipleUpdatesRawMiddleware.cs index e8caada72..b4937358a 100644 --- a/src/Benchmarks/Middleware/MultipleUpdatesRawMiddleware.cs +++ b/src/Benchmarks/Middleware/MultipleUpdatesRawMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class MultipleUpdatesRawMiddleware + public class MultipleUpdatesRawMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiUpdateRaw)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class MultipleUpdatesRawMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public MultipleUpdatesRawMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -54,9 +49,7 @@ public async Task Invoke(HttpContext httpContext) public static class MultipleUpdatesRawMiddlewareExtensions { - public static IApplicationBuilder UseMultipleUpdatesRaw(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseMultipleUpdatesRaw(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/PlaintextMiddleware.cs b/src/Benchmarks/Middleware/PlaintextMiddleware.cs index 378315f14..a258fb0c8 100644 --- a/src/Benchmarks/Middleware/PlaintextMiddleware.cs +++ b/src/Benchmarks/Middleware/PlaintextMiddleware.cs @@ -10,17 +10,12 @@ namespace Benchmarks.Middleware { - public class PlaintextMiddleware + public class PlaintextMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.Plaintext)); private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!"); - private readonly RequestDelegate _next; - - public PlaintextMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public Task Invoke(HttpContext httpContext) { @@ -50,9 +45,7 @@ public static Task WriteResponse(HttpResponse response) public static class PlaintextMiddlewareExtensions { - public static IApplicationBuilder UsePlainText(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UsePlainText(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/ResponseCachingPlaintextCachedMiddleware.cs b/src/Benchmarks/Middleware/ResponseCachingPlaintextCachedMiddleware.cs index 387815bcf..a017ae418 100644 --- a/src/Benchmarks/Middleware/ResponseCachingPlaintextCachedMiddleware.cs +++ b/src/Benchmarks/Middleware/ResponseCachingPlaintextCachedMiddleware.cs @@ -9,16 +9,11 @@ namespace Benchmarks.Middleware { - public class ResponseCachingPlaintextCachedMiddleware + public class ResponseCachingPlaintextCachedMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.ResponseCachingPlaintextCached)); - private readonly RequestDelegate _next; - - public ResponseCachingPlaintextCachedMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public Task Invoke(HttpContext httpContext) { @@ -34,9 +29,7 @@ public Task Invoke(HttpContext httpContext) public static class ResponseCachingPlaintextCachedMiddlewareExtensions { - public static IApplicationBuilder UseResponseCachingPlaintextCached(this IApplicationBuilder builder) - { - return builder.UseResponseCaching().UseMiddleware(); - } + public static IApplicationBuilder UseResponseCachingPlaintextCached(this IApplicationBuilder builder) => + builder.UseResponseCaching().UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/ResponseCachingPlaintextRequestNoCacheMiddleware.cs b/src/Benchmarks/Middleware/ResponseCachingPlaintextRequestNoCacheMiddleware.cs index 48616cbbe..e885ae9b8 100644 --- a/src/Benchmarks/Middleware/ResponseCachingPlaintextRequestNoCacheMiddleware.cs +++ b/src/Benchmarks/Middleware/ResponseCachingPlaintextRequestNoCacheMiddleware.cs @@ -9,16 +9,11 @@ namespace Benchmarks.Middleware { - public class ResponseCachingPlaintextRequestNoCacheMiddleware + public class ResponseCachingPlaintextRequestNoCacheMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.ResponseCachingPlaintextRequestNoCache)); - private readonly RequestDelegate _next; - - public ResponseCachingPlaintextRequestNoCacheMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public Task Invoke(HttpContext httpContext) { @@ -34,9 +29,7 @@ public Task Invoke(HttpContext httpContext) public static class ResponseCachingPlaintextRequestNoCacheMiddlewareExtensions { - public static IApplicationBuilder UseResponseCachingPlaintextRequestNoCache(this IApplicationBuilder builder) - { - return builder.UseResponseCaching().UseMiddleware(); - } + public static IApplicationBuilder UseResponseCachingPlaintextRequestNoCache(this IApplicationBuilder builder) => + builder.UseResponseCaching().UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/ResponseCachingPlaintextResponseNoCacheMiddleware.cs b/src/Benchmarks/Middleware/ResponseCachingPlaintextResponseNoCacheMiddleware.cs index b2a71ff35..00a8783fa 100644 --- a/src/Benchmarks/Middleware/ResponseCachingPlaintextResponseNoCacheMiddleware.cs +++ b/src/Benchmarks/Middleware/ResponseCachingPlaintextResponseNoCacheMiddleware.cs @@ -9,16 +9,11 @@ namespace Benchmarks.Middleware { - public class ResponseCachingPlaintextResponseNoCacheMiddleware + public class ResponseCachingPlaintextResponseNoCacheMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.ResponseCachingPlaintextResponseNoCache)); - private readonly RequestDelegate _next; - - public ResponseCachingPlaintextResponseNoCacheMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public Task Invoke(HttpContext httpContext) { @@ -33,9 +28,7 @@ public Task Invoke(HttpContext httpContext) public static class ResponseCachingPlaintextResponseNoCacheMiddlewareExtensions { - public static IApplicationBuilder UseResponseCachingPlaintextResponseNoCache(this IApplicationBuilder builder) - { - return builder.UseResponseCaching().UseMiddleware(); - } + public static IApplicationBuilder UseResponseCachingPlaintextResponseNoCache(this IApplicationBuilder builder) => + builder.UseResponseCaching().UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/ResponseCachingPlaintextVaryByCachedMiddleware.cs b/src/Benchmarks/Middleware/ResponseCachingPlaintextVaryByCachedMiddleware.cs index 67a23946d..16c609d2c 100644 --- a/src/Benchmarks/Middleware/ResponseCachingPlaintextVaryByCachedMiddleware.cs +++ b/src/Benchmarks/Middleware/ResponseCachingPlaintextVaryByCachedMiddleware.cs @@ -9,16 +9,11 @@ namespace Benchmarks.Middleware { - public class ResponseCachingPlaintextVaryByCachedMiddleware + public class ResponseCachingPlaintextVaryByCachedMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.ResponseCachingPlaintextVaryByCached)); - private readonly RequestDelegate _next; - - public ResponseCachingPlaintextVaryByCachedMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public Task Invoke(HttpContext httpContext) { @@ -35,9 +30,7 @@ public Task Invoke(HttpContext httpContext) public static class ResponseCachingPlaintextVaryByCachedMiddlewareExtensions { - public static IApplicationBuilder UseResponseCachingPlaintextVaryByCached(this IApplicationBuilder builder) - { - return builder.UseResponseCaching().UseMiddleware(); - } + public static IApplicationBuilder UseResponseCachingPlaintextVaryByCached(this IApplicationBuilder builder) => + builder.UseResponseCaching().UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/SingleQueryDapperMiddleware.cs b/src/Benchmarks/Middleware/SingleQueryDapperMiddleware.cs index 525d1fd4e..461ca5be9 100644 --- a/src/Benchmarks/Middleware/SingleQueryDapperMiddleware.cs +++ b/src/Benchmarks/Middleware/SingleQueryDapperMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class SingleQueryDapperMiddleware + public class SingleQueryDapperMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbSingleQueryDapper)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class SingleQueryDapperMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public SingleQueryDapperMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -52,9 +47,7 @@ public async Task Invoke(HttpContext httpContext) public static class SingleQueryDapperMiddlewareExtensions { - public static IApplicationBuilder UseSingleQueryDapper(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseSingleQueryDapper(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } diff --git a/src/Benchmarks/Middleware/SingleQueryEfMiddleware.cs b/src/Benchmarks/Middleware/SingleQueryEfMiddleware.cs index 76409bcb3..7b00b2f10 100644 --- a/src/Benchmarks/Middleware/SingleQueryEfMiddleware.cs +++ b/src/Benchmarks/Middleware/SingleQueryEfMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class SingleQueryEfMiddleware + public class SingleQueryEfMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbSingleQueryEf)); private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions @@ -21,12 +21,7 @@ public class SingleQueryEfMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public SingleQueryEfMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -51,9 +46,7 @@ public async Task Invoke(HttpContext httpContext) public static class SingleQueryEfMiddlewareExtensions { - public static IApplicationBuilder UseSingleQueryEf(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseSingleQueryEf(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } \ No newline at end of file diff --git a/src/Benchmarks/Middleware/SingleQueryRawMiddleware.cs b/src/Benchmarks/Middleware/SingleQueryRawMiddleware.cs index 88a9ff753..b790fcb27 100644 --- a/src/Benchmarks/Middleware/SingleQueryRawMiddleware.cs +++ b/src/Benchmarks/Middleware/SingleQueryRawMiddleware.cs @@ -13,7 +13,7 @@ namespace Benchmarks.Middleware { - public class SingleQueryRawMiddleware + public class SingleQueryRawMiddleware(RequestDelegate next) { private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbSingleQueryRaw)); @@ -22,12 +22,7 @@ public class SingleQueryRawMiddleware PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; - private readonly RequestDelegate _next; - - public SingleQueryRawMiddleware(RequestDelegate next) - { - _next = next; - } + private readonly RequestDelegate _next = next; public async Task Invoke(HttpContext httpContext) { @@ -53,9 +48,7 @@ public async Task Invoke(HttpContext httpContext) public static class SingleQueryRawMiddlewareExtensions { - public static IApplicationBuilder UseSingleQueryRaw(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } + public static IApplicationBuilder UseSingleQueryRaw(this IApplicationBuilder builder) => + builder.UseMiddleware(); } } From c86fb75812e02d8a7884ca3333998c5bfbdb054b Mon Sep 17 00:00:00 2001 From: Khanbala Rashidov <50279392+KhanbalaRashidov@users.noreply.github.com> Date: Wed, 17 Jul 2024 20:40:26 +0400 Subject: [PATCH 2/2] Update Grpc project --- .../Grpc/BasicGrpc/Services/TodoService.cs | 12 ++++-------- .../Server/Services/BenchmarkService.cs | 16 ++++------------ .../Grpc/GrpcHttpApiServer/Server/Startup.cs | 5 +---- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/BenchmarksApps/Grpc/BasicGrpc/Services/TodoService.cs b/src/BenchmarksApps/Grpc/BasicGrpc/Services/TodoService.cs index 5f5affed0..3e465f8e6 100644 --- a/src/BenchmarksApps/Grpc/BasicGrpc/Services/TodoService.cs +++ b/src/BenchmarksApps/Grpc/BasicGrpc/Services/TodoService.cs @@ -23,16 +23,12 @@ static TodoServiceImpl() AllTodosResponse.AllTodos.AddRange(AllTodos); } - public override Task GetAllTodos(GetAllTodosRequest request, ServerCallContext context) - { - return Task.FromResult(AllTodosResponse); - } + public override Task GetAllTodos(GetAllTodosRequest request, ServerCallContext context) => + Task.FromResult(AllTodosResponse); - public override Task GetTodo(GetTodoRequest request, ServerCallContext context) - { - return Task.FromResult(new GetTodoResponse + public override Task GetTodo(GetTodoRequest request, ServerCallContext context) => + Task.FromResult(new GetTodoResponse { Todo = AllTodos.FirstOrDefault(a => a.Id == request.Id) }); - } } \ No newline at end of file diff --git a/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Services/BenchmarkService.cs b/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Services/BenchmarkService.cs index 093f00ce7..d74c6c47c 100644 --- a/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Services/BenchmarkService.cs +++ b/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Services/BenchmarkService.cs @@ -38,19 +38,11 @@ static BenchmarkService() _entries.Entries.AddRange(entries); } - public override Task Json(Empty request, ServerCallContext context) - { - return Task.FromResult(new HelloReply { Message = "Hello, World!" }); - } + public override Task Json(Empty request, ServerCallContext context) => + Task.FromResult(new HelloReply { Message = "Hello, World!" }); - public override Task Json2k(Empty request, ServerCallContext context) - { - return Task.FromResult(_entries); - } + public override Task Json2k(Empty request, ServerCallContext context) => Task.FromResult(_entries); - public override Task JsonInput(EntriesCollection request, ServerCallContext context) - { - return Task.FromResult(new Empty()); - } + public override Task JsonInput(EntriesCollection request, ServerCallContext context) => Task.FromResult(new Empty()); } } diff --git a/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Startup.cs b/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Startup.cs index 4d08c6752..17dbed4ee 100644 --- a/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Startup.cs +++ b/src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Startup.cs @@ -11,10 +11,7 @@ namespace Server { public class Startup { - public void ConfigureServices(IServiceCollection services) - { - services.AddGrpcHttpApi(); - } + public void ConfigureServices(IServiceCollection services) => services.AddGrpcHttpApi(); public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime) {