Having a repository dependent on another repository

Repository should have single responsibility – persist one kind of entity. E.g. employees. If you have to delete some associated records from other repository, it looks like business logic. E.g. When employee is fired we should remove his work log And usual place for business logic is a domain services. This service will have both … Read more

Repository Pattern – Caching

It’s a good idea not to put the caching logic directly into your repository, as that violates the Single Responsibility Principle (SRP) and Separation of Concerns. SRP essentially states that your classes should only have one reason to change. If you conflate the concerns of data access and caching policy in the same class, then … Read more

Entity Framework 6 Code First – Is Repository Implementation a Good One?

@Chris Hardie is correct, EF implements UoW out of the box. However many people overlook the fact that EF also implements a generic repository pattern out of the box too: var repos1 = _dbContext.Set<Widget1>(); var repos2 = _dbContext.Set<Widget2>(); var reposN = _dbContext.Set<WidgetN>(); …and this is a pretty good generic repository implementation that is built into … Read more

Repository pattern and mapping between domain models and Entity Framework

My repositories deal with and provide persistence for a rich domain model. I do not want to expose the anemic, Entity Framework data entity to my business layers, so I need some way of mapping between them. If you you use Entity Framework, it can map Rich Domain Model itself. I’ve answered the similar question … Read more

Repository pattern – Why exactly do we need Interfaces?

So how interfaces come into picture ? Like this: public interface IEmployeeRepository { Employee[] GetAll(); } and then you could have as many implementations as you like: public class EmployeeRepositoryEF: IEmployeeRepository { public Employee[] GetAll() { //here you will return employees after querying your EF DbContext } } public class EmployeeRepositoryXML: IEmployeeRepository { public Employee[] … Read more

How does a service layer fit into my repository implementation?

Take a look at S#arp Architeture . It’s like a best practices architectural framework for building ASP.NET MVC applications. The general architecture pattern is to have 1 repository per entity which is responsible only for data access and 1 service per repository which is responsible only for business logic and communicating between controllers and services. … Read more

Transactions in the Repository Pattern

Booting my computer this morning I faced the exact problem for a project I am working on. I had some ideas which lead to the following design – and comments would be more than awesome. Unfortunately the design suggested by Josh isn’t possible, as I have to work with a remote SQL server and can’t … Read more

Unit of Work + Repository Pattern: The Fall of the Business Transaction Concept

I do agree with your concerns. I prefer to have an ambient unit of work, where the outermost function opening a unit of work is the one that decides whether to commit or abort. Functions called can open a unit of work scope which automatically enlists in the ambient UoW if there is one, or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)