Entity Framework Plugin Architecture Recommendation

I am trying to create a modular ASP.NET MVC application using scopes and dependencies. The application currently consists of the following projects:

  • Framework.Contracts (interfaces for the authentication, authorization, logging service)
  • Framework (implementation of authentication, authorization, ...)
  • Framework.Web (MVC web application)

Each plugin consists of an MVC Area project, contracts and service implementation:

  • EmployeesPlugin.Contracts (Interfaces for IEmployeesService)
  • EmployeesPlugin (Implentation for IEmployeesService)
  • EmployeesPlugin.MVC

I want to use Entity Framework Database First or Model First (since I need to connect an existing database). My problem is that I do not know how to freely judge my entities. I do not want to put them in one common DatabaseLayer project. Rather, I would like to define central objects (User, Settings, LogEntries, ...) for the Framework project and additional objects (for example, Employee, Company) for each plugin.

After reading the ORM Architecture: one or more models (Entity Framework) I thought about creating several models (i.e. multiple data contexts). Actually, I don't like the idea of ​​having redundant code.

I was thinking of creating interfaces that display the properties of each object. These interfaces will be placed in the project for the plugin. How IEmployee expose FirstName and LastName . Then I started creating an IEmployeeRepository to return and create, edit, and delete Employees. However, creating employees does not work if you expose only IEmployee and no specific class.

Another problem is that the Employee object contains references to objects in other projects / plugins. Suppose an employee has several projects. Thus, I decided to create a common IEmployee interface without a project link and an IEmployeeProjects interface containing a link to projects. Thus, I could create an Employee class in a central database-level project that implements both IEmployee add `IEmployeeProjects:

 public class Employee : IEmployee, IEmployeeProjects { // From IEmployee interface public string FirstName { get; set; } public string LastName { get; set; } // From IEmployeeProject interface public virtual ICollection<Project> Projects { get; set; } } 

The problem is that I do not know how to confuse things using the Entity framework.

+4
source share
1 answer

You create a loose connection by removing any tough relationships between them. Instead, simply use identifiers to refer to other objects. It also means that each plugin uses its own DbContext.

Then use the repositories in each plugin to load related objects. It also means that each plugin must define its repository interfaces in a separate assembly that can be used by other plugins.

I also usually create the main object, where I define all the entites, services and repositories that the kernel provides.

+1
source

All Articles