/// <inheritdoc />
        public virtual async Task Invoke(HttpContext context)
        {
            if (Options.BeforeInvoke != null)
            {
                await Options.BeforeInvoke(context);
            }

            if (context.Response.HasStarted || context.RequestAborted.IsCancellationRequested)
            {
                Logger.LogWarning(
                    "Middleware will not be executed [Response.HasStarted={responseHasStarted} Request.Aborted={requestAborted}]",
                    context.Response.HasStarted, context.RequestAborted.IsCancellationRequested);
                return;
            }

            Logger.LogDebug("Invoking the middleware logic");
            await OnInvoke(context);

            if (Options.AfterInvoke != null)
            {
                await Options.AfterInvoke(context);
            }
        }