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 1049601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:38:34+00:00 2026-05-16T16:38:34+00:00

How do you apply validation in an MVP/domain environment ? Let me clearify with

  • 0

How do you apply validation in an MVP/domain environment ?

Let me clearify with an example:

Domain entity:

class Customer
{
  string Name;
  etc.
}

MVP-model

class CustomerModel
{
   string Name;
   etc.
}

I want to apply validation on my domain entities but the MVP model has it’s own model/class
apart from the domain entity, does that mean I have to copy the validation code
to also work on the MVP-model?

One solution I came up with is to drop the MVP-model and use the domain entity as MVP-Model,
but I don’t want to set data to the entities that isn’t validated yet.
And second problem that rises is that if the entity has notify-events,
other parts of the application will be affected with faulty data.

A third thing with that approach is if the user edits some data and then cancels the edit, how do I revert to the old values ? (The entity might not come from a DB so reloading the entity is’t possible in all cases).

Another solution is to make some sort of copy/clone of the entity in question and use the copy as MVP-model, but then it might get troublesome if the entity has a large object graph.

Anyone has some tips about these problems?

  • 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-16T16:38:35+00:00Added an answer on May 16, 2026 at 4:38 pm

    Constraining something like the name of a person probably does not rightfully belong in the domain model, unless in the client’s company there is actually a rule that they don’t do business with customers whose names exceed 96 characters.

    String length and the like are not concerns of the domain — two different applications employing the same model could have different requirements, depending on the UI, persistence constraints, and use cases.

    On the one hand, you want to be sure that your model of a person is complete and accurate, but consider the “real world” person you are modeling. There are no rules about length and no logical corollary to “oops, there was a problem trying to give this person a name.” A person just has a name, so I’d argue that it is the responsibility of the presenter to validate what the user enters before populating the domain model, because the format of the data is a concern of the application moreso than the domain.

    Furthermore, as Udi Dahan explains in his article, Employing the Domain Model Pattern, we use the domain model pattern to encapsulate rules that are subject to change. That a person should not a have a null name is not a requirement that is likely ever to change.

    I might consider using Debug.Assert() in the domain entity just for an added layer of protection through integration and/or manual testing, if I was really concerned about a null name sneaking in, but something like length, again, doesn’t belong there.

    Don’t use your domain entities directly — keep that presentation layer; you’re going to need it. You laid out three very real problems with using entities directly (I think Udi Dahan’s article touches on this as well).

    Your domain model should not acquiesce to the needs of the application, and soon enough your UI is going to need an event or collection filter that you’re just going to have to stick into that entity. Let the presentation layer serve as the adapter instead and each layer will be able to maintain its integrity.

    Let me be clear that the domain model does not have to be devoid of validation, but the validation that it contains should be domain-specific. For example, when attempting to give someone a pay raise, there may be a requirement that no raise can be awarded within 6 months of the last one so you’d need to validate the effective date of the raise. This is a business rule, is subject to change, and absolutely belongs in the domain model.

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

Sidebar

Related Questions

Is there a way to apply fade effect after validation. For example the user
I am using MVC 3 and have a customize model class to apply the
i. e How to apply validation on single property of a model while ignoring
I need to apply validation on input time intervals that are taken in as
I have a few custom form validation rules I wish to apply. Things like
I have been given the task to apply regular expressions on a form validation
I need to apply a css class to invalid controls on a web form.
I have the following validation code processed for my User Model. It works good
I got my form in jQuery ui dialog and I apply client-side validation in
I have two pages apply.php and registration.php. In registration.php , i have if(isset($_POST['submitted'])){ //validation

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.