Category Archives: Patterns

The Repository Pattern: Links, News and Resources (1)

These are my links about Repository Pattern: the differences with DAOs (Data Access Objects); examples with NHibernate, Entity Framework; its use in DDD; its relation to IUnitOfWork; discussion about how to query a repository; the influence of Linq/IQueriable in the evolution of this pattern in .NET (LINQ/IQueryable is a missing piece in Java). There are interesting discussions in Spanish, too. I recommend you should translate them.


A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.

LLBLGenPro, Entity Framework 4.1, and the Repository Pattern

HunabKu: LINQ and Repository

Revisiting the Repository and Unit of Work Patterns with Entity Framework

Demo web app using ASP.NET MVC 3 RTM, Razor, EF Code First and Unity 2.0
Repository Pattern and Unit of Work

Repository is Dead: Long Live Repository

Repository is the new Singleton

DDD: The Generic Repository

The Repository Pattern

N-Tiers using POCOs and Entity Framework – Part Two: Model and Entities

N-Tiers using POCOs and Entity Framework – Part Five: DataAccess Layer

N-Tiers using POCOs and Entity Framework – Part Six: Source Code

Using the NHibernate Repository Pattern in C# ASP .NET

Mock a database repository using Moq

The wages of sin: Proper and improper usage of abstracting an OR/M

The wages of sin: Over architecture in the real world

Architecting in the pit of doom: The evils of the repository abstraction layer
Better Domain-Driven Design Implementation

Entities, Services and what goes between them…

Suteki Shop
Suteki Shop is an eCommerce application. The orginal aim is to write a site for a fashion retail business. It includes a product catalogue, shopping cart and order processing.
    * .NET 4.0
    * ASP.NET MVC 3
    * MVC Contrib
    * NHibernate
    * Windsor IoC Container

Source for @fabiomaulo blog examples

Repository, IQueryable y otras hierbas
"cuando Fowler y Eric Evans en su libro DDD definieron Repository no existía el concepto de IQueryable y creo que no muchos se lo veían venir, así que simplemente si asociamos que Repository es una abstración superior del acceso a datos y este se debe comportar como una colección en memoria (mezclando las definiciones de Fowler y Evans) y coincidimos en que en la .Net Framework las colecciones pueden extenderse a IQueryable, es fácil razonar que por definición un repositorio finaliza implementando IQueryable<T> (mera jalada mi filosofía y asociación, pero para filósofo preguntémosle mejor a @ajlopez!)" <—Great! @cprieto reads my philosophy posts 😉
Spanish discussion

HunabKu: Enhanced Query Object

Implementing Repository Pattern With Entity Framework

Entity Framework as Repository and UnitOfWork?

Repository or DAO?: Repository

Repository or DAO?: DAO

Repositories for Value Objects?

How to use dependency injection and the repository pattern with ASP.NET web services?

FubuMVC Contrib
Contrib for FubuMVC a Front Controller-style MVC framework designed primarily for Web applications built on ASP.NET
Many samples with IRepository, NHibernate, IUnitOfWork

MPBlog Implementation. Part 4
NHibernate Repository and Unit Of Work

Linq specifications: from Argentina with Love

IRepository interface

nHibernate, Linq and Queries

The DAL should go all the way to UI

Returning IQueryable<T>

Generic Repository
The Generic Repository (grepo) is an open source (ASLv2) framework for Java which allows you to access (database) repositories in a generic and consistent manner.

The catalogue metaphor and command-query seperation architectures
Query Objects vs Methods on a Repository

Using Repository and Unit of Work patterns with Entity Framework 4.0

AltNet-Argentina: DAO, Repository y clases Query

DDD: The Generic Repository

My Links

More links about other patterns are coming.

Keep tuned!

Angel “Java” Lopez

Design Patterns in an Interpreter, using TDD

Past October, I participated in an ALT.NET Hispano VAN about Design Patterns. I presented some of the classic design patterns of the GangOfFour book. My presentation (Spanish) DesignPatterns.pptx The VAN video (Spanish voice) and resources.

During the VAN, I explain and use some of the design patterns, but with a key idea: use all of them in the same example: an interpreter. You can download the C# code from my Google Code Project AjCodeKatas at Patterns folder.

Maybe, that code evolve, but you can download the VAN original code from

Note: the namespaces that I used are related to the patterns. The code was developed using TDD (Test-Driven Design).

This is the list of patterns:

Interpreter: used in a expression interpreted, base of all the example.

Composite: with commands in the interpreter. There is a composite comamnd that contains a list of commands.

Template Method: it is in the method .Evaluate of the BinaryExpression: it evaluated two expressions and the results is used in the method .Apply, that is implemented at each of the subclasses.

Strategy: Instead of writing a class, I use Func<obj,obj,obj> to apply in the evaluation of ArithmeticBinaryExpression.

Decorator: An IContext is passed to each command and expressiona. It has the responsability of keep the values of the variables. I decorated it to have a new IContext implementation that raise events with info about what variables and values are read and changed.

Observer: Events in .NET, an evolution of the original pattern.

Adapter: I want to consume a file with code of the language to interpret, using a TextReader. But I need to read words, tokens (see Token class). Lexer class is an adapter around the TextReader. It has new method to read the next token in the stream.

Abstract Factory: The example is not in the interpreter. There is code that use ADO.NET providers, that act as an abstract factory.

Facade: with Strategy, it’s one of the most important pattern to learn and employ. All Strategy derives to composition instead inheritance, and to Dependency Injection, Inversion of Control and IoC containers. For me, Facade is like the “API” of our business, domain. A classic example: ISession in NHibernate.

Machine class is a kind of Facade. It is the entry point to the interpreter. It coordinate and delegate work to Parser (another adapter example), Lexer, files, Context. The interpreter consumer can invoke this object without direct interaction with the internal implementation.

Visitor: I wrote a class, that takes an instance of the Interpreter (as a tree to execute) and decompiles it to text.

You have more examples and UML diagrams at:

Thanks to the ALT.NET Hispano for the opportunity to talk about this topic. I should publish more advances of my series about writing an interpreter using TDD.

Keep tuned!

Angel “Java” Lopez