Skip to content

Commit 40b2001

Browse files
committed
Renamed Aggregate to AggregateRoot and update ValueObject
1 parent 7644d3f commit 40b2001

File tree

10 files changed

+43
-37
lines changed

10 files changed

+43
-37
lines changed

Src/Aggregate.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Src/AggregateRoot.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Xer.DomainDriven
4+
{
5+
public abstract class AggregateRoot<TId> : Entity<TId>, IAggregateRoot<TId> where TId : IEquatable<TId>
6+
{
7+
public AggregateRoot(TId aggregateId)
8+
: base(aggregateId)
9+
{
10+
}
11+
}
12+
}

Src/Entity.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ namespace Xer.DomainDriven
55
public abstract class Entity<TId> : IEntity<TId> where TId : IEquatable<TId>
66
{
77
/// <summary>
8-
/// Unique identifier.
8+
/// Unique ID.
99
/// </summary>
1010
public TId Id { get; protected set; }
1111

1212
/// <summary>
13-
/// Date when object was created.
13+
/// Date created.
1414
/// </summary>
1515
public DateTime Created { get; protected set; }
1616

1717
/// <summary>
18-
/// Date when object3 was last updated.
18+
/// Date updated.
1919
/// </summary>
2020
public DateTime Updated { get; protected set; }
2121

2222
/// <summary>
2323
/// Constructor.
2424
/// </summary>
25-
/// <param name="entityId">ID.</param>
25+
/// <param name="entityId">ID of entity.</param>
2626
public Entity(TId entityId)
2727
{
2828
Id = entityId;

Src/IAggregate.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

Src/IAggregateRoot.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Xer.DomainDriven
4+
{
5+
public interface IAggregateRoot<TId> : IEntity<TId> where TId : IEquatable<TId>
6+
{
7+
}
8+
}

Src/Repositories/IAggregateAsyncRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Xer.DomainDriven.Repositories
66
{
7-
public interface IAggregateAsyncRepository<TAggregate, TAggregateId> where TAggregate : IAggregate<TAggregateId>
7+
public interface IAggregateAsyncRepository<TAggregate, TAggregateId> where TAggregate : IAggregateRoot<TAggregateId>
88
where TAggregateId : IEquatable<TAggregateId>
99
{
1010
Task SaveAsync(TAggregate aggregate, CancellationToken cancellationToken = default(CancellationToken));

Src/Repositories/IAggregateRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Xer.DomainDriven.Repositories
44
{
5-
public interface IAggregateRepository<TAggregate, TAggregateId> where TAggregate : IAggregate<TAggregateId>
5+
public interface IAggregateRepository<TAggregate, TAggregateId> where TAggregate : IAggregateRoot<TAggregateId>
66
where TAggregateId : IEquatable<TAggregateId>
77
{
88
void Save(TAggregate aggregate);

Src/Repositories/InMemoryAggregateRepository.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
54
using System.Threading;
65
using System.Threading.Tasks;
76
using Xer.DomainDriven.Exceptions;
87

98
namespace Xer.DomainDriven.Repositories
109
{
1110
public class InMemoryAggregateRepository<TAggregate> : InMemoryAggregateRepository<TAggregate, Guid>
12-
where TAggregate : IAggregate<Guid>
11+
where TAggregate : IAggregateRoot<Guid>
1312
{
1413
public InMemoryAggregateRepository()
1514
{
@@ -22,7 +21,7 @@ public InMemoryAggregateRepository(bool throwIfAggregateIsNotFound) : base(throw
2221

2322
public class InMemoryAggregateRepository<TAggregate, TAggregateId> : IAggregateRepository<TAggregate, TAggregateId>,
2423
IAggregateAsyncRepository<TAggregate, TAggregateId>
25-
where TAggregate : IAggregate<TAggregateId>
24+
where TAggregate : IAggregateRoot<TAggregateId>
2625
where TAggregateId : IEquatable<TAggregateId>
2726
{
2827
#region Declarations

Src/ValueObject.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ public override int GetHashCode()
6868

6969
#region HashCode Class
7070

71-
protected class HashCode
71+
protected struct HashCode
7272
{
7373
private readonly int _value;
7474

75-
public HashCode(params object[] valueObjectFields)
75+
private HashCode(object[] fields)
7676
{
7777
unchecked
78-
{
79-
int hash = 19;
78+
{
79+
int hash = fields.Length > 0 ? 19 : 0;
8080

81-
foreach(object field in valueObjectFields)
81+
for (int i = 0; fields.Length > 0; i++)
8282
{
83-
hash = hash * 486187739 + field.GetHashCode();
83+
hash = hash * 486187739 + fields[i].GetHashCode();
8484
}
8585

8686
_value = hash;
@@ -91,6 +91,11 @@ public static implicit operator int(HashCode hashCode)
9191
{
9292
return hashCode._value;
9393
}
94+
95+
public static HashCode From(object field, params object[] otherFields)
96+
{
97+
return new HashCode(otherFields.Length > 0 ? new[] { field, otherFields } : new[] { field });
98+
}
9499
}
95100

96101
#endregion HashCode Class

Src/Xer.DomainDriven.nuspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>Xer.DomainDriven</id>
5-
<version>0.1.0</version>
5+
<version>0.1.1</version>
66
<title>Xer.DomainDriven</title>
77
<authors>jeyjeyemem</authors>
88
<owners>jeyjeyemem</owners>
@@ -11,7 +11,9 @@
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>DDD entities and marker interfaces.</description>
1313
<summary>DDD entities and marker interfaces</summary>
14-
<releaseNotes>Initial release.</releaseNotes>
14+
<releaseNotes>
15+
- Renamed Aggregate to AggregateRoot. - Update implementation of ValueObject.
16+
</releaseNotes>
1517
<copyright>Copyright 2017</copyright>
1618
<tags>DDD</tags>
1719
</metadata>

0 commit comments

Comments
 (0)