Standard practice to identify specification template for customer code?

I have an N-tiered application where I use the Specification template. Now I want to provide some ways to create specifications for client code. This should be a few predefined parameters, for example:

  • Equally
  • Greaterthan
  • Contains

These objects (let me call them filters) should not contain any logic (methods), only the type and parameters of the data filter. And there has to be a natural way to turn them into specifications on the server. Here is an example of how it should look from the client side:

var serviceClient = new DataModuleService(); var equalFilter = new ContainsFilter<Book>("Title","Lord of the Rings"); var lordOfTheRingBooks = serviceClient.GetBooks(equalFilter); 

There should also be filter types for all standard operations (for example, Equal, Greater, In, Between, StartsWith for a string, etc.) and ways to combine them with Boolean operators (and, or, not).

Are there some templates / standard methods for implementing such a thing?


UPD: the task is still frozen, and I began to think that there is a problem in the definition of the task.

+6
source share
2 answers

The answer is a high level - I believe that you can try LINQ expressions that support the entire logical and conditional statement that you mentioned. Scans the System.Linq.Expressions Namespace to view the available types.

Useful links:

+4
source

What you're trying to do sounds to me like what Hibernate does with its query criteria . You can combine them , however you want to create the filter you are interested in.

This is not C #, but Java and C # are similar languages, so maybe you could borrow some ideas from there.

Alternatively, you can go to the Hibernate port on .NET for the same criteria requests (although I don’t know for sure the API is the same as Java).

+2
source

Source: https://habr.com/ru/post/920443/


All Articles