What is the benefit of using a repository?

Feb 5, 2008 at 3:48 AM
Aside from the fact that you can mock a repository, is there any other reason to use a repository instead of a standard data access layer?
Feb 5, 2008 at 11:59 AM
You get the entity, CRUD and mapping generation, that in my opinion avoids a lot of monkey code writing. You also get the error handling and the dependency injection that allows the mocking for tests and makes your business logic agnostic from your database implementation, you can generate repositories for SQL & Oracle (if needed), and use the one you need in a particular implementation just changing the configuration.
Feb 5, 2008 at 5:18 PM
In many ways, the repository classes are a data access layer; they serve the same function. However, rather than returning data readers or DataSets, they return domain objects, thus putting the focus on the domain model. If you like the "domain model pattern" repositories are the way to go. If you don't, then use DataSets or data readers.

Or did I misunderstand what you meant by "standard data access layer"?
Feb 5, 2008 at 7:23 PM


jschmiede wrote:
You get the entity, CRUD and mapping generation, that in my opinion avoids a lot of monkey code writing. You also get the error handling and the dependency injection that allows the mocking for tests and makes your business logic agnostic from your database implementation, you can generate repositories for SQL & Oracle (if needed), and use the one you need in a particular implementation just changing the configuration.


If I understand correctly, the CRUD generation and mapping is a feature of the PNP RF's code generation, not something intrinsic to a repository.

I can see value in using dependency injection, but for what I do, being database agnostic isn't all that important. Same for mocking. Our tests go through the database and then we rollback any changes, so we don't really need to mock the DAL. I guess if we were really trying to test better we would test the DAL and then mock the DAL to test the business layer.

Can you tell me what type of error handling the repository provides? Typically, we don't handle any exceptions in our DAL, we let them bubble up to the application to be handled.

Feb 5, 2008 at 7:25 PM


ctavares wrote:
In many ways, the repository classes are a data access layer; they serve the same function. However, rather than returning data readers or DataSets, they return domain objects, thus putting the focus on the domain model. If you like the "domain model pattern" repositories are the way to go. If you don't, then use DataSets or data readers.

Or did I misunderstand what you meant by "standard data access layer"?



I think you understood me correct. But when is the difference between using a repository, and using some DAL class that returns business objects?
i.e.
dim invoices as list(of invoice) = DAL.GetInvoices(customerId)
Feb 6, 2008 at 10:15 AM
I want to use wcsf for an ecommerce website.
Is it better/simple to use Repository factory or NetTiers for DAL ?
Feb 6, 2008 at 1:57 PM
It Implements special exception for duplicate key & sp argument error
Feb 6, 2008 at 1:59 PM
I´m using Rep factory, its easier than use hand made dal, but it is just another name for the same thing