diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index 1d2e42f7..2a54f036 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -18,4 +18,4 @@ - \ No newline at end of file + diff --git a/src/Domain/Common/Base/AggregateRoot.cs b/src/Domain/Common/Base/AggregateRoot.cs index 83275545..5dafe5e9 100644 --- a/src/Domain/Common/Base/AggregateRoot.cs +++ b/src/Domain/Common/Base/AggregateRoot.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations.Schema; +using SSW.CleanArchitecture.Domain.Common.Interfaces; +using System.ComponentModel.DataAnnotations.Schema; namespace SSW.CleanArchitecture.Domain.Common.Base; @@ -24,10 +25,6 @@ public abstract class AggregateRoot : Entity, IAggregateRoot public void ClearDomainEvents() => _domainEvents.Clear(); } -public interface IAggregateRoot -{ -} - // TODO: Delete this once TodoItems are removed public abstract class BaseEntity : Entity { diff --git a/src/Domain/Common/Interfaces/IAggregateRoot.cs b/src/Domain/Common/Interfaces/IAggregateRoot.cs new file mode 100644 index 00000000..104b2995 --- /dev/null +++ b/src/Domain/Common/Interfaces/IAggregateRoot.cs @@ -0,0 +1,14 @@ +using SSW.CleanArchitecture.Domain.Common.Base; + +namespace SSW.CleanArchitecture.Domain.Common.Interfaces; + +public interface IAggregateRoot +{ + public IReadOnlyList DomainEvents { get; } + + public void AddDomainEvent(DomainEvent domainEvent); + + public void RemoveDomainEvent(DomainEvent domainEvent); + + public void ClearDomainEvents(); +} \ No newline at end of file diff --git a/src/Infrastructure/Persistence/ApplicationDbContext.cs b/src/Infrastructure/Persistence/ApplicationDbContext.cs index 99f5e580..3242c923 100644 --- a/src/Infrastructure/Persistence/ApplicationDbContext.cs +++ b/src/Infrastructure/Persistence/ApplicationDbContext.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using SSW.CleanArchitecture.Application.Common.Interfaces; using SSW.CleanArchitecture.Domain.Common.Base; +using SSW.CleanArchitecture.Domain.Common.Interfaces; using SSW.CleanArchitecture.Domain.Heroes; using SSW.CleanArchitecture.Domain.Teams; using SSW.CleanArchitecture.Domain.TodoItems; diff --git a/src/Infrastructure/Persistence/Interceptors/DispatchDomainEventsInterceptor.cs b/src/Infrastructure/Persistence/Interceptors/DispatchDomainEventsInterceptor.cs index 650e61b2..c33429cb 100644 --- a/src/Infrastructure/Persistence/Interceptors/DispatchDomainEventsInterceptor.cs +++ b/src/Infrastructure/Persistence/Interceptors/DispatchDomainEventsInterceptor.cs @@ -27,7 +27,7 @@ public async Task DispatchDomainEvents(DbContext? context) return; var entities = context.ChangeTracker - .Entries() + .Entries() .Where(e => e.Entity.DomainEvents.Any()) .Select(e => e.Entity) .ToList(); @@ -41,4 +41,4 @@ public async Task DispatchDomainEvents(DbContext? context) foreach (var domainEvent in domainEvents) await mediator.Publish(domainEvent); } -} +} \ No newline at end of file