views:

9

answers:

1

Hello,

One thing that I'm confused about in regards to DDD is that our domain is supposed to handle all business logic and enforce invariants. I have noticed some people (me included) handle certain invariants in the presentation layer (i.e. WebForms, Views, etc) with javascript. This is mainly done to improve performance so the server is not hit for every request which may be invalid.

Even though this approach may be beneficial performance-wise, it violates DDD principles. What if the business rules are changed? This way we don't have a rich domain where all the business rules are captured. In case of a change, we should change the domain as well as the presentation layer.

Has anyone come across this situation before?

I'd like to know your thoughts on this.

Cheers,

Mosh

A: 

One framework that supports DRY, and both server and client side validation, is ASP.NET MVC 2.

This is done by generating JavaScript from the model rules that is sent to the client.

You can read more about it here: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

Martin R-L
I know about the validation features in ASP.NET MVC 2. However, what I am referring to here is more complex validation rules. Like:If some checkbox is checked, and there are no items added to the list Then display some message. It is more than the validating input fields against null, or data range, etc.
Mosh
If you want your code to be DRY and solve complex model validation client-side, I suggest you allow your entities to be in invalid states, and have them report what's invalid (I often use a BrokenRule collection of some sort).Then your Controller/Presenter/ViewModel uses that information in order to update the View accordingly.
Martin R-L