Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDD improvements #453

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CSharpFunctionalExtensions/AggregateRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;

namespace CSharpFunctionalExtensions
{
public abstract class AggregateRoot<TId, TDomainEvent> : Entity<TId>, IAggregateRoot<TDomainEvent>
{
private readonly List<TDomainEvent> _domainEvents = new List<TDomainEvent>();
public virtual IEnumerable<TDomainEvent> DomainEvents => _domainEvents;

protected virtual void Raise(TDomainEvent newEvent)
{
_domainEvents.Add(newEvent);
}

protected virtual void ClearEvents()
{
_domainEvents.Clear();
}
}
}
4 changes: 2 additions & 2 deletions CSharpFunctionalExtensions/Entity/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CSharpFunctionalExtensions
{
public abstract class Entity<TId>
public abstract class Entity<TId> : IEntity<TId>
{
public virtual TId Id { get; protected set; }

Expand Down Expand Up @@ -30,7 +30,7 @@ public override bool Equals(object obj)
return Id.Equals(other.Id);
}

private bool IsTransient()
public bool IsTransient()
{
return Id is null || Id.Equals(default(TId));
}
Expand Down
10 changes: 10 additions & 0 deletions CSharpFunctionalExtensions/Entity/IEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CSharpFunctionalExtensions
{
public interface IEntity<TId>
{
TId Id { get; }
bool Equals(object obj);
bool IsTransient();
int GetHashCode();
}
}
9 changes: 9 additions & 0 deletions CSharpFunctionalExtensions/IAggregateRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace CSharpFunctionalExtensions
{
public interface IAggregateRoot<TDomainEvent>
{
IEnumerable<TDomainEvent> DomainEvents { get; }
}
}