Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for extending default evaluator list #328

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class SpecificationEvaluator : ISpecificationEvaluator
// Will use singleton for default configuration. Yet, it can be instantiated if necessary, with default or provided evaluators.
public static SpecificationEvaluator Default { get; } = new SpecificationEvaluator();

private readonly List<IEvaluator> evaluators = new List<IEvaluator>();
protected List<IEvaluator> Evaluators { get; } = new List<IEvaluator>();

public SpecificationEvaluator()
{
this.evaluators.AddRange(new IEvaluator[]
this.Evaluators.AddRange(new IEvaluator[]
{
WhereEvaluator.Instance,
SearchEvaluator.Instance,
Expand All @@ -26,7 +26,7 @@ public SpecificationEvaluator()
}
public SpecificationEvaluator(IEnumerable<IEvaluator> evaluators)
{
this.evaluators.AddRange(evaluators);
this.Evaluators.AddRange(evaluators);
}

/// <inheritdoc/>
Expand All @@ -48,7 +48,7 @@ public virtual IQueryable<T> GetQuery<T>(IQueryable<T> query, ISpecification<T>
{
if (specification is null) throw new ArgumentNullException("Specification is required");

var evaluators = evaluateCriteriaOnly ? this.evaluators.Where(x => x.IsCriteriaEvaluator) : this.evaluators;
var evaluators = evaluateCriteriaOnly ? this.Evaluators.Where(x => x.IsCriteriaEvaluator) : this.Evaluators;

foreach (var evaluator in evaluators)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class SpecificationEvaluator : ISpecificationEvaluator
/// </summary>
public static SpecificationEvaluator Cached { get; } = new SpecificationEvaluator(true);

private readonly List<IEvaluator> evaluators = new List<IEvaluator>();
protected List<IEvaluator> Evaluators { get; } = new List<IEvaluator>();

public SpecificationEvaluator(bool cacheEnabled = false)
{
this.evaluators.AddRange(new IEvaluator[]
this.Evaluators.AddRange(new IEvaluator[]
{
WhereEvaluator.Instance,
SearchEvaluator.Instance,
Expand All @@ -40,7 +40,7 @@ public SpecificationEvaluator(bool cacheEnabled = false)

public SpecificationEvaluator(IEnumerable<IEvaluator> evaluators)
{
this.evaluators.AddRange(evaluators);
this.Evaluators.AddRange(evaluators);
}

/// <inheritdoc/>
Expand All @@ -62,7 +62,7 @@ public virtual IQueryable<T> GetQuery<T>(IQueryable<T> query, ISpecification<T>
{
if (specification is null) throw new ArgumentNullException("Specification is required");

var evaluators = evaluateCriteriaOnly ? this.evaluators.Where(x => x.IsCriteriaEvaluator) : this.evaluators;
var evaluators = evaluateCriteriaOnly ? this.Evaluators.Where(x => x.IsCriteriaEvaluator) : this.Evaluators;

foreach (var evaluator in evaluators)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class InMemorySpecificationEvaluator : IInMemorySpecificationEvaluator
// Will use singleton for default configuration. Yet, it can be instantiated if necessary, with default or provided evaluators.
public static InMemorySpecificationEvaluator Default { get; } = new InMemorySpecificationEvaluator();

private readonly List<IInMemoryEvaluator> evaluators = new List<IInMemoryEvaluator>();
protected List<IInMemoryEvaluator> Evaluators { get; } = new List<IInMemoryEvaluator>();

public InMemorySpecificationEvaluator()
{
this.evaluators.AddRange(new IInMemoryEvaluator[]
this.Evaluators.AddRange(new IInMemoryEvaluator[]
{
WhereEvaluator.Instance,
SearchEvaluator.Instance,
Expand All @@ -26,7 +26,7 @@ public InMemorySpecificationEvaluator()
}
public InMemorySpecificationEvaluator(IEnumerable<IInMemoryEvaluator> evaluators)
{
this.evaluators.AddRange(evaluators);
this.Evaluators.AddRange(evaluators);
}

public virtual IEnumerable<TResult> Evaluate<T, TResult>(IEnumerable<T> source, ISpecification<T, TResult> specification)
Expand All @@ -47,7 +47,7 @@ public virtual IEnumerable<TResult> Evaluate<T, TResult>(IEnumerable<T> source,

public virtual IEnumerable<T> Evaluate<T>(IEnumerable<T> source, ISpecification<T> specification)
{
foreach (var evaluator in evaluators)
foreach (var evaluator in Evaluators)
{
source = evaluator.Evaluate(source, specification);
}
Expand Down