From 5cb38f9791343bd707358b0a4cdbac8433d2ce76 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:43:52 +0000 Subject: [PATCH 1/7] chore(deps): bump ClickHouse.Client from 7.2.2 to 7.4.1 Bumps [ClickHouse.Client](https://github.com/DarkWanderer/ClickHouse.Client) from 7.2.2 to 7.4.1. - [Release notes](https://github.com/DarkWanderer/ClickHouse.Client/releases) - [Commits](https://github.com/DarkWanderer/ClickHouse.Client/compare/7.2.2...7.4.1) --- updated-dependencies: - dependency-name: ClickHouse.Client dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- ...ogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj b/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj index 920288d..6cf13b9 100644 --- a/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj +++ b/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj @@ -13,7 +13,7 @@ - + From 31a3783775f8ea88e7ac3cba57876ad8804f1213 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:44:40 +0000 Subject: [PATCH 2/7] chore(deps): bump xunit from 2.7.0 to 2.8.0 Bumps [xunit](https://github.com/xunit/xunit) from 2.7.0 to 2.8.0. - [Commits](https://github.com/xunit/xunit/compare/2.7.0...2.8.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Cnblogs.Architecture.IntegrationTests.csproj | 2 +- .../Cnblogs.Architecture.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj b/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj index 12e8a73..535933c 100644 --- a/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj +++ b/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj @@ -3,7 +3,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj index 5c940e3..30a4ce5 100644 --- a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj +++ b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj @@ -3,7 +3,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 42d18d5c91efcd5b72b0c56c30fa155bd8725479 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:45:03 +0000 Subject: [PATCH 3/7] chore(deps): bump Dapr.AspNetCore from 1.13.0 to 1.13.1 Bumps [Dapr.AspNetCore](https://github.com/dapr/dotnet-sdk) from 1.13.0 to 1.13.1. - [Release notes](https://github.com/dapr/dotnet-sdk/releases) - [Commits](https://github.com/dapr/dotnet-sdk/compare/v1.13.0...v1.13.1) --- updated-dependencies: - dependency-name: Dapr.AspNetCore dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.Architecture.Ddd.EventBus.Dapr.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cnblogs.Architecture.Ddd.EventBus.Dapr/Cnblogs.Architecture.Ddd.EventBus.Dapr.csproj b/src/Cnblogs.Architecture.Ddd.EventBus.Dapr/Cnblogs.Architecture.Ddd.EventBus.Dapr.csproj index f8b54e6..c72b727 100644 --- a/src/Cnblogs.Architecture.Ddd.EventBus.Dapr/Cnblogs.Architecture.Ddd.EventBus.Dapr.csproj +++ b/src/Cnblogs.Architecture.Ddd.EventBus.Dapr/Cnblogs.Architecture.Ddd.EventBus.Dapr.csproj @@ -9,6 +9,6 @@ - + From 2cb18346e1508f5e27cb9c691eeaffcf0b6d052d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:46:15 +0000 Subject: [PATCH 4/7] chore(deps): bump Microsoft.EntityFrameworkCore.InMemory Bumps [Microsoft.EntityFrameworkCore.InMemory](https://github.com/dotnet/efcore) from 8.0.3 to 8.0.4. - [Release notes](https://github.com/dotnet/efcore/releases) - [Commits](https://github.com/dotnet/efcore/compare/v8.0.3...v8.0.4) --- updated-dependencies: - dependency-name: Microsoft.EntityFrameworkCore.InMemory dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.Architecture.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj index 5c940e3..daf56a5 100644 --- a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj +++ b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj @@ -1,7 +1,7 @@ - + From 621236dc5870215835971114eb7bb2a788d0c8ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:51:16 +0000 Subject: [PATCH 5/7] chore(deps): bump xunit.runner.visualstudio from 2.5.7 to 2.8.0 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.5.7 to 2.8.0. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/compare/2.5.7...2.8.0) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Cnblogs.Architecture.IntegrationTests.csproj | 2 +- .../Cnblogs.Architecture.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj b/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj index 535933c..11f45a0 100644 --- a/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj +++ b/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj @@ -4,7 +4,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj index 30a4ce5..89fc8c7 100644 --- a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj +++ b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj @@ -4,7 +4,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 095f5327757aa4d7e090da428f609cc43b85629c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Thu, 16 May 2024 16:09:51 +0800 Subject: [PATCH 6/7] feat: support async query&command creation on minimal api mapping --- .../CqrsRouteMapper.cs | 75 ++++++++++++++----- ....Architecture.Ddd.Cqrs.ServiceAgent.csproj | 2 +- ...dd.Infrastructure.Dapper.Clickhouse.csproj | 2 +- ....Ddd.Infrastructure.EntityFramework.csproj | 2 +- ...Architecture.IntegrationTestProject.csproj | 2 +- .../Program.cs | 15 +++- ...blogs.Architecture.IntegrationTests.csproj | 2 +- .../Cnblogs.Architecture.UnitTests.csproj | 2 +- 8 files changed, 74 insertions(+), 28 deletions(-) diff --git a/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/CqrsRouteMapper.cs b/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/CqrsRouteMapper.cs index 5b4ad3a..ab233a3 100644 --- a/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/CqrsRouteMapper.cs +++ b/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/CqrsRouteMapper.cs @@ -21,11 +21,29 @@ public static class CqrsRouteMapper private static readonly string[] GetAndHeadMethods = { "GET", "HEAD" }; - private static readonly List PostCommandPrefixes = new() { "Create", "Add", "New" }; + private static readonly List PostCommandPrefixes = new() + { + "Create", + "Add", + "New" + }; - private static readonly List PutCommandPrefixes = new() { "Update", "Modify", "Replace", "Alter" }; + private static readonly List PutCommandPrefixes = new() + { + "Update", + "Modify", + "Replace", + "Alter" + }; - private static readonly List DeleteCommandPrefixes = new() { "Delete", "Remove", "Clean", "Clear", "Purge" }; + private static readonly List DeleteCommandPrefixes = new() + { + "Delete", + "Remove", + "Clean", + "Clear", + "Purge" + }; /// /// Map a query API, using GET method. would been constructed from route and query string. @@ -96,14 +114,7 @@ public static IEndpointConventionBuilder MapQuery( string nullRouteParameterPattern = "-", bool enableHead = false) { - var isQuery = handler.Method.ReturnType.GetInterfaces().Where(x => x.IsGenericType) - .Any(x => QueryTypes.Contains(x.GetGenericTypeDefinition())); - if (isQuery == false) - { - throw new ArgumentException( - "delegate does not return a query, please make sure it returns object that implement IQuery<> or IListQuery<> or interface that inherit from them"); - } - + var returnType = EnsureReturnTypeIsQuery(handler); if (mapNullableRouteParameters is MapNullableRouteParameter.Disable) { return MapRoutes(route); @@ -118,7 +129,7 @@ public static IEndpointConventionBuilder MapQuery( var parsedRoute = RoutePatternFactory.Parse(route); var context = new NullabilityInfoContext(); - var nullableRouteProperties = handler.Method.ReturnType.GetProperties() + var nullableRouteProperties = returnType.GetProperties() .Where( p => p.GetMethod != null && p.SetMethod != null @@ -209,8 +220,7 @@ public static IEndpointConventionBuilder MapCommand( [StringSyntax("Route")] string route, Delegate handler) { - EnsureDelegateReturnTypeIsCommand(handler); - var commandTypeName = handler.Method.ReturnType.Name; + var commandTypeName = EnsureReturnTypeIsCommand(handler).Name; if (PostCommandPrefixes.Any(x => commandTypeName.StartsWith(x))) { return app.MapPostCommand(route, handler); @@ -255,7 +265,7 @@ public static IEndpointConventionBuilder MapPostCommand( [StringSyntax("Route")] string route, Delegate handler) { - EnsureDelegateReturnTypeIsCommand(handler); + EnsureReturnTypeIsCommand(handler); return app.MapPost(route, handler).AddEndpointFilter(); } @@ -285,7 +295,7 @@ public static IEndpointConventionBuilder MapPutCommand( [StringSyntax("Route")] string route, Delegate handler) { - EnsureDelegateReturnTypeIsCommand(handler); + EnsureReturnTypeIsCommand(handler); return app.MapPut(route, handler).AddEndpointFilter(); } @@ -315,7 +325,7 @@ public static IEndpointConventionBuilder MapDeleteCommand( [StringSyntax("Route")] string route, Delegate handler) { - EnsureDelegateReturnTypeIsCommand(handler); + EnsureReturnTypeIsCommand(handler); return app.MapDelete(route, handler).AddEndpointFilter(); } @@ -385,15 +395,42 @@ public static IEndpointRouteBuilder StopMappingPrefixToDelete(this IEndpointRout return app; } - private static void EnsureDelegateReturnTypeIsCommand(Delegate handler) + private static Type EnsureReturnTypeIsCommand(Delegate handler) { - var isCommand = handler.Method.ReturnType.GetInterfaces().Where(x => x.IsGenericType) + var returnType = handler.Method.ReturnType; + if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>)) + { + returnType = returnType.GenericTypeArguments.First(); + } + + var isCommand = returnType.GetInterfaces().Where(x => x.IsGenericType) .Any(x => CommandTypes.Contains(x.GetGenericTypeDefinition())); if (isCommand == false) { throw new ArgumentException( "handler does not return command, check if delegate returns type that implements ICommand<> or ICommand<,>"); } + + return returnType; + } + + private static Type EnsureReturnTypeIsQuery(Delegate handler) + { + var returnType = handler.Method.ReturnType; + if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>)) + { + returnType = returnType.GenericTypeArguments.First(); + } + + var isCommand = returnType.GetInterfaces().Where(x => x.IsGenericType) + .Any(x => QueryTypes.Contains(x.GetGenericTypeDefinition())); + if (isCommand == false) + { + throw new ArgumentException( + "handler does not return query, check if delegate returns type that implements IQuery<>"); + } + + return returnType; } private static List GetNotEmptySubsets(ICollection items) diff --git a/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj b/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj index c8a0773..53f1d17 100644 --- a/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj +++ b/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj b/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj index 6cf13b9..c4357b8 100644 --- a/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj +++ b/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj b/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj index f5f841d..47f95bf 100644 --- a/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj +++ b/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj @@ -9,7 +9,7 @@ - + diff --git a/test/Cnblogs.Architecture.IntegrationTestProject/Cnblogs.Architecture.IntegrationTestProject.csproj b/test/Cnblogs.Architecture.IntegrationTestProject/Cnblogs.Architecture.IntegrationTestProject.csproj index 1b9b076..799840f 100644 --- a/test/Cnblogs.Architecture.IntegrationTestProject/Cnblogs.Architecture.IntegrationTestProject.csproj +++ b/test/Cnblogs.Architecture.IntegrationTestProject/Cnblogs.Architecture.IntegrationTestProject.csproj @@ -1,7 +1,7 @@  - + diff --git a/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs b/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs index 3d5f4ed..e62ef74 100644 --- a/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs +++ b/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs @@ -7,6 +7,7 @@ using Cnblogs.Architecture.IntegrationTestProject.Application.Queries; using Cnblogs.Architecture.IntegrationTestProject.Payloads; using Cnblogs.Architecture.TestIntegrationEvents; +using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); @@ -36,10 +37,18 @@ var apis = app.NewVersionedApi(); var v1 = apis.MapGroup("/api/v{version:apiVersion}").HasApiVersion(1); -v1.MapQuery("apps/{appId}/strings/{stringId:int}/value", MapNullableRouteParameter.Enable, enableHead: true); -v1.MapQuery("strings/{id:int}"); +v1.MapQuery( + "apps/{appId}/strings/{stringId:int}/value", + MapNullableRouteParameter.Enable, + enableHead: true); +v1.MapQuery( + "strings/{stringId:int}", + async (int stringId, [FromQuery] bool found) + => await Task.FromResult(new GetStringQuery(StringId: stringId, Found: found))); v1.MapQuery("strings"); -v1.MapCommand("strings", (CreatePayload payload) => new CreateCommand(payload.NeedError, payload.Data)); +v1.MapCommand( + "strings", + (CreatePayload payload) => Task.FromResult(new CreateCommand(payload.NeedError, payload.Data))); v1.MapCommand( "strings/{id:int}", (int id, UpdatePayload payload) => new UpdateCommand(id, payload.NeedValidationError, payload.NeedExecutionError)); diff --git a/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj b/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj index 11f45a0..2b6ad3f 100644 --- a/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj +++ b/test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj @@ -1,7 +1,7 @@ - + diff --git a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj index 6545a31..6db550f 100644 --- a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj +++ b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj @@ -1,7 +1,7 @@ - + From b3078851f53bbfdd1a72d5c801548d4b8bae25f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Thu, 16 May 2024 16:41:44 +0800 Subject: [PATCH 7/7] fix: add default value for query param --- test/Cnblogs.Architecture.IntegrationTestProject/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs b/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs index e62ef74..6c9aa95 100644 --- a/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs +++ b/test/Cnblogs.Architecture.IntegrationTestProject/Program.cs @@ -43,7 +43,7 @@ enableHead: true); v1.MapQuery( "strings/{stringId:int}", - async (int stringId, [FromQuery] bool found) + async (int stringId, [FromQuery] bool found = true) => await Task.FromResult(new GetStringQuery(StringId: stringId, Found: found))); v1.MapQuery("strings"); v1.MapCommand(