Let's assume we have an ASP.NET MVC web application with following tiers:

  • Business logic
  • Entities (business domain and database POCOs)
  • Common (resources, consts)
  • Data access (database EF queries, EDMX EF models and so on)
  • Web application (MVC web application)

We're using view models approach. Currently view models are placed in Entities layer. Data access queries returns view models (due to efficiency issues, so we avoid using mapper).

Web layer references all other layers. Data access references Common and Entities layers. Business logic references Entities and Common layers, in the future also Data access layer.

There's an idea to move view models to Web layer. Why? Because they're in fact bound with a particular technology (MVC) and UI implementation. But we're facing a problem here, because in this scenario Data access layer must reference Web and Web references Data access, so we have a circular dependency issue.

Moreover we have scenario when some validation of view model requires reference to Data access layer. We're going to keep validation method inside view models. Currently we want to implement it by injecting database context class (which is in Data access layer) to view model by constructor.

Do you have any idea how can we avoid it? Is it good idea to keep view models inside our Web layer?

  • 1
    What is the point of having business logic if your web app can just bypass it and go straight to data access?
    – JeffO
    Commented Apr 3, 2015 at 12:24
  • So Data access layer should only expose db context and Business layer should contain queries? I rather thought that Business layer will have some other business logic, not related to database access like for instance e-mail sending. Anyway, even if we move queries to Business logic and view models to web project we still have circular reference... Commented Apr 3, 2015 at 12:39

2 Answers 2


I keep view models in the web project, for reason you stated, it's usually only useful to the relevant view.

I'm not sure why your data access layer would reference the web project though?

  • If view models are placed in Web project (Web layer) then Data access layer which is returning view models must reference Web. Commented Apr 3, 2015 at 12:35
  • Ah, different terms for different things. I would call the representation of DB objects just Models. They have property for each column in DB. A view model takes Models and other required things (maybe lists for drop downs for instance), and gathers it all together - everything the view needs. A view usually doesn't match up exactly with 1 DB table. Commented Apr 3, 2015 at 12:45
  • You're right, but we really return view models in Data access methods. It's done so to avoid overhead by mapping models to view models. Commented Apr 3, 2015 at 12:55
  • 2
    That "overhead" is what allows a nicely separated layer. Commented Apr 3, 2015 at 13:09
  1. If you keep ViewModels in web project, You will need them in Business Logic, When calling repository and converting domain model to View model. And you cannot add Web project reference in Business Logic.
  2. If you keep it in Entities, that is good. But one issue. You will be using ViewModels in Web project. And adding Reference to Entities will expose Domain Models to web project. That is not good.

Based on the issues, It is suggested to keep View Models in a separate project. So, It can be referenced where needed without exposing any thing not needed. And will also resolve the issue of circular reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.