添加项目文件。
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using IdentityService.Domain.Entities;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
|
||||
namespace IdentityService.Infrastructure
|
||||
{
|
||||
public class UserDbContext : IdentityDbContext<IdentityService.Domain.Entities.User, Role, Guid>
|
||||
{
|
||||
private IMediator? mediator;
|
||||
public DbSet<IdentityService.Domain.Entities.User> Users { get; private set; }
|
||||
|
||||
public UserDbContext(DbContextOptions<UserDbContext> options, IMediator mediator)
|
||||
: base(options)
|
||||
{
|
||||
this.mediator = mediator;
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
|
||||
modelBuilder.EnableSoftDeletionGlobalFilter();
|
||||
}
|
||||
|
||||
public async override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (mediator != null)
|
||||
{
|
||||
await mediator.DispatchDomainEventsAsync(this);
|
||||
}
|
||||
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user