You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There exists no possibility to extend the default evaluators listed in SpecificationEvaluator.Default. There exists an example of how to write your own evaluator in in #247 but it doesn't touch the subject of how to inject it.
If I want to extend with a custom evaluator I've to create my own list of all the default evaluators and then add my custom one. This gives a hard coded dependency and if Ardalis makes a change to the default list of evaluators I will have to update my own code as well to keep up.
Suggestion: at least change the private readonly List<IEvaluator> evaluators to protected so projects can create their own custom SpecificationEvaluator extending from Ardalis SpecificationEvaluator and add their on evaluators to the default ones.
publicclassCustomSpecificationEvaluator:SpecificationEvaluator{publicCustomSpecificationEvaluator(boolcacheEnabled=false):base(GetAllEvaluators(cacheEnabled)){}privatestaticIEnumerable<IEvaluator>GetAllEvaluators(boolcacheEnabled=false){vardefaultAndCustomEvaluators=newList<IEvaluator>();// add Ardalis default evaluators
defaultAndCustomEvaluators.AddRange(new IEvaluator[]{// this list will need to be maintained
WhereEvaluator.Instance,
SearchEvaluator.Instance,cacheEnabled? IncludeEvaluator.Cached : IncludeEvaluator.Default,
OrderEvaluator.Instance,
PaginationEvaluator.Instance,
AsNoTrackingEvaluator.Instance,
IgnoreQueryFiltersEvaluator.Instance,
#if!NETSTANDARD2_0
AsSplitQueryEvaluator.Instance,
AsNoTrackingWithIdentityResolutionEvaluator.Instance
#endif
});// add custom evaluators
defaultAndCustomEvaluators.AddRange(new IEvaluator[]{
AsSingleQueryEvaluator.Instance
});returndefaultAndCustomEvaluators;}}
There exists many solutions to this problem. Another one would be to expose the evaluators property. Whatever solution that don't force you to copy-paste the default evaluator list is fine. 🙂
The text was updated successfully, but these errors were encountered:
Please refer to this comment on why we didn't add support for appending custom evaluators (the order might be important).
Also, here is an example of how to create and inject a custom evaluator. I know we have to consolidate the documentation. Any help is welcome.
Back to the question, ahh I give up, let's update the state as protected 😄 We'll update it in the next release.
To clarify for future readers. In some specific cases, the order of statements while building the IQueryable is important to EF Core. For instance, if you have some filtering logic (e.g. Where statement), it should be placed before any paging statements (Take/Skip). So, if you're writing your custom evaluators, be careful how you inject them.
There exists no possibility to extend the default evaluators listed in
SpecificationEvaluator.Default
. There exists an example of how to write your own evaluator in in #247 but it doesn't touch the subject of how to inject it.If I want to extend with a custom evaluator I've to create my own list of all the default evaluators and then add my custom one. This gives a hard coded dependency and if Ardalis makes a change to the default list of evaluators I will have to update my own code as well to keep up.
Suggestion: at least change the
private readonly List<IEvaluator> evaluators
toprotected
so projects can create their own custom SpecificationEvaluator extending from Ardalis SpecificationEvaluator and add their on evaluators to the default ones.This would result in:
instead as of today being forced to code:
There exists many solutions to this problem. Another one would be to expose the
evaluators
property. Whatever solution that don't force you to copy-paste the default evaluator list is fine. 🙂The text was updated successfully, but these errors were encountered: