ardalis / Specification

Base class with tests for adding specifications to a DDD model
MIT License
1.83k stars 238 forks source link

Which Design Pattern is behind Evaluators? #382

Closed elyosemite closed 4 months ago

elyosemite commented 4 months ago

I recently search in google about Evaluators Pattern, however I did not find out anything about design pattern that it calls Evaluators?

Help me get there and understand the design pattern behind it. Would it be the Rule Engine?

fiseni commented 4 months ago

Hi @elyosemite,

There is no pattern called Evaluators. I just came up with that name, because it made sense in our case. The specifications hold all query-related data, and at some point, we need to apply that state for a given provider. For EF, we apply all expressions on top of the DbSets, and return the final IQueryable. In the very first version, while we had support only for Where and Include, we had a single method GetQyery that did all of the work. But, that wouldn't scale well. That's why we came up with the current infrastructure, where we have isolated constructs to deal with different query features. We called them evaluators (partial evaluators and specification evaluators). This enables us easily to add/remove different evaluators per provider and also provides the ability to extend the evaluation with user-provided custom evaluators.

As for utilized patterns in the library, we're using the Singleton pattern, Strategy, Builder and so on.