Skip to content

Commit

Permalink
Updates to shared kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken committed Apr 9, 2024
1 parent 56ffc07 commit a88f62c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MinimalRichDomain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{18ABF4ED-34E6-42B4-A242-BAD1739AAF17} = {FF69C4FB-2589-43CE-9CB7-E21B71838AE6}
{A62056DA-D2FC-49C2-92EE-D47D3BBED116} = {FF69C4FB-2589-43CE-9CB7-E21B71838AE6}
{A62056DA-D2FC-49C2-92EE-D47D3BBED116} = {10FA7376-ECEA-4A08-B3CC-0CA22DEC2690}
{CFDE6B77-F6EA-4C43-83BE-9B202B7F2C07} = {FF69C4FB-2589-43CE-9CB7-E21B71838AE6}
{C0025AF3-9E9C-4936-A286-C86CFD3F759F} = {10FA7376-ECEA-4A08-B3CC-0CA22DEC2690}
EndGlobalSection
Expand Down
6 changes: 4 additions & 2 deletions src/MinimalRichDomain/AggregateRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using System.Reflection;

namespace MinimalRichDomain;
public abstract class AggregateRoot<TId>
public abstract class AggregateRoot<TId> : IEntity<TId>
{
public IReadOnlyCollection<IDomainEvent> DomainEvents => _domainEvents.AsReadOnly();
public TId Id { get; }
public int CurrentVersion { get; private set; }

protected int NextVersion => CurrentVersion + 1;

private readonly List<IDomainEvent> _domainEvents;

protected AggregateRoot(TId id)
Expand Down Expand Up @@ -58,7 +60,7 @@ protected virtual void RaiseAndApplyDomainEvent(IDomainEvent domainEvent)
DomainEventTracker.RaiseDomainEvent(domainEvent);
}

public virtual void Apply(IDomainEvent domainEvent)
protected virtual void Apply(IDomainEvent domainEvent)
{
if (CanApply(domainEvent))
{
Expand Down
5 changes: 4 additions & 1 deletion src/MinimalRichDomain/IApplyEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace MinimalRichDomain;
using System.ComponentModel;

namespace MinimalRichDomain;
public interface IApplyEvent<TEvent> where TEvent : IDomainEvent
{
[EditorBrowsable(EditorBrowsableState.Never)]
void Apply(TEvent @event);
}
5 changes: 5 additions & 0 deletions src/MinimalRichDomain/IEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace MinimalRichDomain;
public interface IEntity<TId>
{
TId Id { get; }
}
2 changes: 1 addition & 1 deletion src/MinimalRichDomain/MinimalRichDomain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<PackageId>MinimalRichDomain</PackageId>
<Title>Shared kernel for a minimal event-sourced rich domain model</Title>
<Version>0.1.3-alpha</Version>
<Version>0.1.4-alpha</Version>
<Authors>Ken van Grinsven</Authors>
<Company>Grinsven Software Solutions</Company>
<Product>MinimalRichDomain</Product>
Expand Down
5 changes: 5 additions & 0 deletions test/MinimalRichDomain.Tests/AggregateRootTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public TestEntity() : base(Guid.NewGuid())

public TestEntity(IReadOnlyCollection<IDomainEvent> domainEvents) : base(Guid.NewGuid(), domainEvents) { }

public new void Apply(IDomainEvent domainEvent)
{
base.Apply(domainEvent);
}

protected override void ValidateState()
{
}
Expand Down

0 comments on commit a88f62c

Please sign in to comment.