Skip to content

Commit

Permalink
Refactor entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken van Grinsven committed Jun 20, 2024
1 parent fd8f35d commit 863b414
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A minimal impact shared kernel library for basic event-sourced domain models.

### Usage
```csharp
public partial class BlogPost : Aggregate<BlogPostId>
public partial class BlogPost : EventSourcedEntity<BlogPostId>
{
public Title Title { get; private set; }
public uint Views { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using MinimalDomainEvents.Core;

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

protected int NextVersion => CurrentVersion + 1;
public int NextVersion => CurrentVersion + 1;

private readonly List<IDomainEvent> _domainEvents;

protected Aggregate(TId id)
protected EventSourcedEntity(TId id)
{
Id = id;
_domainEvents = new();
}

protected Aggregate(TId id, IReadOnlyCollection<IDomainEvent> domainEvents)
protected EventSourcedEntity(TId id, IReadOnlyCollection<IDomainEvent> domainEvents)
{
Id = id;
_domainEvents = new(domainEvents.Count);
Expand Down
4 changes: 4 additions & 0 deletions src/MinimalRichDomain/IAggregate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace MinimalRichDomain
{
internal interface IAggregate<out TId> : IEntity<TId> { }
}
2 changes: 1 addition & 1 deletion src/MinimalRichDomain/IEntity.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace MinimalRichDomain;
public interface IEntity<TId>
public interface IEntity<out 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>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>Ken van Grinsven</Authors>
<Company>Grinsven Software Solutions</Company>
<Product>MinimalRichDomain</Product>
Expand Down

0 comments on commit 863b414

Please sign in to comment.