Click here to Skip to main content
14,691,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to set up a layered structure for a Blazor-server application, but seem to be keep getting confused on where classes should reside to keep dependencies loosely coupled. In a lot of examples I see projects called 'Core' and 'Services', but never is there an explanation of what sort of classes should be in these projects.

The structure I have seemed fine, until I realized that the UI needs a reference to both the business layer (for the service injection) and a reference to the DAL for the viewmodel to model mapping. Surely this is not the best way to do this?
Also, should my concrete classes reside in the same layer as the interfaces they are implementing?

Any advice please.

What I have tried:

So far i have the following structure:

DataAccess (project)
 - DAL (folder) Has classes and interfaces for each entity to wrap entity framework CRUD operations
 - Models (folder) Has model classes and DBsets generated by entity framework

Business(project)
 - Services (folder) Has classes and interfaces that make calls to the DAL project, performs some additional logic and return models. Also has classes that have tasks that are not dependent on the data source.

BlazorUI (project)
 - Pages (folder) Has razor components with injected services from the business project.
 - ViewModels (folder) Poco classes with data annotations.
 - Mappers (folder) Classes to convert a ViewModel to a DataAccess.Model and vice versa.
Posted
Comments
Gerry Schmitz 19-Jun-20 19:24pm
   
The UI (i.e. "view") does not reference the DAL, IMO. View - View Model - Model - DAL. Anything else, and you start getting "cycles". Use EF entities (everywhere) before "custom" POCOs.
TheRedEye 20-Jun-20 2:54am
   
Thanks Gerry. Your last statement sounds contradictory unless I'm misunderstanding. Aren't the EF entities the Model in the V-VM-M-DAL? And aren't the custom POCOs the viewmodels in the V-VM-M-DAL?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900