Structure for switchable data access level

I need to write a data access layer using the Entity Framework. One of the requirements is to allow the configuration file to control where the data comes from. With one configuration setting, it should come from the database; on the other, from a web service.

Now, my initial thought is to have 3 DataAccess classes:

  • WidgetDataAccess
  • WidgetDatabaseDataAccess
  • WidgetWebServiceDataAccess

All of them will implement the same interface. WidgetDataAccess will read the configuration and delegate the correct child class. That seems reasonable, right?

Is there any template I should follow, or anyone with a better way to structure this?

+4
source share
1 answer

Yes, the repository template / UnitOfWork.

  • Widget.Core : your MVC application uses only the Widget.DAL namespace, a dependent, into which either Widget.DAL.DatabaseService or Widget.DAL.WebService is entered based on your configuration file.
  • Widget.DAL : IRepository, IUnitOfWork, IWhateverYouNeed, DTOs
  • Widget.DAL.DatabaseService : models and entity structure context. Implementing Widget.DAL Interfaces Using an Entity Framework Context
  • Widget.DAL.WebService : web client, domain objects, implementation of Widget.DAL interfaces using your web client
+1
source

Source: https://habr.com/ru/post/1441860/


All Articles