Adds refactoring

This commit is contained in:
BinaryAlley committed 2024-08-26 23:32:38 +03:00
1 parent 8b729cc16c
commit ddfaaefa27
39 files changed
+673 -396

No files matched your search

@@ -4,20 +4,11 @@
/// Base class for all domain Aggregate Roots.
/// </summary>
/// <typeparam name="TId">The type representing the unique identifier for the Aggregate Root. It should be a non-nullable type.</typeparam>
/// <typeparam name="TIdType">The type of the unique identifier for the Aggregate Root. It should be a non-nullable type.</typeparam>
public abstract class AggregateRoot<TId, TIdType> : Entity<TId> where TId : notnull, AggregateRootId<TIdType>
where TIdType : notnull
public abstract class AggregateRoot<TId> : Entity<TId> where TId : notnull
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the unique identifier of the Aggregate Root.
/// </summary>
public new AggregateRootId<TIdType> Id { get; protected set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="AggregateRoot{TId, TIdType}"/> class.
/// Initializes a new instance of the <see cref="AggregateRoot{TId}"/> class.
/// </summary>
/// <param name="id">The id of the entity.</param>
protected AggregateRoot(TId id) : base(id)
@@ -27,7 +18,7 @@ public abstract class AggregateRoot<TId, TIdType> : Entity<TId> where TId : notn
#pragma warning disable CS8618
/// <summary>
/// Initializes a new instance of the <see cref="AggregateRoot{TId, TIdType}"/> class.
/// Initializes a new instance of the <see cref="AggregateRoot{TId}"/> class.
/// </summary>
protected AggregateRoot() // only needed during reflection
{
@@ -1,15 +0,0 @@
namespace Lumina.Domain.Common.Models.Core;
/// <summary>
/// Base identity class for all domain Aggregate Roots.
/// </summary>
/// <typeparam name="TId">The type representing the unique identifier for the Aggregate Root. It should be a non-nullable type.</typeparam>
public abstract class AggregateRootId<TId> : ValueObject where TId : notnull
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the unique identifier of the Aggregate Root.
/// </summary>
public abstract TId Value { get; protected set; }
#endregion
}
@@ -11,6 +11,16 @@ public abstract class Entity<TId> : IEquatable<Entity<TId>> where TId : notnull
/// Gets the unique identifier of the entity.
/// </summary>
public TId Id { get; protected set; }
/// <summary>
/// Gets the date and time when the entity was created.
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// Gets the date and time when the entity was last updated.
/// </summary>
public DateTime? Updated { get; set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Common.Models.Core;
/// <summary>
/// Base class for all entity identifiers.
/// </summary>
/// <typeparam name="TId">The type of the identifier.</typeparam>
[DebuggerDisplay("{Value}")]
public abstract class EntityId<TId> : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public TId Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Overload C-tor.
/// </summary>
/// <param name="value">The value representing this object.</param>
protected EntityId(TId value)
{
Value = value;
}
#pragma warning disable CS8618
/// <summary>
/// Default C-tor.
/// </summary>
protected EntityId()
{
}
#pragma warning restore CS8618
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object?> GetEqualityComponents()
{
yield return Value;
}
/// <summary>
/// Customized ToString() method.
/// </summary>
/// <returns>Custom string value showing relevant data for current class.</returns>
public override string? ToString()
{
return Value?.ToString() ?? base.ToString();
}
#endregion
}
@@ -11,7 +11,7 @@ public abstract class ValueObject : IEquatable<ValueObject>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public abstract IEnumerable<object> GetEqualityComponents();
public abstract IEnumerable<object?> GetEqualityComponents();
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
@@ -42,7 +42,7 @@ public abstract class ValueObject : IEquatable<ValueObject>
/// <param name="left">The left operand of equality.</param>
/// <param name="right">The right operand of equality.</param>
/// <returns><see langword="true"/> if <paramref name="left"/> is equal to <paramref name="right"/>, <see langword="false"/> otherwise.</returns>
public static bool operator ==(ValueObject left, ValueObject right)
public static bool operator ==(ValueObject? left, ValueObject? right)
{
return Equals(left, right);
}
@@ -53,7 +53,7 @@ public abstract class ValueObject : IEquatable<ValueObject>
/// <param name="left">The left operand of equality.</param>
/// <param name="right">The right operand of equality.</param>
/// <returns><see langword="true"/> if <paramref name="left"/> is not equal to <paramref name="right"/>, <see langword="false"/> otherwise.</returns>
public static bool operator !=(ValueObject left, ValueObject right)
public static bool operator !=(ValueObject? left, ValueObject? right)
{
return !Equals(left, right);
}
@@ -91,5 +91,14 @@ public readonly struct Optional<T>
{
return value.HasValue ? Some(value.Value) : None();
}
/// <summary>
/// Customized ToString() method.
/// </summary>
/// <returns>Custom string value showing relevant data for current class.</returns>
public override string ToString()
{
return HasValue ? Value?.ToString()! : string.Empty;
}
#endregion
}
@@ -17,17 +17,17 @@ public class LanguageInfo : ValueObject
/// <summary>
/// Gets the ISO 639-1 two-letter language code.
/// </summary>
public string LanguageCode { get; }
public string LanguageCode { get; private set; }
/// <summary>
/// Gets the full name of the language in English.
/// </summary>
public string LanguageName { get; }
public string LanguageName { get; private set; }
/// <summary>
/// Gets an optional native name of the language.
/// </summary>
public Optional<string> NativeName { get; }
public Optional<string> NativeName { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================