0

My exhibition architecture like this:

The Web project contains an MVC view and WebAPI controls that return something and receive something. The Domain project includes a domain model The Core project includes DTOs from microservices and services, with whom they communicate

Where to put models view now?

  1. In a Web project, and there map the domain to the viewmodel - it is only for presentation and data reception
  2. In the Core project and servicing WebApi controllers, you should already return viewmodels - domain, viewmodel and DTO services.

What do you recommend? What is your opinion? Maybe there is a standard?

Nerf
  • 938
  • 1
  • 13
  • 30
  • 3
    well view models only apply to the presentation layer, so that would be the obvious place. You shouldn't return a viewmodel from the API IMHO. Instead the viewmodel may be composed of objects (or objects derived from) from multiple services, if necessary. Sometimes there might a 1-1 mapping too, but that's mere coincidence. This is entirely a design decision for you, though, and opinion-based questions like this aren't generally a good fit for the SO format. You tend to get opinions, like mine, rather than concrete fact. There are lots of theories, but no "correct" answer. – ADyson Jul 14 '17 at 13:42
  • Yes, but then what about "application services" with join results of few services and return something to webapi? – Nerf Jul 14 '17 at 13:47
  • @Nerf, you can call more than one services from application backend and сombine to simple model and another logic from simple model to your webapi. Also you can cache results from your API. – itikhomi Jul 14 '17 at 13:53

1 Answers1

3

Your WebAPI does not return view models. It can return domain models, DTOs, true or false, nothing, but not ViewModels. View models should be shaped in whatever way your view, UI, needs it.

So it is possible to have some redundant objects, but it is always best practice to have viewmodels shaped for your view.

You should probably create a ViewModels folder in your web app and put them in there.

Fabio S.
  • 460
  • 7
  • 22