Files
mixtape/zero.Core/Communication/Interceptors/Interceptors.cs
T

49 lines
1.7 KiB
C#
Raw Normal View History

2021-11-22 14:29:22 +01:00
using Microsoft.Extensions.Logging;
namespace zero.Communication;
public class Interceptors : IInterceptors
{
protected IZeroContext Context { get; set; }
2021-12-29 01:25:35 +01:00
protected Lazy<IEnumerable<IInterceptor>> Registrations { get; set; }
2021-11-22 14:29:22 +01:00
protected ILogger<IInterceptor> Logger { get; set; }
2021-12-29 01:25:35 +01:00
public Interceptors(IZeroContext context, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger)
2021-11-22 14:29:22 +01:00
{
Context = context;
Registrations = registrations;
Logger = logger;
}
/// <inheritdoc />
2021-11-27 18:09:27 +01:00
public InterceptorInstruction<T> ForCreate<T>(T model) where T : ZeroIdEntity, new() => new(this, Context, Registrations, Logger, InterceptorRunType.Create, model);
2021-11-22 14:29:22 +01:00
/// <inheritdoc />
2021-11-27 18:09:27 +01:00
public InterceptorInstruction<T> ForUpdate<T>(T model) where T : ZeroIdEntity, new() => new(this, Context, Registrations, Logger, InterceptorRunType.Update, model);
2021-11-22 14:29:22 +01:00
/// <inheritdoc />
2021-11-27 18:09:27 +01:00
public InterceptorInstruction<T> ForDelete<T>(T model) where T : ZeroIdEntity, new() => new(this, Context, Registrations, Logger, InterceptorRunType.Delete, model);
2021-11-22 14:29:22 +01:00
}
public interface IInterceptors
{
/// <summary>
/// Instruction which can run interceptors before and after a creating an entity
/// </summary>
InterceptorInstruction<T> ForCreate<T>(T model) where T : ZeroIdEntity, new();
/// <summary>
/// Instruction which can run interceptors before and after updating an entity
/// </summary>
InterceptorInstruction<T> ForUpdate<T>(T model) where T : ZeroIdEntity, new();
/// <summary>
/// Instruction which can run interceptors before and after deleting an entity
/// </summary>
InterceptorInstruction<T> ForDelete<T>(T model) where T : ZeroIdEntity, new();
}