- Today Kar-Khan pointed out to me the my get/setter-based approach to jumping through a bunch of hoops immediately upon model binding which I crafted here, refined here, and then had Joel refine here, is just goofy. It is better to just have plain Jane get/setters and then call a method to do more complicated things with them beyond get and set. It didn’t want to do this because it entails putting an extra line of code in the Controller, but boy is that ever the lesser of the two evils compared to the mess I've been making.
- I added the following to our Base Class for Repositories:
public virtual IQueryable<T> FindFilteredSet(List<Specification<T>> specifications)
{
Specification<T> currentSpecification =
new AdHocSpecification<T>(t => t != null);
IQueryable<T> results =
Session.Query<T>().Where(currentSpecification.IsSatisfiedBy());
foreach(Specification<T> specification in specifications)
{
IQueryable<T> concatenatedResults =
Session.Query<T>().FindAll(specification).FindAll(currentSpecification);
currentSpecification = specification;
results = concatenatedResults;
}
return results;
}
public virtual IQueryable<T> FindFilteredSet(List<Specification<T>> specifications)
{
var query = Session.Query<T>();
specifications.ForEach(spec => query.Where(spec.IsSatisfiedBy()));
return query;
}
- We are taking the approach above in lieu of chaining specs in the name of a cleaner process outside of logic nested in Controllers which may also be encapsulated to play nicely with a comparable means devised for filtering based upon custom attributes. (I am building specifications for filtering on the static parameters of objects and the static parameters of their children in this example.)
Tuesday, August 30, 2011
What I did today!
Today:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment