More on ISpecification and ILinqSpecification

Jan 25, 2010 at 10:43 AM

Last week, I posted some questions about the Domain.Contracts.Specifications namespace in WCHM:

 

Domain.Contracts.Specifications - Querying with filtering, sorting, pagination

http://whocanhelpme.codeplex.com/Thread/View.aspx?ThreadId=81003

 

In hindsight, the two questions posted there are different enough to warrant separate discussions, so I'm posting this new message to discussion question 1 in particular:

 

"1) What's the role of Domain.Contracts.Specifications.ISpecification<T>? What is its relation to Domain.Contracts.Specifications.ILinqSpecification<T>?"

 

With helpful direction from Howard via Twitter, I was able to review a lot of material on the Specification pattern in general, and the Linq Repository Specification patter in particular:


Implementing the Specification Pattern via Linq
Nicholas Blumhardt's Blog
http://ubik.com.au/article/named/implementing_the_specification_pattern_with_linq

Linq, the Specification Pattern and Encapsulation
Fredrik Kalseth's Blog
http://www.iridescence.no/post/Linq-the-Specification-Pattern-and-Encapsulation.aspx

Implementing ORM-independent Linq queries
Rinat Abdullin's Blog
http://rabdullin.com/implementing-orm-independent-linq-queries/

 

This ultimately led me to Steven Burman's Blog ( http://www.mostlyclean.com/category/Linq.aspx ), and his linq-specifications project:

http://code.google.com/p/linq-specifications

 

From looking at the code, and based on Howard's message to the SharpArch mailing list in April 2009:


LINQ + NHibernate + Specification Pattern
S#arp Architecture Mailing List
http://groups.google.com/group/sharp-architecture/browse_thread/thread/4a6700a9cfb52dc6/3f6fbd40787ef466?lnk=gst&q=specification#3f6fbd40787ef466

 

it looks as though the WCHM Specification implementation is based largely on the linq-specifications project.

 

Looking deeper at the WCHM code in Domain.Contracts.Specifications reveals though that there are a number of differences between the implementations, which leads me to the following questions:

 

* What does the WCHM concrete implementation of ISpecification<T> look like? (I cannot find a concrete implementation of this interface in the codebase)

* Can you post a sample usage of ISpecification<T>? In the WCHM codebase, only the ILinqSpecification<T> (via concrete class QuerySpecification<T>) is used to create specifications. (I cannot find any inheritors of ISpecification<T> in the codebase).

* The WCHM ILinqSpecification<T> contract is more or less equivalent to the Linq.Specifications ISpecification<T>contract. On the other hand, the WCHM ISpecification<T> contract seems to be a lot different, and has a lot of other functionality (IsGeneralizationOf, IsSpecialCaseOf, etc) not found in Linq.Specifications. What was the motivation for the differences?

 

I think a nice juicy code sample would help me out the most here, but as always, any comments/feedback are greatly appreciated.

 

Based on the contracts, I can see WCHM is doing a lot of smart things with the specification pattern. Thank you again for sharing this with the community. I am learning such a great deal from this!

 

Best regards, Martin