-
Notifications
You must be signed in to change notification settings - Fork 249
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 the (logical) combination of specifications #254
Comments
Hey @AndreErb , We had lengthy conversations on this topic on many occasions. There are several issues with that approach, and I do believe it will do more harm than good.
Anyhow, we still don't want to confine the usage, and we tried to create an extensible infrastructure so the users can define their desired custom behavior.
public class CustomerBaseSpec : Specification<Customer>
{
public CustomerBaseSpec()
{
Query.Include(x => x.Stores);
}
}
public class CustomerByIdSpec : CustomerBaseSpec
{
public CustomerByIdSpec(int id)
{
Query.Where(x => x.Id == id);
}
}
public static class CustomerSpecExtensions
{
public static ISpecificationBuilder<Customer> ApplyBaseRules(
this ISpecificationBuilder<Customer> specificationBuilder)
{
specificationBuilder.Include(x => x.Stores);
return specificationBuilder;
}
}
public class CustomerByIdSpec : Specification<Customer>
{
public CustomerByIdSpec(int id)
{
Query.ApplyBaseRules()
.Where(x => x.Id == id);
}
} As you can notice, the infrastructure is quite flexible and you have many options to achieve the same results. Let me know if this helps. |
@fiseni Some of your arguments are are something which I already had foreseen (e.g. the "query generation" argument). I agree with your explanations and arguments, so that's why I am closing this issue as well. Thank you again for your time and effort! |
I wonder if it would be possible to add support for the (logical) combination of specifications, using operators like
(&, |, !, ==, !=)
I have watched your guys' YouTube videos about this Specification Library and you too mentioned the problem, that specification names tend to become large, when multiple logic/rules are contained. You discussed different naming approaches to mitigate this, however it feels like the real problem is somehow a consequence of the pattern itself. If one has "SpecA" and "SpecB" it seems to violate the DRY principle as well, if one had to create "SpecAB" with both rules repeated, just in order to combine them.
This seems to be related to Add support for updating specifications
Also ASbeletsky's NSpecification library has this kind feature and I saw this approach on different web blogs, too.
Not sure if it is possible (diserable) at all, since specs also project the result and therefore might not even be compatible at all.
However, it seems hard to extend this for ourselves and if it could or should be done, it feels like should be done in the library itself.
BTW: Thanks for this library and your great work!
The text was updated successfully, but these errors were encountered: