Repository pattern in CSLA

We use Repository Pattern inside our CSLA BO to extract data access code into a separate class – repository object,  because we use interface IRepository to loose couple BO and concrete Repository object and implement “design by contract”, so BO doesn’t care which technology repository is using, either using or Linq to SQL, or NHinbernate or Entity Framework .

The benefits of using this model include:

  • Loose coupling between BL and DAL
  • Easy to switch to different Data Access technology
  • Central place to control and switch IOC container

Updated at Feb. 09, 2009:
Found this post about the difference between DAO and Repository pattern. Yes, my model is more similar to DAO, because I was following one Repo/DAO per table rule. In fact, I’m on the progress of switching to the new Csla.ObjectFactory which is a real repository class, or, at lease, can be a repository wrapper, as Ryan did in his example.


6 thoughts on “Repository pattern in CSLA

  1. I like this approach, and we are thinking of using a similar technique. For me this is DAO not a repository (although I’m pretty new to this.) From what I have read the Repository pattern lives above the BO.

    Regardless of that, have you had any issues with memory, as you will have to copy the contents of DTO into BO. If you have a BusinessListBase with many records then the memory will consume twice the amount?

  2. I always thought DAO and Repository are almost same. Maybe I should look back to the defination more detail. Anyway I think if using LinQ2Sql yield return properly, memeroy won’t be a big issue.

  3. Pingback: TechFocus2.0 » CSLA 3.6: Object Factory intro

  4. In case you are still not clear. Here is my IRepository definition:

    public interface IRepository

    DTO FindById(int id);

    DTO Insert(DTO data);
    DTO Update(DTO newData, DTO oldData); // Our Stored Procedure is very old fashion. We don’t have choice.

    void Delete(DTO data);


    public interface IDynamicQueryable
    IEnumerable FindAllByCriteria(string criteria);
    IEnumerable FindAllByCriteria(Func criteria);

    public interface INameValueListRepository
    Dictionary GetAll();

  5. Pingback: Mock/Test DataAccess Funtions in CSLA « maonet technotes

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s