Can I use the Repository to do the BLL part?

Posted on

Question :

I was reading about Repository vs Dao and I saw the following sentence:


[…] The Repository standard is intended to support the domain model
  providing persistence. Unlike DAO, which is an object of
  application infrastructure and is part of the persistence layer, the
  Repository is part of the domain model that is part of the

So, can the repository be used as a class for BLL?


Answer :

Depends: If in your project you want your business layer (BLL) to have no references to data access technologies, data mapping, etc … of the structure of your project you can use this design pattern . But the implementation of the Repository will not necessarily fall within your business layer (BLL).

Repository isolates domain (business-related) objects from access code details and mapping these objects to the database. That is, it adds a separation layer between the data access and domain layers.

This means that if you have a business layer (BLL) in your application, you can use this design pattern to have a clear separation between your data access layers and your business layer .

Por que ter essa separação e cenário onde utilizei:

I’ve worked a little with Domain Driven Design ( DDD ) and in this scenario if you put your Repository within your business layer, you may end up having technology references (eg NHibernate, Entity, etc.), which is not recommended (since business rules have no relation to the technologies used in the project, the idea here is you do not mix these two things) when using DDD.

In this case we then insert the Interface (s) of the repository (s) into the business layer, letting the infrastructure layer deploy the repository interfaces and this layer does have reference to the technologies used for recovery, persistence of data, etc.


The Repository can not only be in the BLL ( Business Logic Layer ), as it is the place of it, it will serve basically as the intermediary of your application for your DAL ( Data Access Layer ) where your DAO

Of course depending on the architecture, the size of the project, or the “I want so and end point” , you can also nest the two under the same layer.

I have already implemented business rules (BLL) within Repository classes (DAO).
I did not see problems in this, and it’s very practical.

When needed, you can refactor the code easily, and extract this code to a BLL class.


You can abstract the Repository into one more layer in your application, and it is not wrong to apply your business rules within it. It would be wrong if you were doing this directly in DAO


Leave a Reply

Your email address will not be published. Required fields are marked *