using Microsoft.EntityFrameworkCore;
using Prefab.Domain.Common;
namespace Prefab.Data;
///
/// Extension methods for when configuring the database model.
///
public static class ModelBuilderExtensions
{
///
/// Ignores the domain event collection for all entities implementing .
///
/// The model builder to configure.
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));
});
}
}