Angel \”Java\” Lopez on Blog

October 7, 2011

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.

Repository
http://martinfowler.com/eaaCatalog/repository.html

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
http://www.mattjcowan.com/funcoding/2011/09/25/llblgen-ef-repository-pattern/

HunabKu: LINQ and Repository
http://fabiomaulo.blogspot.com/2009/06/linq-and-repository.html

Revisiting the Repository and Unit of Work Patterns with Entity Framework
http://blogs.microsoft.co.il/blogs/gilf/archive/2010/06/21/revisiting-the-repository-and-unit-of-work-patterns-with-entity-framework.aspx

EFMVC
http://efmvc.codeplex.com/
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
http://codebetter.com/gregyoung/2009/04/23/repository-is-dead-long-live-repository/

Repository is the new Singleton
http://ayende.com/blog/3955/repository-is-the-new-singleton

DDD: The Generic Repository
http://codebetter.com/gregyoung/2009/01/16/ddd-the-generic-repository/

The Repository Pattern
http://blogs.hibernatingrhinos.com/nhibernate/archive/0001/01/01/the-repository-pattern.aspx

N-Tiers using POCOs and Entity Framework – Part Two: Model and Entities
http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-2.html

N-Tiers using POCOs and Entity Framework – Part Five: DataAccess Layer
http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-5.html

N-Tiers using POCOs and Entity Framework – Part Six: Source Code
http://blog.jorgef.net/2011/02/n-tiers-pocos-ef-6.html

Using the NHibernate Repository Pattern in C# ASP .NET
http://jasper-net.blogspot.com/2011/04/using-nhibernate-repository-pattern-in.html

Mock a database repository using Moq
http://www.codeproject.com/Articles/47603/Mock-a-database-repository-using-Moq.aspx

The wages of sin: Proper and improper usage of abstracting an OR/M
http://ayende.com/blog/4788/the-wages-of-sin-proper-and-improper-usage-of-abstracting-an-or-m

The wages of sin: Over architecture in the real world
http://ayende.com/blog/4786/the-wages-of-sin-over-architecture-in-the-real-world

Architecting in the pit of doom: The evils of the repository abstraction layer
http://ayende.com/blog/4784/architecting-in-the-pit-of-doom-the-evils-of-the-repository-abstraction-layer
Better Domain-Driven Design Implementation
http://www.udidahan.com/2007/03/06/better-domain-driven-design-implementation/

Entities, Services and what goes between them…
http://ayende.com/blog/2145/entities-services-and-what-goes-between-them

Suteki Shop
http://mikehadlow.blogspot.com/search/label/Suteki%20Shop
http://code.google.com/p/sutekishop/
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.
Using
    * .NET 4.0
    * ASP.NET MVC 3
    * MVC Contrib
    * NHibernate
    * Windsor IoC Container

Hunabku
https://bitbucket.org/fabiomaulo/hunabku
Source for @fabiomaulo blog examples
http://www.fabiomaulo.blogspot.com/

Repository, IQueryable y otras hierbas
http://cprieto.com/index.php/2010/05/20/repository-iqueryablet-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 http://groups.google.com/group/altnet-hispano/browse_thread/thread/9c9e84a850dd00bc

HunabKu: Enhanced Query Object
http://fabiomaulo.blogspot.com/2010/07/enhanced-query-object.html

Implementing Repository Pattern With Entity Framework
http://www.codeproject.com/KB/database/ImplRepositoryPatternEF.aspx

Entity Framework as Repository and UnitOfWork?
http://stackoverflow.com/questions/520065/entity-framework-as-repository-and-unitofwork

Repository or DAO?: Repository
http://fabiomaulo.blogspot.com/2009/09/repository-or-dao-repository.html

Repository or DAO?: DAO
http://fabiomaulo.blogspot.com/2009/09/repository-or-dao-dao.html

Repositories for Value Objects?
http://tech.groups.yahoo.com/group/domaindrivendesign/message/17972

How to use dependency injection and the repository pattern with ASP.NET web services?
http://stackoverflow.com/questions/1449870/how-to-use-dependency-injection-and-the-repository-pattern-with-asp-net-web-servi

FubuMVC Contrib
http://code.google.com/p/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
http://www.simplyvinay.com/Post/50/MPBlog-Implementation.-Part-4.aspx
NHibernate Repository and Unit Of Work

Linq specifications: from Argentina with Love
http://joseoncode.com/2009/12/24/linq-specifications-from-argentina-with-love/

IRepository interface
http://weblogs.asp.net/alexeyzakharov/archive/2009/11/18/irepository-interface.aspx

nHibernate, Linq and Queries
http://lucisferre.net/2009/05/19/nhibernate-linq-and-queries/

The DAL should go all the way to UI
http://ayende.com/blog/3958/the-dal-should-go-all-the-way-to-ui

Returning IQueryable<T>
http://weblogs.asp.net/fredriknormen/archive/2008/12/01/returning-iqueryable-lt-t-gt.aspx

Generic Repository
http://grepo.codehaus.org/
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
http://codebetter.com/iancooper/2009/10/08/the-catalogue-metaphor-and-command-query-seperation-architectures/
Query Objects vs Methods on a Repository
http://www.udidahan.com/2007/03/28/query-objects-vs-methods-on-a-repository/

Using Repository and Unit of Work patterns with Entity Framework 4.0
http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx

AltNet-Argentina: DAO, Repository y clases Query
http://groups.google.com/group/altnet-argentina/browse_thread/thread/a3f5324ab8418277?pli=1

DDD: The Generic Repository
http://codebetter.com/gregyoung/2009/01/16/ddd-the-generic-repository/

My Links
http://www.delicious.com/ajlopez/repository

More links about other patterns are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

January 14, 2011

Design Patterns in an Interpreter, using TDD

Filed under: .NET, C Sharp, Patterns, Test-Driven Development — ajlopez @ 11:26 am

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 Patterns20101017.zip.

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:

http://www.dofactory.com/Patterns/Patterns.aspx

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
http://www.ajlopez.com
http://twitter.com/ajlopez

Create a free website or blog at WordPress.com.