diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppCommandMiddleware.cs index 70cb33d59..b9676d94c 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Orleans; using Squidex.Domain.Apps.Entities.Apps.Commands; @@ -38,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Apps this.contextProvider = contextProvider; } - public override async Task HandleAsync(CommandContext context, Func next) + public override async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is UploadAppImage uploadImage) { @@ -52,7 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Apps contextProvider.Context.App = app; } - await next(); + await next(context); } private async Task UploadAsync(UploadAppImage uploadImage) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs index 58183a69d..156b04edb 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs @@ -164,7 +164,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes } } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is CreateApp createApp) { @@ -174,7 +174,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes try { - await next(); + await next(context); } finally { @@ -195,7 +195,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes } else { - await next(); + await next(context); if (context.IsCompleted) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs index 785523ff8..878c1aa74 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Apps.Commands; using Squidex.Infrastructure; @@ -25,13 +24,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation this.userResolver = userResolver; } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is AssignContributor assignContributor && ShouldInvite(assignContributor)) { var created = await userResolver.CreateUserIfNotExistsAsync(assignContributor.ContributorId, true); - await next(); + await next(context); if (created && context.PlainResult is IAppEntity app) { @@ -40,7 +39,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation } else { - await next(); + await next(context); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/AlwaysCreateClientCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/AlwaysCreateClientCommandMiddleware.cs index 6d131dbef..de9fad661 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/AlwaysCreateClientCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/AlwaysCreateClientCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Apps.Commands; using Squidex.Infrastructure.Commands; @@ -15,7 +14,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates { public sealed class AlwaysCreateClientCommandMiddleware : ICommandMiddleware { - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { if (context.IsCompleted && context.Command is CreateApp createApp) { @@ -24,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates context.CommandBus.PublishAsync(command).Forget(); } - return next(); + return next(context); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateBlogCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateBlogCommandMiddleware.cs index 95ac51bae..94967d103 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateBlogCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateBlogCommandMiddleware.cs @@ -20,7 +20,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates { private const string TemplateName = "Blog"; - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.IsCompleted && context.Command is CreateApp createApp && IsRightTemplate(createApp)) { @@ -41,7 +41,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates CreatePostsAsync(publish)); } - await next(); + await next(context); } private static bool IsRightTemplate(CreateApp createApp) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateIdentityCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateIdentityCommandMiddleware.cs index 7ae11260e..6bcbe0628 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateIdentityCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateIdentityCommandMiddleware.cs @@ -18,7 +18,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates { private const string TemplateName = "Identity"; - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.IsCompleted && context.Command is CreateApp createApp && IsRightTemplate(createApp)) { @@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates CreateUsersSchemaAsync(publish)); } - await next(); + await next(context); } private static bool IsRightTemplate(CreateApp createApp) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateProfileCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateProfileCommandMiddleware.cs index 19827379b..aab99d41c 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateProfileCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateProfileCommandMiddleware.cs @@ -20,7 +20,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates { private const string TemplateName = "Profile"; - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.IsCompleted && context.Command is CreateApp createApp && IsRightTemplate(createApp)) { @@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates CreateSkillsSchemaAsync(publish)); } - await next(); + await next(context); } private static bool IsRightTemplate(CreateApp createApp) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetCommandMiddleware.cs index c9c446945..b99e705bc 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Threading.Tasks; @@ -47,7 +46,7 @@ namespace Squidex.Domain.Apps.Entities.Assets this.assetMetadataSources = assetMetadataSources; } - public override async Task HandleAsync(CommandContext context, Func next) + public override async Task HandleAsync(CommandContext context, NextDelegate next) { var tempFile = context.ContextId.ToString(); @@ -71,7 +70,7 @@ namespace Squidex.Domain.Apps.Entities.Assets context.Complete(result); - await next(); + await next(context); return; } } @@ -121,7 +120,7 @@ namespace Squidex.Domain.Apps.Entities.Assets } } - private async Task HandleCoreAsync(CommandContext context, Func next) + private async Task HandleCoreAsync(CommandContext context, NextDelegate next) { await base.HandleAsync(context, next); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Comments/CommentsCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Comments/CommentsCommandMiddleware.cs index 563652a42..bfc1d5f11 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Comments/CommentsCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Comments/CommentsCommandMiddleware.cs @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Comments this.userResolver = userResolver; } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is CommentsCommand commentsCommand) { @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Comments await ExecuteCommandAsync(context, commentsCommand); } - await next(); + await next(context); } private async Task ExecuteCommandAsync(CommandContext context, CommentsCommand commentsCommand) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentCommandMiddleware.cs index 6b002ad96..46cbd5aa4 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Orleans; using Squidex.Domain.Apps.Entities.Contents.Commands; @@ -29,7 +28,7 @@ namespace Squidex.Domain.Apps.Entities.Contents this.contextProvider = contextProvider; } - public override async Task HandleAsync(CommandContext context, Func next) + public override async Task HandleAsync(CommandContext context, NextDelegate next) { await base.HandleAsync(context, next); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/SingletonCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/SingletonCommandMiddleware.cs index a9695f500..44ff091be 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/SingletonCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/SingletonCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Entities.Contents.Commands; @@ -18,9 +17,9 @@ namespace Squidex.Domain.Apps.Entities.Contents { public sealed class SingletonCommandMiddleware : ICommandMiddleware { - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { - await next(); + await next(context); if (context.IsCompleted && context.Command is CreateSchema createSchema && diff --git a/backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs b/backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs index c3a346594..42c240f2a 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs @@ -70,9 +70,9 @@ namespace Squidex.Domain.Apps.Entities.Rules.Indexes } } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { - await next(); + await next(context); if (context.IsCompleted) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleCommandMiddleware.cs index 9f02f0398..963e0f0fe 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Orleans; using Squidex.Domain.Apps.Entities.Rules.Commands; @@ -30,7 +29,7 @@ namespace Squidex.Domain.Apps.Entities.Rules this.contextProvider = contextProvider; } - public override async Task HandleAsync(CommandContext context, Func next) + public override async Task HandleAsync(CommandContext context, NextDelegate next) { await base.HandleAsync(context, next); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Rules/UsageTracking/UsageTrackerCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Rules/UsageTracking/UsageTrackerCommandMiddleware.cs index b96cec588..4e1d5294a 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Rules/UsageTracking/UsageTrackerCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Rules/UsageTracking/UsageTrackerCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Orleans; using Squidex.Domain.Apps.Core.Rules.Triggers; @@ -27,7 +26,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.UsageTracking usageTrackerGrain = grainFactory.GetGrain(SingleGrain.Id); } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { switch (context.Command) { @@ -55,7 +54,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.UsageTracking } } - await next(); + await next(context); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs index 65ce8ddb9..f440674ea 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs @@ -94,7 +94,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes } } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is CreateSchema createSchema) { @@ -104,7 +104,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes try { - await next(); + await next(context); } finally { @@ -123,7 +123,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes } else { - await next(); + await next(context); if (context.IsCompleted) { diff --git a/backend/src/Squidex.Infrastructure.Amazon/Assets/AmazonS3AssetStore.cs b/backend/src/Squidex.Infrastructure.Amazon/Assets/AmazonS3AssetStore.cs index 13b08d855..e8e09e0da 100644 --- a/backend/src/Squidex.Infrastructure.Amazon/Assets/AmazonS3AssetStore.cs +++ b/backend/src/Squidex.Infrastructure.Amazon/Assets/AmazonS3AssetStore.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.IO; using System.Net; using System.Threading; diff --git a/backend/src/Squidex.Infrastructure/Commands/CommandExtensions.cs b/backend/src/Squidex.Infrastructure/Commands/CommandExtensions.cs index c669a221a..2b3334dff 100644 --- a/backend/src/Squidex.Infrastructure/Commands/CommandExtensions.cs +++ b/backend/src/Squidex.Infrastructure/Commands/CommandExtensions.cs @@ -14,7 +14,7 @@ namespace Squidex.Infrastructure.Commands { public static Task HandleAsync(this ICommandMiddleware commandMiddleware, CommandContext context) { - return commandMiddleware.HandleAsync(context, () => TaskHelper.Done); + return commandMiddleware.HandleAsync(context, x => TaskHelper.Done); } } } diff --git a/backend/src/Squidex.Infrastructure/Commands/CustomCommandMiddlewareRunner.cs b/backend/src/Squidex.Infrastructure/Commands/CustomCommandMiddlewareRunner.cs index cbb7f4910..b2762f9e4 100644 --- a/backend/src/Squidex.Infrastructure/Commands/CustomCommandMiddlewareRunner.cs +++ b/backend/src/Squidex.Infrastructure/Commands/CustomCommandMiddlewareRunner.cs @@ -23,19 +23,19 @@ namespace Squidex.Infrastructure.Commands this.extensions = extensions.Reverse().ToList(); } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { foreach (var handler in extensions) { - next = Join(handler, context, next); + next = Join(handler, next); } - await next(); + await next(context); } - private static Func Join(ICommandMiddleware handler, CommandContext context, Func next) + private static NextDelegate Join(ICommandMiddleware handler, NextDelegate next) { - return () => handler.HandleAsync(context, next); + return context => handler.HandleAsync(context, next); } } } diff --git a/backend/src/Squidex.Infrastructure/Commands/EnrichWithTimestampCommandMiddleware.cs b/backend/src/Squidex.Infrastructure/Commands/EnrichWithTimestampCommandMiddleware.cs index 0d2ecd412..af49eebe5 100644 --- a/backend/src/Squidex.Infrastructure/Commands/EnrichWithTimestampCommandMiddleware.cs +++ b/backend/src/Squidex.Infrastructure/Commands/EnrichWithTimestampCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using NodaTime; @@ -22,14 +21,14 @@ namespace Squidex.Infrastructure.Commands this.clock = clock; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is ITimestampCommand timestampCommand) { timestampCommand.Timestamp = clock.GetCurrentInstant(); } - return next(); + return next(context); } } } diff --git a/backend/src/Squidex.Infrastructure/Commands/GrainCommandMiddleware.cs b/backend/src/Squidex.Infrastructure/Commands/GrainCommandMiddleware.cs index 0829900cd..90588ab85 100644 --- a/backend/src/Squidex.Infrastructure/Commands/GrainCommandMiddleware.cs +++ b/backend/src/Squidex.Infrastructure/Commands/GrainCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Orleans; @@ -22,11 +21,11 @@ namespace Squidex.Infrastructure.Commands this.grainFactory = grainFactory; } - public virtual async Task HandleAsync(CommandContext context, Func next) + public virtual async Task HandleAsync(CommandContext context, NextDelegate next) { await ExecuteCommandAsync(context); - await next(); + await next(context); } protected async Task ExecuteCommandAsync(CommandContext context) diff --git a/backend/src/Squidex.Infrastructure/Commands/ICommandMiddleware.cs b/backend/src/Squidex.Infrastructure/Commands/ICommandMiddleware.cs index e9ae310da..93dc86c20 100644 --- a/backend/src/Squidex.Infrastructure/Commands/ICommandMiddleware.cs +++ b/backend/src/Squidex.Infrastructure/Commands/ICommandMiddleware.cs @@ -5,13 +5,14 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; namespace Squidex.Infrastructure.Commands { + public delegate Task NextDelegate(CommandContext context); + public interface ICommandMiddleware { - Task HandleAsync(CommandContext context, Func next); + Task HandleAsync(CommandContext context, NextDelegate next); } } diff --git a/backend/src/Squidex.Infrastructure/Commands/InMemoryCommandBus.cs b/backend/src/Squidex.Infrastructure/Commands/InMemoryCommandBus.cs index 987f81711..464f0efb3 100644 --- a/backend/src/Squidex.Infrastructure/Commands/InMemoryCommandBus.cs +++ b/backend/src/Squidex.Infrastructure/Commands/InMemoryCommandBus.cs @@ -9,42 +9,69 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; namespace Squidex.Infrastructure.Commands { public sealed class InMemoryCommandBus : ICommandBus { - private readonly List middlewares; + private readonly IStep pipeline; - public InMemoryCommandBus(IEnumerable middlewares) + private interface IStep { - Guard.NotNull(middlewares); + Task InvokeAsync(CommandContext context); + } - this.middlewares = middlewares.Reverse().ToList(); + private class NoopStep : IStep + { + public Task InvokeAsync(CommandContext context) + { + return Task.CompletedTask; + } } - public async Task PublishAsync(ICommand command) + private class DefaultStep : IStep { - Guard.NotNull(command); + private readonly IStep next; + private readonly ICommandMiddleware middleware; - var context = new CommandContext(command, this); + public DefaultStep(ICommandMiddleware middleware, IStep next) + { + this.middleware = middleware; - var next = new Func(() => TaskHelper.Done); + this.next = next; + } - foreach (var handler in middlewares) + public Task InvokeAsync(CommandContext context) { - next = Join(handler, context, next); + return middleware.HandleAsync(context, next.InvokeAsync); } + } + + public InMemoryCommandBus(IEnumerable middlewares) + { + Guard.NotNull(middlewares); - await next(); + var reverseMiddlewares = middlewares.Reverse().ToList(); - return context; + IStep next = new NoopStep(); + + foreach (var middleware in reverseMiddlewares) + { + next = new DefaultStep(middleware, next); + } + + pipeline = next; } - private static Func Join(ICommandMiddleware handler, CommandContext context, Func next) + public async Task PublishAsync(ICommand command) { - return () => handler.HandleAsync(context, next); + Guard.NotNull(command); + + var context = new CommandContext(command, this); + + await pipeline.InvokeAsync(context); + + return context; } } } \ No newline at end of file diff --git a/backend/src/Squidex.Infrastructure/Commands/LogCommandMiddleware.cs b/backend/src/Squidex.Infrastructure/Commands/LogCommandMiddleware.cs index f0028a205..4ebfa279f 100644 --- a/backend/src/Squidex.Infrastructure/Commands/LogCommandMiddleware.cs +++ b/backend/src/Squidex.Infrastructure/Commands/LogCommandMiddleware.cs @@ -22,7 +22,7 @@ namespace Squidex.Infrastructure.Commands this.log = log; } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { var logContext = (id: context.ContextId.ToString(), command: context.Command.GetType().Name); @@ -40,7 +40,7 @@ namespace Squidex.Infrastructure.Commands .WriteProperty("status", "Completed") .WriteProperty("commandType", ctx.command))) { - await next(); + await next(context); } log.LogInformation(logContext, (ctx, w) => w diff --git a/backend/src/Squidex.Infrastructure/Commands/ReadonlyCommandMiddleware.cs b/backend/src/Squidex.Infrastructure/Commands/ReadonlyCommandMiddleware.cs index 81d2b54ec..9e0f3bf95 100644 --- a/backend/src/Squidex.Infrastructure/Commands/ReadonlyCommandMiddleware.cs +++ b/backend/src/Squidex.Infrastructure/Commands/ReadonlyCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Threading.Tasks; using Microsoft.Extensions.Options; @@ -22,14 +21,14 @@ namespace Squidex.Infrastructure.Commands this.options = options.Value; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { if (options.IsReadonly) { throw new DomainException("Application is in readonly mode at the moment."); } - return next(); + return next(context); } } } diff --git a/backend/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs b/backend/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs index 84ecd94ee..38aee4e18 100644 --- a/backend/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs +++ b/backend/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs @@ -25,13 +25,13 @@ namespace Squidex.Web.CommandMiddlewares this.httpContextAccessor = httpContextAccessor; } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { var httpContext = httpContextAccessor.HttpContext; if (httpContext == null) { - await next(); + await next(context); return; } @@ -50,7 +50,7 @@ namespace Squidex.Web.CommandMiddlewares } } - await next(); + await next(context); if (context.PlainResult is EntitySavedResult result) { diff --git a/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithActorCommandMiddleware.cs b/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithActorCommandMiddleware.cs index 0bff3a6c5..e5a26fd79 100644 --- a/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithActorCommandMiddleware.cs +++ b/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithActorCommandMiddleware.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Security; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -24,11 +23,11 @@ namespace Squidex.Web.CommandMiddlewares this.httpContextAccessor = httpContextAccessor; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { if (httpContextAccessor.HttpContext == null) { - return next(); + return next(context); } if (context.Command is SquidexCommand squidexCommand) @@ -48,7 +47,7 @@ namespace Squidex.Web.CommandMiddlewares } } - return next(); + return next(context); } } } diff --git a/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithAppIdCommandMiddleware.cs b/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithAppIdCommandMiddleware.cs index 394ee4aa7..97f17107d 100644 --- a/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithAppIdCommandMiddleware.cs +++ b/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithAppIdCommandMiddleware.cs @@ -23,7 +23,7 @@ namespace Squidex.Web.CommandMiddlewares this.contextProvider = contextProvider; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is IAppCommand appCommand && appCommand.AppId == null) { @@ -39,7 +39,7 @@ namespace Squidex.Web.CommandMiddlewares appSelfCommand.AppId = appId.Id; } - return next(); + return next(context); } private NamedId GetAppId() diff --git a/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithSchemaIdCommandMiddleware.cs b/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithSchemaIdCommandMiddleware.cs index 03435941b..b798450be 100644 --- a/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithSchemaIdCommandMiddleware.cs +++ b/backend/src/Squidex.Web/CommandMiddlewares/EnrichWithSchemaIdCommandMiddleware.cs @@ -28,11 +28,11 @@ namespace Squidex.Web.CommandMiddlewares this.actionContextAccessor = actionContextAccessor; } - public async Task HandleAsync(CommandContext context, Func next) + public async Task HandleAsync(CommandContext context, NextDelegate next) { if (actionContextAccessor.ActionContext == null) { - await next(); + await next(context); return; } @@ -51,7 +51,7 @@ namespace Squidex.Web.CommandMiddlewares schemaSelfCommand.SchemaId = schemaId?.Id ?? Guid.Empty; } - await next(); + await next(context); } private async Task?> GetSchemaIdAsync(CommandContext context) diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/CommentsCommandMiddlewareTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/CommentsCommandMiddlewareTests.cs index fff0c6c7c..afbbdfb57 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/CommentsCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Comments/CommentsCommandMiddlewareTests.cs @@ -56,7 +56,7 @@ namespace Squidex.Domain.Apps.Entities.Comments var isNextCalled = false; - await sut.HandleAsync(context, () => + await sut.HandleAsync(context, c => { isNextCalled = true; diff --git a/backend/tests/Squidex.Infrastructure.Tests/Commands/CustomCommandMiddlewareRunnerTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Commands/CustomCommandMiddlewareRunnerTests.cs index 955907617..83698bd79 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Commands/CustomCommandMiddlewareRunnerTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Commands/CustomCommandMiddlewareRunnerTests.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Collections.Generic; using System.Threading.Tasks; using FakeItEasy; @@ -31,14 +30,14 @@ namespace Squidex.Infrastructure.Commands this.value = value; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { if (context.Command is Command command) { command.Values.Add(value); } - return next(); + return next(context); } } @@ -57,7 +56,7 @@ namespace Squidex.Infrastructure.Commands var isNextCalled = false; - await sut.HandleAsync(context, () => + await sut.HandleAsync(context, c => { isNextCalled = true; diff --git a/backend/tests/Squidex.Infrastructure.Tests/Commands/InMemoryCommandBusTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Commands/InMemoryCommandBusTests.cs index 733d08f76..3cfe87faf 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Commands/InMemoryCommandBusTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Commands/InMemoryCommandBusTests.cs @@ -21,7 +21,7 @@ namespace Squidex.Infrastructure.Commands { public ICommand LastCommand { get; private set; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { LastCommand = context.Command; @@ -35,7 +35,7 @@ namespace Squidex.Infrastructure.Commands { public ICommand LastCommand { get; private set; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { LastCommand = context.Command; @@ -47,7 +47,7 @@ namespace Squidex.Infrastructure.Commands { public ICommand LastCommand { get; private set; } - public Task HandleAsync(CommandContext context, Func next) + public Task HandleAsync(CommandContext context, NextDelegate next) { LastCommand = context.Command; diff --git a/backend/tests/Squidex.Infrastructure.Tests/Commands/LogCommandMiddlewareTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Commands/LogCommandMiddlewareTests.cs index e09180efd..9adb6af79 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Commands/LogCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Commands/LogCommandMiddlewareTests.cs @@ -47,7 +47,7 @@ namespace Squidex.Infrastructure.Commands { var context = new CommandContext(command, commandBus); - await sut.HandleAsync(context, () => + await sut.HandleAsync(context, c => { context.Complete(true); @@ -68,7 +68,7 @@ namespace Squidex.Infrastructure.Commands await Assert.ThrowsAsync(async () => { - await sut.HandleAsync(context, () => throw new InvalidOperationException()); + await sut.HandleAsync(context, c => throw new InvalidOperationException()); }); Assert.Equal(log.LogLevels, new Dictionary @@ -84,7 +84,7 @@ namespace Squidex.Infrastructure.Commands { var context = new CommandContext(command, commandBus); - await sut.HandleAsync(context, () => TaskHelper.Done); + await sut.HandleAsync(context, c => TaskHelper.Done); Assert.Equal(log.LogLevels, new Dictionary { diff --git a/backend/tests/Squidex.Infrastructure.Tests/Commands/ReadonlyCommandMiddlewareTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Commands/ReadonlyCommandMiddlewareTests.cs index ac098a25b..5c4ed9e22 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Commands/ReadonlyCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Commands/ReadonlyCommandMiddlewareTests.cs @@ -51,7 +51,7 @@ namespace Squidex.Infrastructure.Commands private async Task MakeCallAsync(CommandContext context) { - await sut.HandleAsync(context, () => + await sut.HandleAsync(context, c => { context.Complete(true);