The goal of this post is to clarify an architecture of a single page application using the following technologies:
- ASP MVC
- AngularJS
- WebAPI
- Entity Framework
The next diagram shows at the left the client side and at the right the server side:
The first row is the communication between the different used technologies.
The middle row represent the logic of our application and the last the data containers used on these classes.
Using the previous diagram is easy to see which data each layer uses.
e.g:
- The Angular controller can only work with the Angular context.
- The WebAPI controller send and receive data in JSON format. The JSON objects are automatically translated to C# view models. The WebAPI controllers are also able to map the view-models to domain objects to use the domain services. WebAPI controllers can also request domain objects to the domain services and translate it to ViewModels c# before sending it back to the client-side in JSON format.
Data containers and layers:
- AngularJS Context: The context is populated by the angular repository. HTML templates bind to it.
- ViewModels Json: The data is sent from client to server side and vice versa in JSON format. The WebAPI controller send automatically by default the data in this format. The send and received data in JSON format is mapped automatically to the expected object.
- ViewModels C#: The data the WebAPI controller send and receive as parameter. The conversion between Json and C# view models is done automatically by the WebAPI controller. This class is a subset of our entity domain objects plus some calculated properties that our views may need. It can be used for example to keep some server-side data hidden on the client-side.
- Entities: Entity Framework entities or domain specific classes. All the data related to the domain. Theses classes are completely independent of the view. The domain services or application logic must use theses classes. The mapping from and to Entities to c# view models can be done automatically or Auto-mapper.
Superb, what a blog it is! This blog presents helpful data to us, keep it up.
LikeLike
Hi Juan carlos, in the backend the mapping from viewmodel to domain model should be in the services. So the controller only know viewmodels
LikeLike
Thanks for your feedback!
LikeLike