开发者

Persisting specifications

开发者 https://www.devze.com 2023-02-15 09:06 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号