Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 821547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:39:30+00:00 2026-05-15T02:39:30+00:00

When developing in ASP.NET MVC I use a 1:1 ViewModel setup where the viewmodel

  • 0

When developing in ASP.NET MVC I use a 1:1 ViewModel setup where the viewmodel contains only the data required by the view. I’m also using data annotations to validate on the viewmodel.

My concern is that this is not following the DRY principle as I find myself having to duplicate validation throughout my sites. I’d love to have validation in one place (my domain model) but because I never send the domain model to the view model this is not possible.

I was wondering if anyone else has ran into this issue and found a suitable method of working around it or has a better solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:39:31+00:00Added an answer on May 15, 2026 at 2:39 am

    We had similar concerns when we adopted a 1:1 ViewModel approach. We found that 1) the duplication is less than appears at first and 2) that the overall maintainability and power of the application is improved enough that any non-DRY costs are worth the price.

    We ended up thinking about validation for the ViewModel and domain models from different perspectives (separation of concerns). When implementing validation at the domain level model we’re looking for comprehensive security to prevent attacks. We’re also detecting serious “contract” violations that indicate bugs in the upper layers. When implementing validation at the view model we’re strictly concerned with usability.

    If you approach the models from these different perspectives, there’s less overlap then you might think. The domain layer might allow certain operations that you want to restrict in the ViewModel for usability reasons. Or the ViewModel might assume that only inputs for the rendered view are posted, relying on the domain model for comprehensive security validation designed to prevent attacks.

    1:1 ViewModels also greatly ease testability. Tests for the ViewModel can be written independently of the domain layer which makes unit tests lighter, more maintainable and in general more useful. Likewise, you can test the domain model without the mental contortions of how inputs flow through the user interface. This also adheres to the “defense in depth” security principle.

    We’ve also noticed that Views change much more frequently than the domain layer. There’s a comfort in knowing that you’ve got really good security unit test coverage on your domain model and when you implement a new View, you only need to worry about validation from a usability perspective.

    Lastly, if you anticipate having a web services layer, you’ll find the separation of domain and view models pays dividends. Without it, the domain model inevitably gets written to support the UI. When you layer on the service interface you’ll find there’s an impedance mismatch.

    If there does end up being significant duplication, you can always factor the validation out separately. In our experience, that hasn’t been worth it for all the reasons discussed above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 444k
  • Answers 444k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a good article on this subject: Inserting Excel Charts… May 15, 2026 at 6:44 pm
  • Editorial Team
    Editorial Team added an answer You need to store that value in a variable: DECLARE… May 15, 2026 at 6:44 pm
  • Editorial Team
    Editorial Team added an answer You can do so via the Request.ClientCertificate, which is an… May 15, 2026 at 6:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.