Sprint Planner Helper – Session 21

Posted by Marcus Hammarberg on March 20, 2009

I’m back! After doing a detour through the sample chapter of the upcoming ASP.NET MVC book (lovingly called “The four faces”, i heard…) I now feel ready to go on.

And I learned a few things by that sample chapter; about ASP.NET MVC, yes but also I saw some flaws of my DDD-ing, especially in the use of the Repository pattern.

The main thing is that I have a separate Update-method that feels a bit strange. Another thing I learned and finally understood was the IQueryable-interface.

By using it you can defer the execution of the actual database query until the client calls. Which means that the query will be fine tuned with all the parameters that the client has includes (such as Take, Sort etc.). (For a much better explanation see this.)

So I’ll update my IRepository to something like this:

    public interface IRepository<T>  where T :IBaseEntity


        T GetById(int id);

        IQueryable<T> Find();

        void Add(T entity);

        void Delete(T entity);

        void Save();


And then I’ll face the consequences of that… I expect loads of tests and code to fix.

[Coding, coding, coding…]

The first thing I needed to do was to move the fakes from the Repository-project into the Test-project where they belong (again a tip from the sample chapter). OK – that made me re-invent the InMemory-Repository. But when I was done the code quality was much better. Clean code!

But I also feel that I might ditch the InMemory solution altogether and go to a database-solution… It starts to feel quite strange…

Then the connection to CodePlex was lost… Took about ten minutes to restart…

With my new repository I also introduced a pattern, called Unit Of Work. Its from Fowlers book Patterns of Enterprise Architecture, which on my bedside table. In this example is basically means that I need to be sure to call the Save-method of the IRepository-interface after each add or delete.

Finally I once again got the opportunity to praise TDD. Did refactoring for about 50 minutes with minor changes all over the place. Ran the tests… 5 failing. Corrected them in 5 minutes! Show me that without any test and I will be very impressed.

Next session will start to implement some “implementation patterns” from the sample chapter, such as the Details-views, the two-phase Delete etc.

Published by Marcus Hammarberg on Last updated