feat: base domain
This commit is contained in:
@@ -12,9 +12,14 @@ namespace Bahla.Domain.Builders
|
|||||||
=> !string.IsNullOrEmpty(entity._roleName) && !string.IsNullOrWhiteSpace(entity._roleName);
|
=> !string.IsNullOrEmpty(entity._roleName) && !string.IsNullOrWhiteSpace(entity._roleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal sealed class RoleValueMaskIsNotZeroSpecification : CompositeSpecification<RoleBuilder>
|
||||||
|
{
|
||||||
|
public override bool IsSatisfiedBy(RoleBuilder entity)
|
||||||
|
=> entity._valueMask != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public sealed class RoleBuilder : IRoleBuilder
|
public sealed class RoleBuilder : IRoleBuilder
|
||||||
{
|
{
|
||||||
internal Identifier _identifier = Identifier.Generate;
|
internal Identifier _identifier = Identifier.Generate;
|
||||||
|
|
||||||
internal string _roleName = string.Empty;
|
internal string _roleName = string.Empty;
|
||||||
@@ -22,14 +27,8 @@ namespace Bahla.Domain.Builders
|
|||||||
internal uint _valueMask;
|
internal uint _valueMask;
|
||||||
|
|
||||||
public Role Build()
|
public Role Build()
|
||||||
{
|
=> new RoleNameIsNotEmptySpecification()
|
||||||
if (new RoleNameIsNotEmptySpecification()
|
.IsSatisfiedBy(this) ? new Role(this) : throw new EntityBuilderException("Role name cannot be null or empty");
|
||||||
.IsSatisfiedBy(this)) {
|
|
||||||
return new Role(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new EntityBuilderException("Role name cannot be null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRoleBuilder WithIdentifier(Identifier identifier)
|
public IRoleBuilder WithIdentifier(Identifier identifier)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ using Bahla.Domain.Specifications.Base;
|
|||||||
|
|
||||||
namespace Bahla.Domain.Specifications
|
namespace Bahla.Domain.Specifications
|
||||||
{
|
{
|
||||||
public sealed class AndNotSpecification<T>(ISpecification<T> left, ISpecification<T> right) : CompositeSpecification<T> where T : class
|
public sealed class AndNotSpecification<T>(IEntitySpecification<T> left, IEntitySpecification<T> right) : CompositeSpecification<T> where T : IEntity
|
||||||
{
|
{
|
||||||
private readonly ISpecification<T> _left = left;
|
private readonly IEntitySpecification<T> _left = left;
|
||||||
private readonly ISpecification<T> _right = right;
|
private readonly IEntitySpecification<T> _right = right;
|
||||||
|
|
||||||
public override bool IsSatisfiedBy(T entity)
|
public override bool IsSatisfiedBy(T entity)
|
||||||
=> _left.IsSatisfiedBy(entity) && !_right.IsSatisfiedBy(entity);
|
=> _left.IsSatisfiedBy(entity) && !_right.IsSatisfiedBy(entity);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using Bahla.Domain.Specifications.Base;
|
using Bahla.Domain.Entities.Base;
|
||||||
|
using Bahla.Domain.Specifications.Base;
|
||||||
|
|
||||||
namespace Bahla.Domain.Specifications
|
namespace Bahla.Domain.Specifications
|
||||||
{
|
{
|
||||||
public sealed class AndSpecification<T>(ISpecification<T> left, ISpecification<T> right) : CompositeSpecification<T> where T : class
|
public sealed class AndSpecification<T>(IEntitySpecification<T> left, IEntitySpecification<T> right) : CompositeSpecification<T> where T : IEntity
|
||||||
{
|
{
|
||||||
private readonly ISpecification<T> _left = left;
|
private readonly IEntitySpecification<T> _left = left;
|
||||||
private readonly ISpecification<T> _right = right;
|
private readonly IEntitySpecification<T> _right = right;
|
||||||
public override bool IsSatisfiedBy(T entity)
|
public override bool IsSatisfiedBy(T entity)
|
||||||
=> _left.IsSatisfiedBy(entity) && _right.IsSatisfiedBy(entity);
|
=> _left.IsSatisfiedBy(entity) && _right.IsSatisfiedBy(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
namespace Bahla.Domain.Specifications.Base
|
using Bahla.Domain.Entities.Base;
|
||||||
|
using Bahla.Domain.Specifications.Base;
|
||||||
|
|
||||||
|
namespace Bahla.Domain.Specifications
|
||||||
{
|
{
|
||||||
public abstract class CompositeSpecification<T> : ISpecification<T> where T : class
|
public abstract class CompositeSpecification<T> : IEntitySpecification<T> where T : IEntity
|
||||||
{
|
{
|
||||||
public abstract bool IsSatisfiedBy(T entity);
|
public abstract bool IsSatisfiedBy(T entity);
|
||||||
public ISpecification<T> And(ISpecification<T> other)
|
|
||||||
=> new AndSpecification<T>(this, other);
|
public IEntitySpecification<T> And(IEntitySpecification<T> specification)
|
||||||
public ISpecification<T> AndNot(ISpecification<T> other)
|
=> new AndSpecification(this, specification);
|
||||||
=> new AndNotSpecification<T>(this, other);
|
|
||||||
public ISpecification<T> Not()
|
public IEntitySpecification<T> AndNot(IEntitySpecification<T> specification)
|
||||||
=> new NotSpecification<T>(this);
|
=> new AndNotSpecification(this, specification);
|
||||||
public ISpecification<T> Or(ISpecification<T> other)
|
public IEntitySpecification<T> Not()
|
||||||
=> new OrSpecification<T>(this, other);
|
=> new NotSpecification(this);
|
||||||
public ISpecification<T> OrNot(ISpecification<T> other)
|
|
||||||
=> new OrNotSpecification<T>(this, other);
|
public IEntitySpecification<T> Or(IEntitySpecification<T> specification)
|
||||||
|
=> new OrSpecification(this, specification);
|
||||||
|
|
||||||
|
IEntitySpecification<T> OrNot(IEntitySpecification<T> specification)
|
||||||
|
=> new OrNotSpecification(this, specification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/Bahla.Domain/Specifications/Base/IEntitySpecification.cs
Normal file
15
src/Bahla.Domain/Specifications/Base/IEntitySpecification.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Bahla.Domain.Entities.Base;
|
||||||
|
|
||||||
|
namespace Bahla.Domain.Specifications.Base
|
||||||
|
{
|
||||||
|
public interface IEntitySpecification<T> where T : IEntity
|
||||||
|
{
|
||||||
|
bool IsSatisfiedBy(T entity);
|
||||||
|
IEntitySpecification<T> And(IEntitySpecification<T> other);
|
||||||
|
IEntitySpecification<T> AndNot(IEntitySpecification<T> other);
|
||||||
|
IEntitySpecification<T> Or(IEntitySpecification<T> other);
|
||||||
|
IEntitySpecification<T> OrNot(IEntitySpecification<T> other);
|
||||||
|
IEntitySpecification<T> Not();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace Bahla.Domain.Specifications.Base
|
|
||||||
{
|
|
||||||
public interface ISpecification<T> where T : class
|
|
||||||
{
|
|
||||||
bool IsSatisfiedBy(T entity);
|
|
||||||
ISpecification<T> And(ISpecification<T> other);
|
|
||||||
ISpecification<T> AndNot(ISpecification<T> other);
|
|
||||||
ISpecification<T> Or(ISpecification<T> other);
|
|
||||||
ISpecification<T> OrNot(ISpecification<T> other);
|
|
||||||
ISpecification<T> Not();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,9 +3,9 @@ using Bahla.Domain.Specifications.Base;
|
|||||||
|
|
||||||
namespace Bahla.Domain.Specifications
|
namespace Bahla.Domain.Specifications
|
||||||
{
|
{
|
||||||
public sealed class NotSpecification<T>(ISpecification<T> other) : CompositeSpecification<T> where T : class
|
public sealed class NotSpecification<T>(IEntitySpecification<T> other) : CompositeSpecification<T> where T : IEntity
|
||||||
{
|
{
|
||||||
private readonly ISpecification<T> _other = other;
|
private readonly IEntitySpecification<T> _other = other;
|
||||||
public override bool IsSatisfiedBy(T entity)
|
public override bool IsSatisfiedBy(T entity)
|
||||||
=> !_other.IsSatisfiedBy(entity);
|
=> !_other.IsSatisfiedBy(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ using Bahla.Domain.Specifications.Base;
|
|||||||
|
|
||||||
namespace Bahla.Domain.Specifications
|
namespace Bahla.Domain.Specifications
|
||||||
{
|
{
|
||||||
public sealed class OrNotSpecification<T>(ISpecification<T> left, ISpecification<T> right) : CompositeSpecification<T> where T : class
|
public sealed class OrNotSpecification<T>(IEntitySpecification<T> left, IEntitySpecification<T> right) : CompositeSpecification<T> where T : IEntity
|
||||||
{
|
{
|
||||||
private readonly ISpecification<T> _left = left;
|
private readonly IEntitySpecification<T> _left = left;
|
||||||
private readonly ISpecification<T> _right = right;
|
private readonly IEntitySpecification<T> _right = right;
|
||||||
|
|
||||||
public override bool IsSatisfiedBy(T entity)
|
public override bool IsSatisfiedBy(T entity)
|
||||||
=> _left.IsSatisfiedBy(entity) || !_right.IsSatisfiedBy(entity);
|
=> _left.IsSatisfiedBy(entity) || !_right.IsSatisfiedBy(entity);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using Bahla.Domain.Specifications.Base;
|
using Bahla.Domain.Entities.Base;
|
||||||
|
using Bahla.Domain.Specifications.Base;
|
||||||
|
|
||||||
namespace Bahla.Domain.Specifications
|
namespace Bahla.Domain.Specifications
|
||||||
{
|
{
|
||||||
public sealed class OrSpecification<T>(ISpecification<T> left, ISpecification<T> right) : CompositeSpecification<T> where T : class
|
public sealed class OrSpecification<T>(IEntitySpecification<T> left, IEntitySpecification<T> right) : CompositeSpecification<T> where T : IEntity
|
||||||
{
|
{
|
||||||
private readonly ISpecification<T> _left = left;
|
private readonly IEntitySpecification<T> _left = left;
|
||||||
private readonly ISpecification<T> _right = right;
|
private readonly IEntitySpecification<T> _right = right;
|
||||||
|
|
||||||
public override bool IsSatisfiedBy(T entity)
|
public override bool IsSatisfiedBy(T entity)
|
||||||
=> _left.IsSatisfiedBy(entity) || _right.IsSatisfiedBy(entity);
|
=> _left.IsSatisfiedBy(entity) || _right.IsSatisfiedBy(entity);
|
||||||
|
|||||||
Reference in New Issue
Block a user