From d79022e9610911a9f8cb6e88f57898415067e5a1 Mon Sep 17 00:00:00 2001 From: witskeeper Date: Tue, 19 Nov 2024 09:19:59 +0800 Subject: [PATCH 1/2] use dotnet9 --- Directory.Build.targets | 8 ++++---- global.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index e12c7bf7..0ee85276 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -10,10 +10,10 @@ 8.0.2 - 9.0.0-rc.1.24452.1 - 9.0.0-rc.1.24431.7 - 9.0.0-rc.1.24451.1 - 9.0.0-rc.1 + 9.0.0 + 9.0.0 + 9.0.0 + 9.0.0 9.0.0-preview.1 diff --git a/global.json b/global.json index 529835b4..1fdb64aa 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.100-rc.1.24452.12", + "version": "9.0.100", "allowPrerelease": true, "rollForward": "latestMinor" } From 678ae606f5d1663113390ac77f95cdf2c76efa87 Mon Sep 17 00:00:00 2001 From: witskeeper Date: Tue, 26 Nov 2024 10:19:33 +0800 Subject: [PATCH 2/2] clean code --- Directory.Build.targets | 4 ++-- src/AspNetCore/ServiceCollectionExtension.cs | 9 +++++---- .../NetCorePalInstrumentation.cs | 2 +- .../ServiceCollectionExtensionTests.cs | 2 +- .../PageQueryableExtensionsTests.cs | 6 +++--- .../OrderCreatedntegrationEventHandler.cs | 2 -- test/NetCorePal.Web/NetCorePal.Web.csproj | 1 + 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 0ee85276..2cdf5229 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -13,7 +13,7 @@ 9.0.0 9.0.0 9.0.0 - 9.0.0 + 9.0.1 9.0.0-preview.1 @@ -65,7 +65,7 @@ - + diff --git a/src/AspNetCore/ServiceCollectionExtension.cs b/src/AspNetCore/ServiceCollectionExtension.cs index 32514d1e..72bea183 100644 --- a/src/AspNetCore/ServiceCollectionExtension.cs +++ b/src/AspNetCore/ServiceCollectionExtension.cs @@ -52,21 +52,22 @@ public static MediatRServiceConfiguration AddKnownExceptionValidationBehavior( /// 将所有实现IQuery接口的类注册为查询类,添加到容器中 /// /// - /// + /// /// - public static IServiceCollection AddAllQueries(this IServiceCollection services, params Assembly[] Assemblies) + public static IServiceCollection AddAllQueries(this IServiceCollection services, params Assembly[] assemblies) { - foreach (var assembly in Assemblies) + foreach (var assembly in assemblies) { //从assembly中获取所有实现IQuery接口的类 var queryTypes = assembly.GetTypes().Where(p => - p.IsClass && !p.IsAbstract && p.GetInterfaces().Any(i => i == typeof(IQuery))); + p is { IsClass: true, IsAbstract: false } && Array.Exists(p.GetInterfaces(), i => i == typeof(IQuery))); foreach (var queryType in queryTypes) { //注册为自己 services.AddScoped(queryType, queryType); } } + return services; } diff --git a/src/NetCorePal.OpenTelemetry.Diagnostics/NetCorePalInstrumentation.cs b/src/NetCorePal.OpenTelemetry.Diagnostics/NetCorePalInstrumentation.cs index eeeedd71..fa62e4bf 100644 --- a/src/NetCorePal.OpenTelemetry.Diagnostics/NetCorePalInstrumentation.cs +++ b/src/NetCorePal.OpenTelemetry.Diagnostics/NetCorePalInstrumentation.cs @@ -3,7 +3,7 @@ /// /// NetCorePalInstrumentation /// -public class NetCorePalInstrumentation : IDisposable +public sealed class NetCorePalInstrumentation : IDisposable { private readonly DiagnosticSourceSubscriber? _diagnosticSourceSubscriber; diff --git a/test/NetCorePal.Extensions.AspNetCore.UnitTests/ServiceCollectionExtensionTests.cs b/test/NetCorePal.Extensions.AspNetCore.UnitTests/ServiceCollectionExtensionTests.cs index c554a056..c8304ad4 100644 --- a/test/NetCorePal.Extensions.AspNetCore.UnitTests/ServiceCollectionExtensionTests.cs +++ b/test/NetCorePal.Extensions.AspNetCore.UnitTests/ServiceCollectionExtensionTests.cs @@ -17,7 +17,7 @@ public void AddAllQueriesTests() { var services = new ServiceCollection(); services.AddAllQueries(typeof(ServiceCollectionExtensionTests).Assembly); - Assert.Equal(1, services.Count); + Assert.Single(services); var provider = services.BuildServiceProvider(); var queryHandler = provider.GetRequiredService(); Assert.NotNull(queryHandler); diff --git a/test/NetCorePal.Extensions.Dto.Tests/PageQueryableExtensionsTests.cs b/test/NetCorePal.Extensions.Dto.Tests/PageQueryableExtensionsTests.cs index 63aa112d..fe9f10db 100644 --- a/test/NetCorePal.Extensions.Dto.Tests/PageQueryableExtensionsTests.cs +++ b/test/NetCorePal.Extensions.Dto.Tests/PageQueryableExtensionsTests.cs @@ -14,12 +14,12 @@ public void ToPagedDataTests() Assert.Equal(1, pagedData.Index); pagedData = allStrings.ToPagedData(2, 2, true); - Assert.Equal(1, pagedData.Items.Count()); + Assert.Single(pagedData.Items); Assert.Equal(3, pagedData.Total); Assert.Equal(2, pagedData.Index); pagedData = allStrings.ToPagedData(3, 2, true); - Assert.Equal(0, pagedData.Items.Count()); + Assert.Empty(pagedData.Items); Assert.Equal(3, pagedData.Total); Assert.Equal(3, pagedData.Index); @@ -31,7 +31,7 @@ public void ToPagedDataTests() Assert.Equal(1, pagedData.Index); pagedData = allStrings.ToPagedData(2, 2, false); - Assert.Equal(1, pagedData.Items.Count()); + Assert.Single(pagedData.Items); Assert.Equal(0, pagedData.Total); Assert.Equal(2, pagedData.Index); diff --git a/test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs b/test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs index 291b6fcb..bb16b561 100644 --- a/test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs +++ b/test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs @@ -6,10 +6,8 @@ namespace NetCorePal.Web.Application.IntegrationEventHandlers /// /// /// - /// /// public class OrderCreatedIntegrationEventHandler( - IMediator mediator, ILogger logger) : IIntegrationEventHandler { /// diff --git a/test/NetCorePal.Web/NetCorePal.Web.csproj b/test/NetCorePal.Web/NetCorePal.Web.csproj index 8d38cda2..d29574cc 100644 --- a/test/NetCorePal.Web/NetCorePal.Web.csproj +++ b/test/NetCorePal.Web/NetCorePal.Web.csproj @@ -9,6 +9,7 @@ Linux ..\.. True + CS1591