April 2009 Blog Posts

It’s been a while since my last update on NCommon, and a few features and some bug fixes have been checked in. A lot of new functionality and bug fixes were added with the help of some good feedback from the CodePlex discussions forum.

The first change is that the GetCurrentUnitOfWork method in the RepositoryBase class has been made virtual. This is done to allow overriding the default behavior in your implementation of repository that sub-classes RepositoryBase. The reason behind this change is to make RepositoryBase more adaptable to scenarios where a the default behavior needs to be overriden.

An AutoComplete mode has been added to UnitOfWork which allows the unit of work to auto complete instead of rolling back when being disposed. This functionality was added with the help from Pablo Ruiz, who originally thought of adding this to NCommon. Thanks Pablo. [http://ncommon.codeplex.com/Thread/View.aspx?ThreadId=52096]

A new method, called Cached, has been added to the IRepository interface. The intent of this method is to notify the underlying provider that results of this query should be cached. This is currently only useful for NHibernate where Query caching can be done.

As a side note, this will be the last source update of NCommon on CodePlex.


Recently I had the chance to work on a Silverlight light front end to a rather complex application. Well, to be fair the concept that the application intended to solve was slightly complex, but the implementation was quite straightforward and simple, to my surprise (the things I’m learning these days!).

Anyways, I stumbled upon this opportunity by stating in a meeting that I could probably tackle the UI. Now I believe a disclaimer is in order. I’ve done UI before, actually my last project required a lot of heavy work on the UI, but that was WinForms and web design stuff. My experience on WPF has been rather limited, mostly in small controlled scenarios that didn’t require a lot of UX wizardry. Now that I have stated that I have done UI before, the clarification I want to add is that if you put in a designer to design the UI, the comparison would be somewhat like this:

to

Well, what I’ve come away with after starting on this Silverlight project is a new found respect for designers that have dome some amazing work with WPF and silverlight. In fact after doing Silverlight work, I’ve come to realize that I don’t have the patience for working on UI stuff.

As a developer I find my time is best suited in solving logical issues. Solving puzzles is fun and satisfying which makes me want to do the best I can do and always push the envelope. But when it comes to UI, I realized that my level of what is “acceptable” is far lower than that of a UX designer. And the reason for that is because in my mind getting UI right is not very interesting, rather the guts of the application is what interests me, and hence why I get to the “acceptable” bar very quickly.

I’ve been thinking about this for a while and recently I caught somewhat a designer goes through when working on a design challenge. My wife does paintings as a hobby and the one she is working on right now is somewhat special to both of us. A few days back I had the chance to observe her tackling a challenge on how to present the background and border of the painting. What I saw was a painful process of getting the colors absolutely right. She took great care to get the mix of her paints just right, the accuracy of her brush strokes had to be just right so that the two borders had the correct mix of shades… if it was me, id mix some colors and if it looks okay that’s what I’d end up using as the color and then just paint.

But one thing that I did learn from this project is that UX can be as rewarding as development. I may not be a UX designer, but I can appreciate the skill required to do so much more now.

Well for now it looks like I’ve been labeled as the UI guy… This is going to be interesting to say the least :)


Oren’s recent posts on the Repository pattern and ORM have raised a hornets nest and intense discussion on the pattern itself. You can read them @: Repository is the new singleton, Mocking NHiberante and The DAL should go all the way to UI. In this post I’ll give my 2 cents on the points made in Oren’s post.

Lets start with the post: Repository is the new singleton. Now I had a very similar discussion with Oren a few weeks back and judging by the comments in that post my reaction was quite similar. I have had some time to think about this though… First of all I do completely agree with the point that the Repository pattern has become somewhat a focal point for DDD purists and is a pattern treated with much reverence. Data access has become such a major point that we have religious arguments on what a repository is and how we should implement it, what methods go into that, the infrastructure behind it and on and on it goes. The dry fact is that data access is the least interesting part in an application and it needs to be treated with that same emotion. You definitely need a standard, testable and mockable data access strategy that works for your application.

Now, one the first reasons I started NCommon was because I hated the fact of creating separate repository implementation for your aggregate roots, and more to the point that repositories should really represent a queryable data store that doesn’t abstract away queries behind methods that some unfortunate developer has to maintain and evolve, but rather allow consumers of the repository to query it directly. Hence why NCommon relies on repositories to implement the IQueryable interface to provide a query infrastructure directly on top of NCommon repositories.

