From 67a5f2f8946ec6333d9ab9cef6b82e458611f829 Mon Sep 17 00:00:00 2001 From: Bernd Dongus Date: Sat, 16 Mar 2024 15:55:51 +0100 Subject: [PATCH] v1.1.1 --- README.md | 4 +- idee5.AspNetCore.TestApi/Program.cs | 9 ++-- idee5.AspNetCore.Tests/ApiIntegrationTests.cs | 1 + .../idee5.AspNetCore.Tests.csproj | 10 ++--- .../ServiceCollectionExtensions.cs | 43 ------------------- idee5.AspNetCore/idee5.AspNetCore.csproj | 8 ++-- 6 files changed, 17 insertions(+), 58 deletions(-) delete mode 100644 idee5.AspNetCore/ServiceCollectionExtensions.cs diff --git a/README.md b/README.md index 9d1e4f7..c699929 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,6 @@ Initial release ## 1.1.0 * Use GetImplementationsWithoutDecorators from idee5.Common * MapRouteDump added -* .NET8 \ No newline at end of file +* .NET8 +## 1.1.1 +* Moved handler registration to idee5.Common.Data \ No newline at end of file diff --git a/idee5.AspNetCore.TestApi/Program.cs b/idee5.AspNetCore.TestApi/Program.cs index e7dfaa6..dee8364 100644 --- a/idee5.AspNetCore.TestApi/Program.cs +++ b/idee5.AspNetCore.TestApi/Program.cs @@ -1,5 +1,7 @@ using idee5.AspNetCore; using idee5.Common; +using idee5.Common.Data; + using System.Reflection; var builder = WebApplication.CreateBuilder(args); @@ -12,10 +14,9 @@ services.RegisterCommandHandlers(); services.AddHttpContextAccessor(); services.AddSingleton(); -services.AddAuthorization(o => { - o.AddPolicy("CommandPolicy", p => p.RequireAssertion(_ => true)); - o.AddPolicy("QueryPolicy", p => p.RequireAssertion(_ => true)); -}); +services.AddAuthorizationBuilder() + .AddPolicy("CommandPolicy", p => p.RequireAssertion(_ => true)) + .AddPolicy("QueryPolicy", p => p.RequireAssertion(_ => true)); var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/idee5.AspNetCore.Tests/ApiIntegrationTests.cs b/idee5.AspNetCore.Tests/ApiIntegrationTests.cs index 749eb3f..d3d08f7 100644 --- a/idee5.AspNetCore.Tests/ApiIntegrationTests.cs +++ b/idee5.AspNetCore.Tests/ApiIntegrationTests.cs @@ -14,6 +14,7 @@ public ApiIntegrationTests(WebApplicationFactory factory) { [Fact] public async Task CanDetectDecorators() { + // TODO: Move test to idee5.Common.Data // Arrange HttpClient client = _factory.CreateClient(); diff --git a/idee5.AspNetCore.Tests/idee5.AspNetCore.Tests.csproj b/idee5.AspNetCore.Tests/idee5.AspNetCore.Tests.csproj index 0fbecd3..9aa37d8 100644 --- a/idee5.AspNetCore.Tests/idee5.AspNetCore.Tests.csproj +++ b/idee5.AspNetCore.Tests/idee5.AspNetCore.Tests.csproj @@ -9,14 +9,14 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/idee5.AspNetCore/ServiceCollectionExtensions.cs b/idee5.AspNetCore/ServiceCollectionExtensions.cs deleted file mode 100644 index 4845456..0000000 --- a/idee5.AspNetCore/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -using idee5.Common; -using Microsoft.Extensions.DependencyInjection; -using System.Reflection; - -namespace idee5.AspNetCore; -/// -/// The service collection extensions. -/// -public static class ServiceCollectionExtensions { - /// - /// Registers the query handlers. - /// - /// The services. - /// The service lifetime. - public static void RegisterQueryHandlers(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { - services.RegisterHandlers(typeof(IQueryHandlerAsync<,>), serviceLifetime); - } - /// - /// Register the command handlers. - /// - /// The services. - /// The service lifetime. - public static void RegisterCommandHandlers(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { - services.RegisterHandlers(typeof(ICommandHandlerAsync<>), serviceLifetime); - } - /// - /// Registers the handlers. Skips validation handlers ("Validat" in their name), as they are . - /// - /// The services. - /// The handler type. E.g. typeof(ICommandHandlerAsync<>) - /// - /// The service lifetime. - public static void RegisterHandlers(this IServiceCollection services, Type handlerType, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) { - IEnumerable implementations = AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(a => a.DefinedTypes.Where(t => !t.IsAbstract && t.IsClass && !t.IsGenericType && t.IsPublic - && t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == handlerType) - && !t.DeclaredConstructors.Any(c => c.GetParameters().Any(p => t.ImplementedInterfaces.Contains(p.ParameterType))))); - foreach (TypeInfo? item in implementations) { - var service = new ServiceDescriptor(item.GetInterfaces().Single(i => i.GetGenericTypeDefinition() == handlerType), item, serviceLifetime); - services.Add(service); - } - } -} diff --git a/idee5.AspNetCore/idee5.AspNetCore.csproj b/idee5.AspNetCore/idee5.AspNetCore.csproj index aae0051..1755cca 100644 --- a/idee5.AspNetCore/idee5.AspNetCore.csproj +++ b/idee5.AspNetCore/idee5.AspNetCore.csproj @@ -6,16 +6,14 @@ enable False idee5 - (c) 2023 idee5 + (c) 2024 idee5 ASP.NET Core additions for commands, queries, ... from the idee5.Common package. True https://github.com/bdongus/idee5.AspNetCore idee5 nuget icon.png idee5;ASP.NET Core MIT - 1.1.0 - 1.1.0.0 - 1.1.0.0 + 1.1.1 README.md @@ -33,7 +31,7 @@ - +