I am building a CRUD application with Entity Framework Model First approach. my application is structured in a way that the UI LAYER and the DAL both depend on the Domain Layer, and the domain layer doesn’t depend on anything. the Domain layer exposes repository and domain object interfaces only. the repositories are implemented in the DAL and provided to the domain layer through dependency injection. as all repositories, my repositories expose functions like getCustomer, deleteCustomer, etc. but since those functions are implemented in the DAL, the DAL has to be able to create objects adhering to the interfaces in the Domain layer. now my binary choice is how should i let it do that: should i use abstract factories and inject them into the DAL or extend the definition of the partial generated entities and make them implement the interfaces exposed by the domain layer ?
I am building a CRUD application with Entity Framework Model First approach. my application
Share
In this type or architecture (hexagonal architecture), domain objects shouldn’t have interfaces, only the repositories. Instead, have the DAL create (reconstitute) domain objects directly. There is no benefit gained in abstracting domain objects into interfaces, only needless complexities, such as factories.
Also, as pointed out by Heather, abstracting the repository is often a needless complexity as well. Making a repository abstraction which is truly portable across implementations is almost always futile. The central benefit of the repository abstraction, in my opinion, is that of encapsulation which can be attained without interfaces – just reference the implementing class directly.