Files
mixtape/mixtape.Raven/Interceptors/Interceptors.cs
T
2026-05-05 11:34:32 +02:00

52 lines
1.8 KiB
C#

using Microsoft.Extensions.Logging;
namespace Mixtape.Raven;
public class Interceptors : IInterceptors
{
protected IMixtapeContext Context { get; set; }
protected IMixtapeStore Store { get; set; }
protected Lazy<IEnumerable<IInterceptor>> Registrations { get; set; }
protected ILogger<IInterceptor> Logger { get; set; }
public Interceptors(IMixtapeContext context, IMixtapeStore store, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger)
{
Context = context;
Store = store;
Registrations = registrations;
Logger = logger;
}
/// <inheritdoc />
public InterceptorInstruction<T> ForCreate<T>(T model) where T : MixtapeIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Create, model);
/// <inheritdoc />
public InterceptorInstruction<T> ForUpdate<T>(T model, T previousModel = null) where T : MixtapeIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Update, model, previousModel);
/// <inheritdoc />
public InterceptorInstruction<T> ForDelete<T>(T model) where T : MixtapeIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Delete, model);
}
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 : MixtapeIdEntity, new();
/// <summary>
/// Instruction which can run interceptors before and after updating an entity
/// </summary>
InterceptorInstruction<T> ForUpdate<T>(T model, T previousModel = null) where T : MixtapeIdEntity, new();
/// <summary>
/// Instruction which can run interceptors before and after deleting an entity
/// </summary>
InterceptorInstruction<T> ForDelete<T>(T model) where T : MixtapeIdEntity, new();
}