From d94d3d9fbe1e7e4bdb42ab56b05c2890f0eda725 Mon Sep 17 00:00:00 2001 From: Oskar Dudycz Date: Fri, 17 Dec 2021 13:16:47 +0100 Subject: [PATCH] Removed redundant entity generic parameter for add command handling from the Simple CQRS with ESDB example. --- .../ECommerce.Core/Commands/CommandHandler.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Sample/EventStoreDB/Simple/ECommerce.Core/Commands/CommandHandler.cs b/Sample/EventStoreDB/Simple/ECommerce.Core/Commands/CommandHandler.cs index 5f2efa363..aad432c50 100644 --- a/Sample/EventStoreDB/Simple/ECommerce.Core/Commands/CommandHandler.cs +++ b/Sample/EventStoreDB/Simple/ECommerce.Core/Commands/CommandHandler.cs @@ -9,13 +9,13 @@ namespace ECommerce.Core.Commands; public static class CommandHandlerExtensions { - public static async Task HandleCreateCommand( + public static async Task HandleCreateCommand( EventStoreClient eventStore, Func handle, Func getId, TCommand command, CancellationToken ct - ) where TEntity : notnull + ) { var entityId = getId(command); var @event = handle(command); @@ -41,25 +41,25 @@ public static async Task HandleUpdateCommand( await eventStore.Append(id, @event, getVersion(command), ct); } - public static IServiceCollection AddCreateCommandHandler( + public static IServiceCollection AddCreateCommandHandler( this IServiceCollection services, Func handle, Func getId - ) where TEntity : notnull => - services.AddCreateCommandHandler(_ => handle, getId); + ) => + services.AddCreateCommandHandler(_ => handle, getId); - public static IServiceCollection AddCreateCommandHandler( + public static IServiceCollection AddCreateCommandHandler( this IServiceCollection services, Func> handle, Func getId - ) where TEntity : notnull => + ) => services .AddTransient>(sp => { var eventStore = sp.GetRequiredService(); return async (command, ct) => - await HandleCreateCommand(eventStore, handle(sp), getId, command, ct); + await HandleCreateCommand(eventStore, handle(sp), getId, command, ct); }); public static IServiceCollection AddUpdateCommandHandler( @@ -122,7 +122,7 @@ public CommandHandlersBuilder AddOn( Func getId ) { - services.AddCreateCommandHandler(_ => handle, getId); + services.AddCreateCommandHandler(_ => handle, getId); return this; } @@ -131,7 +131,7 @@ public CommandHandlersBuilder AddOn( Func getId ) { - services.AddCreateCommandHandler(_ => handle, getId); + services.AddCreateCommandHandler(_ => handle, getId); return this; } @@ -154,4 +154,4 @@ Func getVersion return this; } } -} \ No newline at end of file +}