23 lines
626 B
C#
23 lines
626 B
C#
using Femto.Modules.Auth.Data;
|
|
using MediatR;
|
|
|
|
namespace Femto.Modules.Auth.Infrastructure;
|
|
|
|
internal class SaveChangesPipelineBehaviour<TRequest, TResponse>(AuthContext context)
|
|
: IPipelineBehavior<TRequest, TResponse>
|
|
where TRequest : notnull
|
|
{
|
|
public async Task<TResponse> Handle(
|
|
TRequest request,
|
|
RequestHandlerDelegate<TResponse> next,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var response = await next(cancellationToken);
|
|
|
|
if (context.ChangeTracker.HasChanges())
|
|
await context.SaveChangesAsync(cancellationToken);
|
|
|
|
return response;
|
|
}
|
|
}
|