Skip to content

Commit

Permalink
Tidied up aggregate root interface
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmackay committed Apr 14, 2024
1 parent e1714c1 commit 8dab299
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
7 changes: 2 additions & 5 deletions src/Domain/Common/Base/AggregateRoot.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -24,10 +25,6 @@ public abstract class AggregateRoot<TId> : Entity<TId>, IAggregateRoot
public void ClearDomainEvents() => _domainEvents.Clear();
}

public interface IAggregateRoot
{
}

// TODO: Delete this once TodoItems are removed
public abstract class BaseEntity<TId> : Entity<TId>
{
Expand Down
14 changes: 14 additions & 0 deletions src/Domain/Common/Interfaces/IAggregateRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using SSW.CleanArchitecture.Domain.Common.Base;

namespace SSW.CleanArchitecture.Domain.Common.Interfaces;

public interface IAggregateRoot
{
public IReadOnlyList<DomainEvent> DomainEvents { get; }

public void AddDomainEvent(DomainEvent domainEvent);

public void RemoveDomainEvent(DomainEvent domainEvent);

public void ClearDomainEvents();
}
1 change: 1 addition & 0 deletions src/Infrastructure/Persistence/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task DispatchDomainEvents(DbContext? context)
return;

var entities = context.ChangeTracker
.Entries<IDomainEvents>()
.Entries<IAggregateRoot>()
.Where(e => e.Entity.DomainEvents.Any())
.Select(e => e.Entity)
.ToList();
Expand All @@ -41,4 +41,4 @@ public async Task DispatchDomainEvents(DbContext? context)
foreach (var domainEvent in domainEvents)
await mediator.Publish(domainEvent);
}
}
}

0 comments on commit 8dab299

Please sign in to comment.