Search code examples
onion-architecture

in which layer should i implement viewmodel to domain model mapping in Onion architecture?


Hi I am new to the onion architecture. I have 3 projects in solution, 2 class libraries and an MVC web application.

  1. Core: which have repository interfaces,domain models and business logic. [core has no dependency]
  2. Infrastructure: which have DBContext, Repository classes.

i am injecting dependency using Unity in controller of web app. Please suggest where should i put ViewModel to DomainModel Mapping? should i create a new layer? what are the best practices and project architecture for onion architecture?


Solution

  • I would do the mapping in your MVC project. View models are a UI concern so you already have a place to do this.

    I would suggest reading the Putting Your Controllers On A Diet series of articles by Jimmy Bogard as a starting point for some good practices:

    https://lostechies.com/jimmybogard/2013/10/29/put-your-controllers-on-a-diet-gets-and-queries/