Files
mixtape/zero.Core/Collections/Interceptors/CollectionInterceptor.cs
T

109 lines
3.9 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
2020-11-18 15:55:18 +01:00
using zero.Core.Entities;
2020-11-19 00:14:52 +01:00
namespace zero.Core.Collections
2020-11-18 15:55:18 +01:00
{
public abstract partial class CollectionInterceptor<T> : ICollectionInterceptor<T> where T : ZeroEntity
2020-11-18 15:55:18 +01:00
{
/// <inheritdoc />
public virtual bool CanRun(Parameters args) => true;
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Creating(CreateParameters args) => Task.FromResult<InterceptorResult<T>>(default);
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Updating(UpdateParameters args) => Task.FromResult<InterceptorResult<T>>(default);
2020-11-18 15:55:18 +01:00
2021-09-24 10:38:59 +02:00
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Saving(SaveParameters args) => Task.FromResult<InterceptorResult<T>>(default);
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Deleting(DeleteParameters args) => Task.FromResult<InterceptorResult<T>>(default);
2021-08-26 13:39:30 +02:00
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Purging(PurgeParameters args) => Task.FromResult<InterceptorResult<T>>(default);
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task Created(CreateParameters args) => Task.CompletedTask;
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task Updated(UpdateParameters args) => Task.CompletedTask;
2020-11-18 15:55:18 +01:00
2021-09-24 10:38:59 +02:00
/// <inheritdoc />
public virtual Task Saved(SaveParameters args) => Task.CompletedTask;
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task Deleted(DeleteParameters args) => Task.CompletedTask;
2020-11-18 15:55:18 +01:00
/// <inheritdoc />
public virtual Task Purged(PurgeParameters args) => Task.CompletedTask;
2020-11-18 15:55:18 +01:00
}
public abstract partial class CollectionInterceptor : CollectionInterceptor<ZeroEntity>, ICollectionInterceptor
{
/// <inheritdoc />
public override bool CanRun(Parameters args) => base.CanRun(args);
}
public interface ICollectionInterceptor : ICollectionInterceptor<ZeroEntity> { }
public interface ICollectionInterceptor<T> where T : ZeroEntity
2020-11-18 15:55:18 +01:00
{
/// <summary>
/// Whether any of the interceptor methods is allowed to run based on the parameters
/// </summary>
bool CanRun(CollectionInterceptor<T>.Parameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called after an entity has been stored but before the session has saved its changes
/// </summary>
Task Created(CollectionInterceptor<T>.CreateParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called before an entity is stored and validated
/// </summary>
Task<InterceptorResult<T>> Creating(CollectionInterceptor<T>.CreateParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called after an entity has been deleted but before the session has saved its changes
/// </summary>
Task Deleted(CollectionInterceptor<T>.DeleteParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called before an entity is deleted
/// </summary>
Task<InterceptorResult<T>> Deleting(CollectionInterceptor<T>.DeleteParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called after the document collection has been purged
/// </summary>
Task Purged(CollectionInterceptor<T>.PurgeParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called before a collection is purged
/// </summary>
Task<InterceptorResult<T>> Purging(CollectionInterceptor<T>.PurgeParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called after an entity has been updated but before the session has saved its changes
/// </summary>
Task Updated(CollectionInterceptor<T>.UpdateParameters args);
2020-11-18 15:55:18 +01:00
/// <summary>
/// Called before an entity is stored and validated
/// </summary>
Task<InterceptorResult<T>> Updating(CollectionInterceptor<T>.UpdateParameters args);
2021-09-24 10:38:59 +02:00
/// <summary>
/// Called after an entity has been saved (created or updated) but before the session has saved its changes
/// </summary>
Task Saved(CollectionInterceptor<T>.SaveParameters args);
/// <summary>
/// Called before an entity is stored and validated
/// </summary>
Task<InterceptorResult<T>> Saving(CollectionInterceptor<T>.SaveParameters args);
2020-11-18 15:55:18 +01:00
}
}