Here’s my problem: I use EntityFramework 4.1 Model first, and I have two assembly (Domain and Store)
The domain contains all my business logic
Store manages all persistence logic to the database
So I do not want any entity framework query in my Domain. I use a repository to expose the Store. The Hic! My edmx is in the Store, so the TT that generates my business classes too. As I want my business classes in the assembly’s Domain , I moved the TT into the Domain and change the namespace of code generator. I must refer my Store to know my Domain classes (logic !). But how to call my repository from my Domain without creating a circular reference …?
Summary:
- My Store reference Domain to know the business classes.
- My Domain reference Store to know the repository
You need a repository interface in your domain layer. Then the repository implementation is in your infrastructure layer, and uses EF. This way your infrastructure layer depends on your domain layer (via the implementation of the repository interface, and the creation/retrieval of domain entities), but the domain does not depend on the infrastructure layer.
A good explanation of this general architectural pattern is given in Jeffrey Palermo’s articles on the “onion architecture”.