27 lines
841 B
C#
27 lines
841 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Prefab.Domain.Common;
|
|
|
|
namespace Prefab.Data;
|
|
|
|
/// <summary>
|
|
/// Extension methods for <see cref="ModelBuilder"/> when configuring the database model.
|
|
/// </summary>
|
|
public static class ModelBuilderExtensions
|
|
{
|
|
/// <summary>
|
|
/// Ignores the domain event collection for all entities implementing <see cref="IHasDomainEvents"/>.
|
|
/// </summary>
|
|
/// <param name="builder">The model builder to configure.</param>
|
|
public static void IgnoreDomainEvents(this ModelBuilder builder)
|
|
{
|
|
builder.Model
|
|
.GetEntityTypes()
|
|
.Where(e => typeof(IHasDomainEvents).IsAssignableFrom(e.ClrType))
|
|
.ToList()
|
|
.ForEach(e =>
|
|
{
|
|
builder.Entity(e.ClrType).Ignore(nameof(IHasDomainEvents.Events));
|
|
});
|
|
}
|
|
}
|