mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Adds refactoring
This commit is contained in:
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 =====================================================================================
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggrega
|
||||
/// Aggregate Root for a media contributor.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Id}: {Name}")]
|
||||
public class MediaContributor : AggregateRoot<MediaContributorId, Guid>
|
||||
public class MediaContributor : AggregateRoot<MediaContributorId>
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
|
||||
+2
-10
@@ -7,23 +7,15 @@ namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggrega
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a media contributor.
|
||||
/// </summary>
|
||||
public sealed class MediaContributorId : AggregateRootId<Guid>
|
||||
public sealed class MediaContributorId : EntityId<Guid>
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the value of this object.
|
||||
/// </summary>
|
||||
public override Guid Value { get; protected set; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaContributorId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private MediaContributorId(Guid value)
|
||||
private MediaContributorId(Guid value) : base(value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
+6
-6
@@ -16,11 +16,11 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
|
||||
/// Aggregate root for a book.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Id}: {Title}")]
|
||||
public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
public sealed class Book : AggregateRoot<BookId>
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly List<MediaContributorId> _contributors;
|
||||
private readonly List<Rating> _ratings;
|
||||
private readonly List<BookRating> _ratings;
|
||||
private readonly List<Isbn> _isbns;
|
||||
#endregion
|
||||
|
||||
@@ -114,7 +114,7 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
/// <summary>
|
||||
/// Gets the list of ratings for this book.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Rating> Ratings
|
||||
public IReadOnlyCollection<BookRating> Ratings
|
||||
{
|
||||
get { return _ratings.AsReadOnly(); }
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
List<Rating> ratings) : base(id)
|
||||
List<BookRating> ratings) : base(id)
|
||||
{
|
||||
Id = id;
|
||||
Metadata = metadata;
|
||||
@@ -234,7 +234,7 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
List<Rating> ratings)
|
||||
List<BookRating> ratings)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new Book(
|
||||
@@ -300,7 +300,7 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
List<Rating> ratings)
|
||||
List<BookRating> ratings)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new Book(
|
||||
|
||||
+2
-10
@@ -7,23 +7,15 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a book.
|
||||
/// </summary>
|
||||
public sealed class BookId : AggregateRootId<Guid>
|
||||
public sealed class BookId : EntityId<Guid>
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="BookId"/>.
|
||||
/// </summary>
|
||||
public override Guid Value { get; protected set; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private BookId(Guid value)
|
||||
private BookId(Guid value) : base(value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\..\bin\</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\..\bin\</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ErrorOr" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ErrorOr" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user