Another point I also quite frankly agree with is that DDD is not required in all scenarios and standardizing on the repository pattern as your answer to all your data access strategies. Sometimes you can use a plain ORM directly without needing a repository providing an additional layer of abstraction over it. If your application is simple enough I’d suggest skipping a repository layer all together.

Now the second part goes into describing Oren’s approach of encapsulating complex queries using a Query object that takes in an ISession and an ICriteria to build up the encapsulated query. This is where I have a different opinion than the approach he described. The approach I would take is rather than exposing the infrastructure requirements in the query object, I’d like it to take in an IQueryable and return back a IQueryable. This will allow chaining of queries by multiple of such Query objects without exposing any infrastructure concerns.

Which is a nice segue to the last post: The DAL should go all the way to UI. This post gives a nice diagram of how we think of our traditional applications and for the most part I agree with it. Again, what I have a hard time accepting is the leak of infrastructure concerns. The problem with exposing ICriteria, or any other infrastructure component, to all layers of the application is that eventually a lot of infrastructure concern creeps into layers of the application where they don’t belong. I dislike the idea of having the expose ICriteria to the UI for adding paging and sorting on top of the query encapsulated by ICriteria.

That being said, in my opinion IQueryable is best suited for this job. Its a framework level member that is infrastructure agnostic, provides a very nice way to chain queries together and encapsulates our query requirements rather well. I’ve had comments and questions on NCommon forums before on why IRepository requires to implement the IQueryable interface as opposed to the more traditional approach of pre defined query methods… well Oren’s post quite nicely describes why. IQueryable allows queries on a repository to be augmented and further filtered by other layers.

Am I pimpin NCommon in this post??

Absolutely not. NCommon is a set of patterns and approaches that I feel are the direction I want to use for my future applications. I’m not suggesting that NCommon handles the approaches described in Oren’s post and in this one correctly. Rather, there are many areas where NCommon falls short, one being a detached criteria like functionality (something I am working on, more on this in a future post).

This post is a call to arms and say let querying be a exposed to all layers of an application rather than a careful and controlled encapsulation behind a rigid IRepository interface. Let our repositories be free!

Allowing ad-hoc querying across the layers of your application is a good thing, and it’s something I’d recommend to anyone. Getting caught up in the “what is a DAL layer” topic is not going to provide any value to your application, rather it’s going to end up adding complexity in your application where you don’t need to. As our technologies and frameworks have evolved allowing us to do more with less, similarly our patterns must evolve. I think we can end the rigid repository pattern for a more open, pluggable and extensible repository pattern.


It has been a long time since last posted on my blog, and that has been nagging me for a while now. I guess the reason for my prolonged access from my blog has been mainly due to my time management skills these days.

Needless to say my new assignment is keeping me very busy, and in a good way. The first post I had on this blog talked about the reason as to why I’m starting it in the first place, and one of the biggest reasons was to explore a rational and correct way to develop software and get an overall learning experience. This new assignment is all that and more.

Beyond my current work load I’ve also had trouble keeping up with time management as at least twice in a week I end up feeling exhausted due to travel. Add to that me and my wife got a new puppy home last back and it has been one roller coaster ride since then. A word of advice: if you ever decide to adopt a puppy… be prepared. Puppies can be a very good way to learn patience, something we both have been learning a lot these days :)

Anyways, after a couple of months now I’m getting a hang of my new schedule and getting back on track on managing my time more efficiently. Hopefully that will allow me to resume posts on my blog and get back where I left of.

Things are changing…

One thing I am looking at is moving away from blogger and getting my own site up. I’d like to setup Subtext as my blog host and a wiki site so that I can consolidate my posts and tutorial like stuff onto the wiki (a suggestion I have gotten from many). I haven’t decided on a hosting provider just yet, so if anyone out there has any good suggestions I’d appreciate it.

NCommon is also moving. I’m moving away from CodePlex for good. Why? For one I am tired of having to use IE to post replies on issues and forums topics, and I generally don’t like CodePlex’s performance. NCommon will be moving to Google Code, and soon. I’ll update the blog once it’s done. Although the project in CodePlex will continue to exist, no new updates will be posted there.

Hopefully I can move the blog to the new site sooner than later. Again, update on that will be posted here soon.

posted @ Tuesday, April 21, 2009 5:54 AM | Feedback (2) | Filed Under [ Misc ]