samedi 20 juin 2020

How to setup project structure for EF and Repository Pattern

Im working my way through a tutorial for EF 6 and Repository pattern. The entire project is broken into folders but im attempting to understand how i could separate this into separate layers/class library projects.

I currently have the below (Using DB first approach)

EDMX file connected to my DB (for this example i will use 2 tables Customers and Addresses)

Partial classes (overriding Customers and Addresses)

IRepository (Interface public interface IRepository<TEntity> where TEntity : class) - this interface is then used to create other Repositories i.e. ICustomer (public interface ICustomer : IRepository<Customer>

I then have IUnitOfWork.

Finally a web application (Web forms).

SO my approach is to add a Class Library (I will call this DAL) add EF 6 and my EDMX context file along with a folder for all Entities needing a partial class for.

How should the remaining areas be separated into class libraries? Should i have IRepository in a separate class (maybe called Services) if yes would i just add the Customer/Addresses interfaces into this library along with classes that would have pull the data i.e. Add, Get Delete?

For Unit of Work - should this also reside in another class library?

WebApp - as per the course I would add a reference to unit of Work class library (As far as i understand).

Would be great if someone can show me an example to fill in this missing gap as i have seen some online threads but cant find a way to connect everything?

Aucun commentaire:

Enregistrer un commentaire