ASP.MVC: Repository that reflects IQueryable but not Linq to SQL, DDD How To question

Assuming that your LINQ to SQL (L2S) classes are auto-generated and reflects your underlying database, the short answer is: Don’t expose IQueryable of any of your L2S classes – it would be a Leaky Abstraction. The slightly longer answer: The whole point of Repositories is to hide data access behind an abstraction so that you … Read more

MVVM: Binding to Model while keeping Model in sync with a server version

In the past I ‘ve written an application that supports “live” editing of data objects from multiple locations: many instances of the app can edit the same object at the same time, and when someone pushes changes to the server everyone else gets notified and (in the simplest scenario) sees those changes immediately. Here’s a … Read more

The repository itself is not usually tested?

Repository interface belongs to domain layer. But implementation belongs to infrastructure or data access layer. This implementation is usually not tested with unit test. It uses ORM API heavily, so it is extremely hard and wasteful to test repository in isolation. This problem is not specific to repositories: Don’t mock types you don’t own. Repository … Read more

DDD – the rule that Entities can’t access Repositories directly

There’s a bit of a confusion here. Repositories access aggregate roots. Aggregate roots are entities. The reason for this is separation of concerns and good layering. This doesn’t make sense on small projects, but if you’re on a large team you want to say, “You access a product through the Product Repository. Product is an … Read more

Refactoring code to avoid anti-pattern

I wouldn’t say that it’s an anti-pattern since an anti-pattern is supposed to be a pattern in the first place (a recognizable, widespread way of doing things) and I don’t know of any “Repository-in-the-Domain-object” pattern. However, it’s certainly bad practice IMO because your BankAccount domain object mixes 3 responsibilities : Its natural and legitimate responsibility … Read more

How to remove unit of work functionality from repositories using IOC

You shouldn’t try to supply the AcmeDataContext itself to the EmployeeRepository. I would even turn the whole thing around: Define a factory that allows creating a new unit of work for the Acme domain: Create an abstract AcmeUnitOfWork that abstracts away LINQ to SQL. Create a concrete factory that can allows creating new LINQ to … Read more

Should I abstract the validation framework from Domain layer?

Just like the repository abstraction? Well, I see a few problems with your design even if you shield your domain from the framework by declaring an IUserValidator interface. At first, it seems like if that would lead to the same abstraction strategy as for the Repository and other infrastructure concerns, but there’s a huge difference … Read more