diff --git a/Toolbox.jpeg b/Toolbox.jpeg new file mode 100644 index 0000000..a3fdcf8 Binary files /dev/null and b/Toolbox.jpeg differ diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/IAuditableEntity.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/IAuditableEntity.cs index 77cf562..e8f84e2 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/IAuditableEntity.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/IAuditableEntity.cs @@ -1,22 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Text; +namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions; -namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions +/// +/// Represents the marker interface for auditable entities. +/// +public interface IAuditableEntity { /// - /// Represents the marker interface for auditable entities. + /// Gets the created on date and time in UTC format. /// - public interface IAuditableEntity - { - /// - /// Gets the created on date and time in UTC format. - /// - DateTime CreatedOn { get; } + DateTime CreatedOn { get; } - /// - /// Gets the modified on date and time in UTC format. - /// - DateTime? ModifiedOn { get; } - } + /// + /// Gets the modified on date and time in UTC format. + /// + DateTime? ModifiedOn { get; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/ISoftDeletableEntity.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/ISoftDeletableEntity.cs index 5de18d0..b9b0ef7 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/ISoftDeletableEntity.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/ISoftDeletableEntity.cs @@ -1,22 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Text; +namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions; -namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions +/// +/// Represents the marker interface for soft-deletable entities. +/// +public interface ISoftDeletableEntity { /// - /// Represents the marker interface for soft-deletable entities. + /// Gets the date and time in UTC format the entity was deleted on. /// - public interface ISoftDeletableEntity - { - /// - /// Gets the date and time in UTC format the entity was deleted on. - /// - DateTime? DeletedOn { get; } + DateTime? DeletedOn { get; } - /// - /// Gets a value indicating whether the entity has been deleted. - /// - bool Deleted { get; } - } + /// + /// Gets a value indicating whether the entity has been deleted. + /// + bool Deleted { get; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/TypedIdValueBase.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/TypedIdValueBase.cs new file mode 100644 index 0000000..bcde825 --- /dev/null +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Abstractions/TypedIdValueBase.cs @@ -0,0 +1,60 @@ +namespace Modular.Monolithic.Architecture.Helper.Domain.Abstractions; + +/// +/// Represents the id value entities. +/// +public abstract class TypedIdValueBase : IEquatable +{ + /// + /// Gets or sets the entity identifier. + /// + public Guid Value { get; private set; } + + protected TypedIdValueBase(Guid value) + { + if (value == Guid.Empty) + { + throw new InvalidOperationException("Id value cannot be empty!"); + } + + Value = value; + } + + /// + /// + /// + /// + /// + /// + public static bool operator ==(TypedIdValueBase left, TypedIdValueBase right) + { + if (Object.Equals(left, null)) + { + return Object.Equals(right, null); + } + else + { + return left.Equals(right); + } + } + + public static bool operator !=(TypedIdValueBase left, TypedIdValueBase right) => !(left == right); + + /// + public bool IsTransient() => Value == default; + + /// + public override bool Equals(object obj) + { + if (obj is null) + { + return false; + } + + return obj is TypedIdValueBase other && Equals(other); + } + // + public bool Equals(TypedIdValueBase other) => Value == other?.Value; + /// + public override int GetHashCode() => Value.GetHashCode(); +} diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/BusinessRules/IBusinessRule.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/BusinessRules/IBusinessRule.cs index 16ff36d..3911cdc 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/BusinessRules/IBusinessRule.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/BusinessRules/IBusinessRule.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Modular.Monolithic.Architecture.Helper.Domain.Errors; +using Modular.Monolithic.Architecture.Helper.Domain.Errors; -namespace Modular.Monolithic.Architecture.Helper.Domain.BusinessRules +namespace Modular.Monolithic.Architecture.Helper.Domain.BusinessRules; + +public interface IBusinessRule { - public interface IBusinessRule - { - bool IsFail(); - Error Error { get; } - } + bool IsFail(); + Error Error { get; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Core/AggregateRoot.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Core/AggregateRoot.cs index c55bf51..8e3b6b2 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Core/AggregateRoot.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Core/AggregateRoot.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +namespace Modular.Monolithic.Architecture.Helper.Domain.Core; -namespace Modular.Monolithic.Architecture.Helper.Domain.Core -{ - /// - /// - /// - public abstract class AggregateRoot : Entity { } -} +/// +/// +/// +public abstract class AggregateRoot : Entity { } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Core/Entity.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Core/Entity.cs index 4977db7..ad68236 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Core/Entity.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Core/Entity.cs @@ -1,135 +1,58 @@ -using System; -using System.Collections.Generic; -using Modular.Monolithic.Architecture.Helper.Domain.BusinessRules; +using Modular.Monolithic.Architecture.Helper.Domain.BusinessRules; using Modular.Monolithic.Architecture.Helper.Domain.Events; using Modular.Monolithic.Architecture.Helper.Domain.Exceptions; -namespace Modular.Monolithic.Architecture.Helper.Domain.Core +namespace Modular.Monolithic.Architecture.Helper.Domain.Core; + +/// +/// Represents the base class that all entities derive from. +/// +public abstract class Entity { + + private List _domainEvents; + /// - /// Represents the base class that all entities derive from. + /// Domain events occurred. /// - public abstract class Entity : IEquatable + public IReadOnlyCollection? DomainEvents => _domainEvents?.AsReadOnly(); + /// + /// Initializes a new instance of the class. + /// + /// + /// Required by EF Core. + /// + protected Entity() { - - private List _domainEvents; - - /// - /// Domain events occurred. - /// - public IReadOnlyCollection DomainEvents => _domainEvents?.AsReadOnly(); - /// - /// Gets or sets the entity identifier. - /// - public Guid Id { get; private set; } - /// - /// Initializes a new instance of the class. - /// - /// The entity identifier. - protected Entity(Guid id) - : this() - { - Id = id; - } - /// - /// Initializes a new instance of the class. - /// - /// - /// Required by EF Core. - /// - protected Entity() - { - } - /// - /// - /// - /// - public void AddDomainEvent(IDomainEvent eventItem) - { - _domainEvents = _domainEvents ?? new List(); - _domainEvents.Add(eventItem); - } - /// - /// - /// - /// - public void RemoveDomainEvent(IDomainEvent eventItem) - { - _domainEvents?.Remove(eventItem); - } - /// - /// - /// - public void ClearDomainEvents() - { - _domainEvents?.Clear(); - } - /// - /// - /// - /// - /// - protected void CheckRule(IBusinessRule rule) - { - if (rule.IsFail()) - { - throw new BusinessRuleValidationException(rule); - } - } - /// - /// - /// - /// - /// - /// - public static bool operator ==(Entity left, Entity right) - { - if (Object.Equals(left, null)) - return (Object.Equals(right, null)) ? true : false; - else - return left.Equals(right); - } - - public static bool operator !=(Entity left, Entity right) - { - return !(left == right); - } - - /// - public bool IsTransient() - { - return this.Id == default; - } - /// - public bool Equals(Entity other) - { - if (other is null) - { - return false; - } - - return ReferenceEquals(this, other) || Id == other.Id; - } - /// - public override bool Equals(object obj) + } + /// + /// + /// + /// + public void AddDomainEvent(IDomainEvent eventItem) + { + _domainEvents ??= []; + _domainEvents.Add(eventItem); + } + /// + /// + /// + /// + public void RemoveDomainEvent(IDomainEvent eventItem) => _domainEvents?.Remove(eventItem); + /// + /// + /// + public void ClearDomainEvents() => _domainEvents?.Clear(); + /// + /// + /// + /// + /// + protected void CheckRule(IBusinessRule rule) + { + if (rule.IsFail()) { - if (obj == null || !(obj is Entity)) - return false; - - if (Object.ReferenceEquals(this, obj)) - return true; - - if (this.GetType() != obj.GetType()) - return false; - - Entity item = (Entity)obj; - - if (item.IsTransient() || this.IsTransient()) - return false; - else - return item.Id == this.Id; + throw new BusinessRuleValidationException(rule); } - /// - public override int GetHashCode() => this.Id.GetHashCode() ^ 31; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Core/ValueObject.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Core/ValueObject.cs index 0484d8f..2626556 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Core/ValueObject.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Core/ValueObject.cs @@ -1,60 +1,54 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +namespace Modular.Monolithic.Architecture.Helper.Domain.Core; -namespace Modular.Monolithic.Architecture.Helper.Domain.Core +/// +/// +/// +public abstract class ValueObject : IEquatable { - /// - /// - /// - public abstract class ValueObject : IEquatable + public static bool operator ==(ValueObject a, ValueObject b) { - public static bool operator ==(ValueObject a, ValueObject b) + if (a is null && b is null) { - if (a is null && b is null) - { - return true; - } - - if (a is null || b is null) - { - return false; - } - - return a.Equals(b); + return true; } - public static bool operator !=(ValueObject a, ValueObject b) => !(a == b); - - /// - public bool Equals(ValueObject other) => !(other is null) && GetValues().SequenceEqual(other.GetValues()); - - /// - public override bool Equals(object obj) + if (a is null || b is null) { - if (obj == null || obj.GetType() != GetType()) - { - return false; - } + return false; + } - var other = (ValueObject)obj; + return a.Equals(b); + } - return GetValues().SequenceEqual(other.GetValues()); - } + public static bool operator !=(ValueObject a, ValueObject b) => !(a == b); - /// - public override int GetHashCode() + /// + public bool Equals(ValueObject other) => other is not null && GetValues().SequenceEqual(other.GetValues()); + + /// + public override bool Equals(object obj) + { + if (obj == null || obj.GetType() != GetType()) { - return GetValues() - .Select(x => x != null ? x.GetHashCode() : 0) - .Aggregate((x, y) => x ^ y); + return false; } - /// - /// Gets the atomic values of the value object. - /// - /// The collection of objects representing the value object values. - protected abstract IEnumerable GetValues(); + var other = (ValueObject)obj; + + return GetValues().SequenceEqual(other.GetValues()); } + + /// + public override int GetHashCode() + { + return GetValues() + .Select(x => x != null ? x.GetHashCode() : 0) + .Aggregate((x, y) => x ^ y); + } + + /// + /// Gets the atomic values of the value object. + /// + /// The collection of objects representing the value object values. + protected abstract IEnumerable GetValues(); } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Errors/Error.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Errors/Error.cs index 9ae8066..93ae616 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Errors/Error.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Errors/Error.cs @@ -1,43 +1,44 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Modular.Monolithic.Architecture.Helper.Domain.Core; +using Modular.Monolithic.Architecture.Helper.Domain.Core; -namespace Modular.Monolithic.Architecture.Helper.Domain.Errors +namespace Modular.Monolithic.Architecture.Helper.Domain.Errors; + +/// +/// Represents a concrete domain error. +/// +public sealed class Error : ValueObject { /// - /// Represents a concrete domain error. + /// Gets the empty error instance. /// - public sealed class Error : ValueObject + internal static Error None => new(string.Empty, string.Empty); + + /// + /// Initializes a new instance of the class. + /// + /// The error code. + /// The error message. + public Error(string code, string message) { - /// - /// Initializes a new instance of the class. - /// - /// The error code. - /// The error message. - public Error(string code, string message) - { - Code = code; - Message = message; - } + Code = code; + Message = message; + } - /// - /// Gets the error code. - /// - public string Code { get; } + /// + /// Gets the error code. + /// + public string Code { get; } - /// - /// Gets the error message. - /// - public string Message { get; } + /// + /// Gets the error message. + /// + public string Message { get; } - public override string ToString() => $"{Code}: {Message}"; + public override string ToString() => $"{Code}: {Message}"; - /// - protected override IEnumerable GetValues() - { - yield return Code; - yield return Message; - } + /// + protected override IEnumerable GetValues() + { + yield return Code; + yield return Message; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Events/DomainEvent.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Events/DomainEvent.cs index ee50732..19adea8 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Events/DomainEvent.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Events/DomainEvent.cs @@ -1,18 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; +namespace Modular.Monolithic.Architecture.Helper.Domain.Events; -namespace Modular.Monolithic.Architecture.Helper.Domain.Events +public class DomainEvent : IDomainEvent { - public class DomainEvent : IDomainEvent - { - public Guid Id { get; } - public DateTime OccurredOn { get; } + public Guid Id { get; } + public DateTime OccurredOn { get; } - public DomainEvent() - { - this.Id = Guid.NewGuid(); - this.OccurredOn = DateTime.UtcNow; - } + public DomainEvent() + { + Id = Guid.NewGuid(); + OccurredOn = DateTime.UtcNow; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Events/IDomainEvent.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Events/IDomainEvent.cs index 04e71d4..0760204 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Events/IDomainEvent.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Events/IDomainEvent.cs @@ -1,16 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; +using MediatR; -namespace Modular.Monolithic.Architecture.Helper.Domain.Events +namespace Modular.Monolithic.Architecture.Helper.Domain.Events; + +/// +/// Represents the interface for an event that is raised within the domain. +/// +public interface IDomainEvent : INotification { - /// - /// Represents the interface for an event that is raised within the domain. - /// - public interface IDomainEvent - { - Guid Id { get; } + Guid Id { get; } - DateTime OccurredOn { get; } - } + DateTime OccurredOn { get; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/BusinessRuleException.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/BusinessRuleException.cs index a95b081..4269dae 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/BusinessRuleException.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/BusinessRuleException.cs @@ -1,20 +1,16 @@ using Modular.Monolithic.Architecture.Helper.Domain.BusinessRules; -namespace Modular.Monolithic.Architecture.Helper.Domain.Exceptions -{ - public class BusinessRuleValidationException : DomainException - { - public IBusinessRule BrokenRule { get; } +namespace Modular.Monolithic.Architecture.Helper.Domain.Exceptions; - public BusinessRuleValidationException(IBusinessRule brokenRule) - : base(brokenRule.Error) - { - BrokenRule = brokenRule; - } +public class BusinessRuleValidationException : DomainException +{ + public IBusinessRule BrokenRule { get; } - public override string ToString() - { - return $"{BrokenRule.GetType().FullName}: {BrokenRule.Error}"; - } + public BusinessRuleValidationException(IBusinessRule brokenRule) + : base(brokenRule.Error) + { + BrokenRule = brokenRule; } + + public override string ToString() => $"{BrokenRule.GetType().FullName}: {BrokenRule.Error}"; } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/DomainException.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/DomainException.cs index bbdb115..92736cb 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/DomainException.cs +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Exceptions/DomainException.cs @@ -1,24 +1,24 @@ -using System; -using Modular.Monolithic.Architecture.Helper.Domain.Errors; +using Modular.Monolithic.Architecture.Helper.Domain.Errors; -namespace Modular.Monolithic.Architecture.Helper.Domain.Exceptions +namespace Modular.Monolithic.Architecture.Helper.Domain.Exceptions; + +/// +/// Represents an exception that occurred in the domain. +/// +public class DomainException : Exception { /// - /// Represents an exception that occurred in the domain. + /// Initializes a new instance of the class. /// - public class DomainException : Exception + /// The error containing the information about what happened. + public DomainException(Error error) + : base(error.Message) { - /// - /// Initializes a new instance of the class. - /// - /// The error containing the information about what happened. - public DomainException(Error error) - : base(error.Message) - => Error = error; - - /// - /// Gets the error. - /// - public Error Error { get; } + Error = error; } + + /// + /// Gets the error. + /// + public Error Error { get; } } diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Modular.Monolithic.Architecture.Helper.Domain.csproj b/src/Modular.Monolithic.Architecture.Helper.Domain/Modular.Monolithic.Architecture.Helper.Domain.csproj index 3f611aa..cee7481 100644 --- a/src/Modular.Monolithic.Architecture.Helper.Domain/Modular.Monolithic.Architecture.Helper.Domain.csproj +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Modular.Monolithic.Architecture.Helper.Domain.csproj @@ -1,15 +1,42 @@  - netstandard2.1 - enable + net6.0;net7.0;net8.0 + enable + enable + true + latest + Modular.Monolithic.Architecture.Helper.Domain + Nicholas Gueli + Nicholas Gueli + Library Modular Monolithic Architecture helper for domain layer + Library Modular Monolithic Architecture helper for domain layer + A small library to improve and simplify the development of applications based on the Modular Monolith architecture for domain layer + MIT + https://github.com/niko-olas/Modular.Monolithic.Architecture.Helper + Toolbox.jpeg + csharp visualstudio aspnetcore utilities helper modular-monolithic + git + https://github.com/niko-olas/Modular.Monolithic.Architecture.Helper.git + master + README.md + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + True + + + + + + diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Results/Result.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Results/Result.cs new file mode 100644 index 0000000..f0b4d99 --- /dev/null +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Results/Result.cs @@ -0,0 +1,110 @@ +using Modular.Monolithic.Architecture.Helper.Domain.Errors; + +namespace Modular.Monolithic.Architecture.Helper.Domain.Results; + +/// +/// Represents a result of some operation, with status information and possibly an error. +/// +public class Result +{ + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// The flag indicating if the result is successful. + /// The error. + protected Result(bool isSuccess, Error error) + { + if (isSuccess && error != Error.None) + { + throw new InvalidOperationException(); + } + + if (!isSuccess && error == Error.None) + { + throw new InvalidOperationException(); + } + + IsSuccess = isSuccess; + Error = error; + } + + /// + /// Gets a value indicating whether the result is a success result. + /// + public bool IsSuccess { get; } + + /// + /// Gets a value indicating whether the result is a failure result. + /// + public bool IsFailure => !IsSuccess; + + /// + /// Gets the error. + /// + public Error Error { get; } + + /// + /// Returns a success . + /// + /// A new instance of with the success flag set. + public static Result Success() => new(true, Error.None); + + /// + /// Returns a success with the specified value. + /// + /// The result type. + /// The result value. + /// A new instance of with the success flag set. + public static Result Success(TValue value) => new(value, true, Error.None); + + /// + /// Creates a new with the specified nullable value and the specified error. + /// + /// The result type. + /// The result value. + /// The error in case the value is null. + /// A new instance of with the specified value or an error. + public static Result Create(TValue value, Error error) + where TValue : class + => value is null ? Failure(error) : Success(value); + + /// + /// Returns a failure with the specified error. + /// + /// The error. + /// A new instance of with the specified error and failure flag set. + public static Result Failure(Error error) => new(false, error); + + /// + /// Returns a failure with the specified error. + /// + /// The result type. + /// The error. + /// A new instance of with the specified error and failure flag set. + /// + /// We're purposefully ignoring the nullable assignment here because the API will never allow it to be accessed. + /// The value is accessed through a method that will throw an exception if the result is a failure result. + /// + public static Result Failure(Error error) => new(default!, false, error); + + /// + /// Returns the first failure from the specified . + /// If there is no failure, a success is returned. + /// + /// The results array. + /// + /// The first failure from the specified array,or a success it does not exist. + /// + public static Result FirstFailureOrSuccess(params Result[] results) + { + foreach (var result in results) + { + if (result.IsFailure) + { + return result; + } + } + + return Success(); + } +} diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/Results/ResultT.cs b/src/Modular.Monolithic.Architecture.Helper.Domain/Results/ResultT.cs new file mode 100644 index 0000000..4b7d05e --- /dev/null +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/Results/ResultT.cs @@ -0,0 +1,35 @@ +using Modular.Monolithic.Architecture.Helper.Domain.Errors; + +namespace Modular.Monolithic.Architecture.Helper.Domain.Results; + +/// +/// Represents the result of some operation, with status information and possibly a value and an error. +/// +/// The result value type. +public class Result : Result +{ + private readonly TValue _value; + + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// The result value. + /// The flag indicating if the result is successful. + /// The error. + protected internal Result(TValue value, bool isSuccess, Error error) + : base(isSuccess, error) + { + _value = value; + } + + public static implicit operator Result(TValue value) => Success(value); + + /// + /// Gets the result value if the result is successful, otherwise throws an exception. + /// + /// The result value if the result is successful. + /// when is true. + public TValue Value => IsSuccess + ? _value + : throw new InvalidOperationException("The value of a failure result can not be accessed."); +} diff --git a/src/Modular.Monolithic.Architecture.Helper.Domain/SimpleAuthentication.xml b/src/Modular.Monolithic.Architecture.Helper.Domain/SimpleAuthentication.xml new file mode 100644 index 0000000..3b2e68d --- /dev/null +++ b/src/Modular.Monolithic.Architecture.Helper.Domain/SimpleAuthentication.xml @@ -0,0 +1,283 @@ + + + + Modular.Monolithic.Architecture.Helper.Domain + + + + + Represents the marker interface for auditable entities. + + + + + Gets the created on date and time in UTC format. + + + + + Gets the modified on date and time in UTC format. + + + + + Represents the marker interface for soft-deletable entities. + + + + + Gets the date and time in UTC format the entity was deleted on. + + + + + Gets a value indicating whether the entity has been deleted. + + + + + Represents the id value entities. + + + + + Gets or sets the entity identifier. + + + + + + + + + + + + + + + + + + + + + + + + + + + Represents the base class that all entities derive from. + + + + + Domain events occurred. + + + + + Initializes a new instance of the class. + + + Required by EF Core. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the atomic values of the value object. + + The collection of objects representing the value object values. + + + + Represents a concrete domain error. + + + + + Gets the empty error instance. + + + + + Initializes a new instance of the class. + + The error code. + The error message. + + + + Gets the error code. + + + + + Gets the error message. + + + + + + + + Represents the interface for an event that is raised within the domain. + + + + + Represents an exception that occurred in the domain. + + + + + Initializes a new instance of the class. + + The error containing the information about what happened. + + + + Gets the error. + + + + + Represents a result of some operation, with status information and possibly an error. + + + + + Initializes a new instance of the class with the specified parameters. + + The flag indicating if the result is successful. + The error. + + + + Gets a value indicating whether the result is a success result. + + + + + Gets a value indicating whether the result is a failure result. + + + + + Gets the error. + + + + + Returns a success . + + A new instance of with the success flag set. + + + + Returns a success with the specified value. + + The result type. + The result value. + A new instance of with the success flag set. + + + + Creates a new with the specified nullable value and the specified error. + + The result type. + The result value. + The error in case the value is null. + A new instance of with the specified value or an error. + + + + Returns a failure with the specified error. + + The error. + A new instance of with the specified error and failure flag set. + + + + Returns a failure with the specified error. + + The result type. + The error. + A new instance of with the specified error and failure flag set. + + We're purposefully ignoring the nullable assignment here because the API will never allow it to be accessed. + The value is accessed through a method that will throw an exception if the result is a failure result. + + + + + Returns the first failure from the specified . + If there is no failure, a success is returned. + + The results array. + + The first failure from the specified array,or a success it does not exist. + + + + + Represents the result of some operation, with status information and possibly a value and an error. + + The result value type. + + + + Initializes a new instance of the class with the specified parameters. + + The result value. + The flag indicating if the result is successful. + The error. + + + + Gets the result value if the result is successful, otherwise throws an exception. + + The result value if the result is successful. + when is true. + + +