Blog Stats
  • Posts - 62
  • Articles - 1
  • Comments - 35
  • Trackbacks - 76

 

Domain Validation Considerations

I have an Aggregate called Person that has a method called AddAddress which accepts an IAddress invariant to (hopefully) be added to the Person.Addresses collection. Within the method body of AddAddress, I am invoking a Command object that goes down a list of Specifications and if all are passed, then the address is added to the collection. So far so good.

Now, i am calling this method from my Service layer and am expecting an IAddress object in return. If it fails, what is the best way of communicating that back to the client-caller (Service)? I don't like using exceptions for this kind of granularity and it seems like Aspect Oriented Programming might be screaming at me to apply its paradigm.

If I am applying a kind of 'lazy' validation on Domain entitiies (it doesn't know it is invalid until an object has been added to it to make it so), what is the best way or messaging back to my caller that the attempted action bombed and HERE'S WHY. I could return a Specification that wraps the return object and has the specs that were broken along the way in the Command pattern...but that seems stinky.

What has been your experience with this?


Feedback

# re: Domain Validation Considerations

Gravatar The basic rule for raising exceptions is that if a method can't do what it says it's going to do (i.e. AddAddress) then you raise an exception. Check out Scott Hanselman's blog post for additions tips.

www.hanselman.com/blog/GoodExceptionManagementRulesOfThumb.aspx 9/5/2006 5:25 PM | David Totzke

# re: Domain Validation Considerations

Gravatar Thanks...
exceptions to me are when something exceptional happens in an app, not when an operation fails (such as due to user weird data)...I expect that stuff to happen.
Looking more for OO or AOP methods for elegant solutions to managing validation on events.
My method works great, but would like to hear folks who use patterns in lieu of exceptions. 9/5/2006 7:07 PM | Mike

Post a comment





 

Please add 8 and 4 and type the answer here:

 

 

Copyright © Mike Nichols