mirror of https://github.com/Squidex/squidex.git
38 changed files with 271 additions and 172 deletions
@ -0,0 +1,42 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Web |
|||
{ |
|||
public struct Deferred |
|||
{ |
|||
private readonly Lazy<Task<object>> value; |
|||
|
|||
public Task<object> Value |
|||
{ |
|||
get { return value.Value; } |
|||
} |
|||
|
|||
private Deferred(Func<Task<object>> value) |
|||
{ |
|||
this.value = new Lazy<Task<object>>(value); |
|||
} |
|||
|
|||
public static Deferred Response(Func<object> factory) |
|||
{ |
|||
Guard.NotNull(factory, nameof(factory)); |
|||
|
|||
return new Deferred(() => Task.FromResult(factory())); |
|||
} |
|||
|
|||
public static Deferred AsyncResponse<T>(Func<Task<T>> factory) |
|||
{ |
|||
Guard.NotNull(factory, nameof(factory)); |
|||
|
|||
return new Deferred(async () => await factory()); |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
|
|||
namespace Squidex.Web |
|||
{ |
|||
public interface IGenerateETag |
|||
{ |
|||
Guid Id { get; } |
|||
|
|||
long Version { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.Filters; |
|||
|
|||
namespace Squidex.Web.Pipeline |
|||
{ |
|||
public sealed class DeferredActionFilter : IAsyncActionFilter |
|||
{ |
|||
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) |
|||
{ |
|||
await next(); |
|||
|
|||
if (context.Result is ObjectResult objectResult && objectResult.Value is Deferred deferred) |
|||
{ |
|||
objectResult.Value = await deferred.Value; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue