add UnitWorkBehavior and some files moving add Docker stuff to prepare heroku deployment rename (Up/Down)vote add sample for msbuild tasks
25 lines
604 B
C#
25 lines
604 B
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MediatR;
|
|
|
|
namespace HN.Infrastructure.Behaviors
|
|
{
|
|
public sealed class UnitOfWorkBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
|
|
{
|
|
private readonly HNDbContext _context;
|
|
|
|
public UnitOfWorkBehavior(HNDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
|
|
{
|
|
var response = await next();
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return response;
|
|
}
|
|
}
|
|
} |