1

I'm building a system where a user can subsribe for items and get periodically notifications for new items. Users should define what items they want by filtering on certain properties.

I'm using the specification pattern to filter items. My thought is that users should define their own specifications in a web gui.

The filtering is simply:

ItemService
{
    public IEnumerable<Item> GetMatching(IEnumerable<Item> items, IItemSpecification spec)
    {
        return items.Where(spec.IsMatch);
    }
}

IItemSpecification
{
    IsMatch(Item item);
}

The question is, what's the best way to persist eaach users different specifications? I don't have any requirements on how i persist it. Relational database, document databaes, xml, whatever works.

I can think of:

  • Write a external DSL (and store it in a simple column in a rdb)

  • Store a row (in a rdb) for each property in a specification, which indicates what to filter on and modifiers (equals, greater then). This will result in pretty many rows.

  • Create a new table for each specification (don't know if this is realistic)

It seems that the DSL option is the cleanest solution (i only need to write a DSLSpecification which takes a dsl and pass it to my Itemservice. Maybe i'm overcomplicating things.

alexn
  • 57,867
  • 14
  • 111
  • 145
  • if you are filtering your data in db and optimization is your main goal, you should use method 2 it's the easiest way to use it in db procedure to build dynamic query. if all the job is done in c# you should use DSL or just store is as an XML' serialized IItemSpecification object – Silx Mar 08 '11 at 17:34
  • @Silx All the filtering is done in c#. Storing my specs as xml may work. I just need a way to express all clauses as properties. Going to experiment with that. Thanks. – alexn Mar 08 '11 at 17:36

0 Answers0