User configurable arbritrary list filtering in C#
I would like to implement a user-configurable filtering system for lists in an ASP.NET MVC project.
The configuring user must be able to filter the list by any of the properties of the objects in the list. Additionally, values in the current execution scope such as properties of static classes should be available for use in the comparison. The objects to be filtered are all of the same type.
The purpose of this system is to enable multiple 'white-label' ecommerce sites fed by a central catalogue, but with each site having a slightly different subset of products available.
The configuration needs to be done through an administration interface, rather than through deploying code.
Solutions I am considering:
`1. Implement my own basic syntax. Store text in database to represent comparison. Use reflection to complete the comparison / filtering.
Problems: Don't like rolling my own. Potential for开发者_开发技巧 error in text.
`2. Implement mini 'comparison DLLs', use Spring or similar to inject.
Problems: Application is in webfarm, so potential for deployment error. Management becomes difficult. No admin interface.
Ideally I would like a solution that is easy to maintain (keep information in db) and fairly safe (small margin for error by users).
The solution we found for this problem is fairly controversial, but it does work.
We are storing C# code in the database, and compiling it into a lambda function on demand, then caching the resulting object (we're using AppFabric Server).
This function is then used to filter the list of objects.
We provide an administration interface for people to create and edit their own filters. The administration interface confirms that code can be compiled before it is stored in the database.
精彩评论