Generator Changes at 9/27/2025 8:46:36 AM
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System.Reflection;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Domain.Entities;
|
||||
using CMSMicroservice.Infrastructure.Persistence.Interceptors;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence;
|
||||
|
||||
public class ApplicationDbContext : DbContext, IApplicationDbContext
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly AuditableEntitySaveChangesInterceptor _auditableEntitySaveChangesInterceptor;
|
||||
|
||||
public ApplicationDbContext(
|
||||
DbContextOptions<ApplicationDbContext> options,
|
||||
IMediator mediator,
|
||||
AuditableEntitySaveChangesInterceptor auditableEntitySaveChangesInterceptor)
|
||||
: base(options)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_auditableEntitySaveChangesInterceptor = auditableEntitySaveChangesInterceptor;
|
||||
}
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
builder.HasDefaultSchema("CMS");
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.AddInterceptors(_auditableEntitySaveChangesInterceptor);
|
||||
}
|
||||
|
||||
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _mediator.DispatchDomainEvents(this);
|
||||
|
||||
return await base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
public DbSet<User> Users => Set<User>();
|
||||
public DbSet<UserAddress> UserAddresss => Set<UserAddress>();
|
||||
public DbSet<Package> Packages => Set<Package>();
|
||||
public DbSet<UserOrder> UserOrders => Set<UserOrder>();
|
||||
public DbSet<Role> Roles => Set<Role>();
|
||||
public DbSet<UserRole> UserRoles => Set<UserRole>();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user