Rename All specification to Identity

This commit is contained in:
Sipke Schoorstra 2021-04-20 14:19:25 +02:00
parent 3c8d343165
commit 91bda57411
5 changed files with 15 additions and 30 deletions

View file

@ -31,7 +31,7 @@ namespace Elsa.Activities.Webhooks.ActivityTypes
public async ValueTask<IEnumerable<ActivityType>> GetActivityTypesAsync(CancellationToken cancellationToken = default)
{
var specification = Specification<WebhookDefinition>.All;
var specification = Specification<WebhookDefinition>.Identity;
var definitions = await _webhookDefinitionStore.FindManyAsync(specification, cancellationToken: cancellationToken);
var activityTypes = new List<ActivityType>();

View file

@ -11,8 +11,8 @@ namespace Elsa.Persistence.Specifications
/// </summary>
public abstract class Specification<T> : ISpecification<T>
{
public static readonly ISpecification<T> All = new IdentitySpecification<T>();
public static readonly ISpecification<T> None = All.Not();
public static readonly ISpecification<T> Identity = new IdentitySpecification<T>();
public static readonly ISpecification<T> None = Identity.Not();
private Func<T, bool>? _predicate;
public virtual bool IsSatisfiedBy(T entity)

View file

@ -6,24 +6,9 @@ namespace Elsa.Persistence.Specifications
{
public static class SpecificationCollectionsExtensions
{
public static ISpecification<T> ToAndSpecification<T>(this IEnumerable<ISpecification<T>> specifications)
{
return specifications.Aggregate(Specification<T>.All, (current, specification) => current.And(specification));
}
public static ISpecification<TChecked> ToAndSpecification<TSource, TChecked>(this IEnumerable<TSource> source, Func<TSource, ISpecification<TChecked>> specificationFactory)
{
return source.Select(specificationFactory).ToAndSpecification();
}
public static ISpecification<T> ToOrSpecification<T>(this IEnumerable<ISpecification<T>> specifications)
{
return specifications.Aggregate(Specification<T>.None, (current, specification) => current.Or(specification));
}
public static ISpecification<TChecked> ToOrSpecification<TSource, TChecked>(this IEnumerable<TSource> source, Func<TSource, ISpecification<TChecked>> specificationFactory)
{
return source.Select(specificationFactory).ToOrSpecification();
}
public static ISpecification<T> ToAndSpecification<T>(this IEnumerable<ISpecification<T>> specifications) => specifications.Aggregate(Specification<T>.Identity, (current, specification) => current.And(specification));
public static ISpecification<TChecked> ToAndSpecification<TSource, TChecked>(this IEnumerable<TSource> source, Func<TSource, ISpecification<TChecked>> specificationFactory) => source.Select(specificationFactory).ToAndSpecification();
public static ISpecification<T> ToOrSpecification<T>(this IEnumerable<ISpecification<T>> specifications) => specifications.Aggregate(Specification<T>.None, (current, specification) => current.Or(specification));
public static ISpecification<TChecked> ToOrSpecification<TSource, TChecked>(this IEnumerable<TSource> source, Func<TSource, ISpecification<TChecked>> specificationFactory) => source.Select(specificationFactory).ToOrSpecification();
}
}
}

View file

@ -4,20 +4,20 @@
{
public static ISpecification<T> And<T>(this ISpecification<T> @this, ISpecification<T> specification)
{
var all = Specification<T>.All;
var identity = Specification<T>.Identity;
if (@this == all)
if (@this == identity)
return specification;
return specification == all ? @this : new AndSpecification<T>(@this, specification);
return specification == identity ? @this : new AndSpecification<T>(@this, specification);
}
public static ISpecification<T> Or<T>(this ISpecification<T> @this, ISpecification<T> specification)
{
var all = Specification<T>.All;
var identity = Specification<T>.Identity;
if (@this == all || specification == all)
return all;
if (@this == identity || specification == identity)
return identity;
return new OrSpecification<T>(@this, specification);
}

View file

@ -26,7 +26,7 @@ namespace Elsa.WorkflowProviders
protected override async ValueTask<IEnumerable<IWorkflowBlueprint>> OnGetWorkflowsAsync(CancellationToken cancellationToken)
{
var workflowDefinitions = await _workflowDefinitionStore.FindManyAsync(Specification<WorkflowDefinition>.All, cancellationToken: cancellationToken);
var workflowDefinitions = await _workflowDefinitionStore.FindManyAsync(Specification<WorkflowDefinition>.Identity, cancellationToken: cancellationToken);
return await Task.WhenAll(workflowDefinitions.Select(async x => await _workflowBlueprintMaterializer.CreateWorkflowBlueprintAsync(x, cancellationToken)));
}
}