Skip to content

Commit adcca03

Browse files
authored
Merge pull request #9 from niko-olas/release/1.0
Release/1.0
2 parents afcdb35 + 22a5c1f commit adcca03

17 files changed

+713
-311
lines changed

Toolbox.jpeg

61.7 KB
Loading
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions;
42

5-
namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions
3+
/// <summary>
4+
/// Represents the marker interface for auditable entities.
5+
/// </summary>
6+
public interface IAuditableEntity
67
{
78
/// <summary>
8-
/// Represents the marker interface for auditable entities.
9+
/// Gets the created on date and time in UTC format.
910
/// </summary>
10-
public interface IAuditableEntity
11-
{
12-
/// <summary>
13-
/// Gets the created on date and time in UTC format.
14-
/// </summary>
15-
DateTime CreatedOn { get; }
11+
DateTime CreatedOn { get; }
1612

17-
/// <summary>
18-
/// Gets the modified on date and time in UTC format.
19-
/// </summary>
20-
DateTime? ModifiedOn { get; }
21-
}
13+
/// <summary>
14+
/// Gets the modified on date and time in UTC format.
15+
/// </summary>
16+
DateTime? ModifiedOn { get; }
2217
}
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions;
42

5-
namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions
3+
/// <summary>
4+
/// Represents the marker interface for soft-deletable entities.
5+
/// </summary>
6+
public interface ISoftDeletableEntity
67
{
78
/// <summary>
8-
/// Represents the marker interface for soft-deletable entities.
9+
/// Gets the date and time in UTC format the entity was deleted on.
910
/// </summary>
10-
public interface ISoftDeletableEntity
11-
{
12-
/// <summary>
13-
/// Gets the date and time in UTC format the entity was deleted on.
14-
/// </summary>
15-
DateTime? DeletedOn { get; }
11+
DateTime? DeletedOn { get; }
1612

17-
/// <summary>
18-
/// Gets a value indicating whether the entity has been deleted.
19-
/// </summary>
20-
bool Deleted { get; }
21-
}
13+
/// <summary>
14+
/// Gets a value indicating whether the entity has been deleted.
15+
/// </summary>
16+
bool Deleted { get; }
2217
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions;
2+
3+
/// <summary>
4+
/// Represents the id value entities.
5+
/// </summary>
6+
public abstract class TypedIdValueBase : IEquatable<TypedIdValueBase>
7+
{
8+
/// <summary>
9+
/// Gets or sets the entity identifier.
10+
/// </summary>
11+
public Guid Value { get; private set; }
12+
13+
protected TypedIdValueBase(Guid value)
14+
{
15+
if (value == Guid.Empty)
16+
{
17+
throw new InvalidOperationException("Id value cannot be empty!");
18+
}
19+
20+
Value = value;
21+
}
22+
23+
/// <summary>
24+
///
25+
/// </summary>
26+
/// <param name="left"></param>
27+
/// <param name="right"></param>
28+
/// <returns></returns>
29+
public static bool operator ==(TypedIdValueBase left, TypedIdValueBase right)
30+
{
31+
if (Object.Equals(left, null))
32+
{
33+
return Object.Equals(right, null);
34+
}
35+
else
36+
{
37+
return left.Equals(right);
38+
}
39+
}
40+
41+
public static bool operator !=(TypedIdValueBase left, TypedIdValueBase right) => !(left == right);
42+
43+
/// <inheritdoc />
44+
public bool IsTransient() => Value == default;
45+
46+
/// <inheritdoc />
47+
public override bool Equals(object obj)
48+
{
49+
if (obj is null)
50+
{
51+
return false;
52+
}
53+
54+
return obj is TypedIdValueBase other && Equals(other);
55+
}
56+
// <inheritdoc />
57+
public bool Equals(TypedIdValueBase other) => Value == other?.Value;
58+
/// <inheritdoc />
59+
public override int GetHashCode() => Value.GetHashCode();
60+
}
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
using Modular.Monolithic.Architecture.Helper.Domain.Errors;
1+
using Modular.Monolithic.Architecture.Helper.Domain.Errors;
52

6-
namespace Modular.Monolithic.Architecture.Helper.Domain.BusinessRules
3+
namespace Modular.Monolithic.Architecture.Helper.Domain.BusinessRules;
4+
5+
public interface IBusinessRule
76
{
8-
public interface IBusinessRule
9-
{
10-
bool IsFail();
11-
Error Error { get; }
12-
}
7+
bool IsFail();
8+
Error Error { get; }
139
}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
namespace Modular.Monolithic.Architecture.Helper.Domain.Core;
42

5-
namespace Modular.Monolithic.Architecture.Helper.Domain.Core
6-
{
7-
/// <summary>
8-
///
9-
/// </summary>
10-
public abstract class AggregateRoot : Entity { }
11-
}
3+
/// <summary>
4+
///
5+
/// </summary>
6+
public abstract class AggregateRoot : Entity { }
Lines changed: 47 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,58 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using Modular.Monolithic.Architecture.Helper.Domain.BusinessRules;
1+
using Modular.Monolithic.Architecture.Helper.Domain.BusinessRules;
42
using Modular.Monolithic.Architecture.Helper.Domain.Events;
53
using Modular.Monolithic.Architecture.Helper.Domain.Exceptions;
64

7-
namespace Modular.Monolithic.Architecture.Helper.Domain.Core
5+
namespace Modular.Monolithic.Architecture.Helper.Domain.Core;
6+
7+
/// <summary>
8+
/// Represents the base class that all entities derive from.
9+
/// </summary>
10+
public abstract class Entity
811
{
12+
13+
private List<IDomainEvent> _domainEvents;
14+
915
/// <summary>
10-
/// Represents the base class that all entities derive from.
16+
/// Domain events occurred.
1117
/// </summary>
12-
public abstract class Entity : IEquatable<Entity>
18+
public IReadOnlyCollection<IDomainEvent>? DomainEvents => _domainEvents?.AsReadOnly();
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="Entity"/> class.
21+
/// </summary>
22+
/// <remarks>
23+
/// Required by EF Core.
24+
/// </remarks>
25+
protected Entity()
1326
{
14-
15-
private List<IDomainEvent> _domainEvents;
16-
17-
/// <summary>
18-
/// Domain events occurred.
19-
/// </summary>
20-
public IReadOnlyCollection<IDomainEvent> DomainEvents => _domainEvents?.AsReadOnly();
21-
/// <summary>
22-
/// Gets or sets the entity identifier.
23-
/// </summary>
24-
public Guid Id { get; private set; }
25-
/// <summary>
26-
/// Initializes a new instance of the <see cref="Entity"/> class.
27-
/// </summary>
28-
/// <param name="id">The entity identifier.</param>
29-
protected Entity(Guid id)
30-
: this()
31-
{
32-
Id = id;
33-
}
34-
/// <summary>
35-
/// Initializes a new instance of the <see cref="Entity"/> class.
36-
/// </summary>
37-
/// <remarks>
38-
/// Required by EF Core.
39-
/// </remarks>
40-
protected Entity()
41-
{
42-
}
43-
/// <summary>
44-
///
45-
/// </summary>
46-
/// <param name="eventItem"></param>
47-
public void AddDomainEvent(IDomainEvent eventItem)
48-
{
49-
_domainEvents = _domainEvents ?? new List<IDomainEvent>();
50-
_domainEvents.Add(eventItem);
51-
}
52-
/// <summary>
53-
///
54-
/// </summary>
55-
/// <param name="eventItem"></param>
56-
public void RemoveDomainEvent(IDomainEvent eventItem)
57-
{
58-
_domainEvents?.Remove(eventItem);
59-
}
60-
/// <summary>
61-
///
62-
/// </summary>
63-
public void ClearDomainEvents()
64-
{
65-
_domainEvents?.Clear();
66-
}
67-
/// <summary>
68-
///
69-
/// </summary>
70-
/// <param name="rule"></param>
71-
/// <exception cref="BusinessRuleValidationException"></exception>
72-
protected void CheckRule(IBusinessRule rule)
73-
{
74-
if (rule.IsFail())
75-
{
76-
throw new BusinessRuleValidationException(rule);
77-
}
78-
}
79-
/// <summary>
80-
///
81-
/// </summary>
82-
/// <param name="left"></param>
83-
/// <param name="right"></param>
84-
/// <returns></returns>
85-
public static bool operator ==(Entity left, Entity right)
86-
{
87-
if (Object.Equals(left, null))
88-
return (Object.Equals(right, null)) ? true : false;
89-
else
90-
return left.Equals(right);
91-
}
92-
93-
public static bool operator !=(Entity left, Entity right)
94-
{
95-
return !(left == right);
96-
}
97-
98-
/// <inheritdoc />
99-
public bool IsTransient()
100-
{
101-
return this.Id == default;
102-
}
103-
/// <inheritdoc />
104-
public bool Equals(Entity other)
105-
{
106-
if (other is null)
107-
{
108-
return false;
109-
}
110-
111-
return ReferenceEquals(this, other) || Id == other.Id;
112-
}
113-
/// <inheritdoc />
114-
public override bool Equals(object obj)
27+
}
28+
/// <summary>
29+
///
30+
/// </summary>
31+
/// <param name="eventItem"></param>
32+
public void AddDomainEvent(IDomainEvent eventItem)
33+
{
34+
_domainEvents ??= [];
35+
_domainEvents.Add(eventItem);
36+
}
37+
/// <summary>
38+
///
39+
/// </summary>
40+
/// <param name="eventItem"></param>
41+
public void RemoveDomainEvent(IDomainEvent eventItem) => _domainEvents?.Remove(eventItem);
42+
/// <summary>
43+
///
44+
/// </summary>
45+
public void ClearDomainEvents() => _domainEvents?.Clear();
46+
/// <summary>
47+
///
48+
/// </summary>
49+
/// <param name="rule"></param>
50+
/// <exception cref="BusinessRuleValidationException"></exception>
51+
protected void CheckRule(IBusinessRule rule)
52+
{
53+
if (rule.IsFail())
11554
{
116-
if (obj == null || !(obj is Entity))
117-
return false;
118-
119-
if (Object.ReferenceEquals(this, obj))
120-
return true;
121-
122-
if (this.GetType() != obj.GetType())
123-
return false;
124-
125-
Entity item = (Entity)obj;
126-
127-
if (item.IsTransient() || this.IsTransient())
128-
return false;
129-
else
130-
return item.Id == this.Id;
55+
throw new BusinessRuleValidationException(rule);
13156
}
132-
/// <inheritdoc />
133-
public override int GetHashCode() => this.Id.GetHashCode() ^ 31;
13457
}
13558
}

0 commit comments

Comments
 (0)