DDD Application Service Domain Model to View Model Mapping
Asked Answered
E

1

9

My understanding of the application services are that they link between the domain and the user interface together. In other words, they serve the controller to perform operations on the domain.

I have the following project layout in my application:

  • Domain Core
  • Infrastructure
  • Service Interfaces
  • Web UI
    • ViewModels
    • Views
    • Controllers
    • Services (Application Services)

My Service Interfaces lies outside the Web UI project. Then in the Web UI Project I implement the services interfaces under Services.

However this structure is a bit flawed and creates a circular dependency when we put this in practice. I tried to follow the architecture in this link: https://www.develop.com/onionarchitecture

For a given service, I want to pass in the view model, perform operations on the domain based on the view model, then return an updated view model. Is this approach wrong?

Is my understanding correct that the application service in essence take the view model as a parameter, update some details in the domain and view model if it needs and then returns a view model?

Or

Does the application service only deal with c# datatypes and domain models as a parameter and returns the same datatypes? In other words does not get or set any information in a view model. In fact does not know the view model exist.

I just need some clarification on what is the best approach from a strict DDD approach.

Encyst answered 20/8, 2015 at 20:4 Comment(3)
Application services do not usually live in the presentation (UI) layer, there's an Application layer for that purpose.Gare
Do do i create a different project for those service implementation or put them under Services, where my interfaces lies?Encyst
You can keep all things together in one project, as long as you dedicate a directory for each component/layer.Ontario
J
4

Answering your questions: Yes, you are right. For MVC application, you can design layer that takes and returns ViewModels and operate with Domain inside

Good example of solution structure is made by Dino Esposito here. I adopted my project to this structure and it became much clear. My opinion is that onion architecture is overcomplicated for small or medium projects.

Jackquelinejackrabbit answered 21/8, 2015 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.