This commit is contained in:
2025-10-27 17:39:18 -04:00
commit 31f723bea4
1579 changed files with 642409 additions and 0 deletions

26
Prefab/Data/Extensions.cs Normal file
View File

@@ -0,0 +1,26 @@
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));
});
}
}