Add Exception middleware
This commit is contained in:
@@ -3,17 +3,19 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Diary.Data
|
||||
{
|
||||
|
||||
public interface IDiaryDBContext
|
||||
{
|
||||
{
|
||||
DbSet<Entry> Entries { get; set; }
|
||||
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public class DiaryDBContext : DbContext, IDiaryDBContext
|
||||
{
|
||||
public DbSet<Entry> Entries { get; set; }
|
||||
|
||||
public DiaryDBContext(DbContextOptions<DiaryDBContext> options) : base(options){
|
||||
public DiaryDBContext(DbContextOptions<DiaryDBContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
@@ -22,5 +24,10 @@ namespace Diary.Data
|
||||
|
||||
builder.ApplyConfiguration(new EntryConfiguration());
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Diary.Data
|
||||
namespace Diary.Data
|
||||
{
|
||||
public class UnitOfWork
|
||||
{
|
||||
public UnitOfWork()
|
||||
{
|
||||
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
Task CompleteAsync();
|
||||
}
|
||||
|
||||
public class UnitOfWork:IUnitOfWork
|
||||
{
|
||||
private readonly IDiaryDBContext _context;
|
||||
|
||||
public UnitOfWork(IDiaryDBContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
public async Task CompleteAsync()
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user