DTO question

3 views
Skip to first unread message

cathal

unread,
Nov 13, 2009, 7:21:46 AM11/13/09
to S#arp Architecture
Hey,
I often see questions about DTO layers, and indeed many of you
advocate them as good practice.
I need a separate DTO layer - one major reason being because I am
using MvcContrib InputBuilders - and the authors of this project can't
stress enough the need for separate and numerous dto's / view-models.

So that's fine - I have my DTO's, and can use auto-mapper to go to/
from my repository (domain) objects.

But my question is as follows:
I'm decorating my dto objects with various attributes, including
validation attributes (using Castle validation). Even if
NHiberate.Validator was being used, there is still the fact that the
dto object is a completely separate entity to the repository object.
Is there any advice on how to merge the validation? Otherwise I'm
maintaining 2 objects - and keeping them consistent will become a
nightmare.

P.s. I can't use the S#arp dto (the one in the controllers that simply
contains the repository object) as the InputBuilder reflects over the
dto to build the form - so I want the dto to be quite flat.

Jonathan Parker

unread,
Nov 13, 2009, 6:31:45 PM11/13/09
to sharp-arc...@googlegroups.com
I would suggest that the DTO should be quite dumb as well as flat and thus not contain any validation.

cathal

unread,
Nov 18, 2009, 5:46:40 AM11/18/09
to S#arp Architecture
Thanks Jonathan.

Significantly I have to decorate my DTO with attributes so that the
form renders automatically via the InputBuilders. However I accept
your point, and perhaps all I need to do is adopt a convention such
that DTO properties have the same name as domain object properties -
that way the validation messages from the domain object validation can
be used directly by the form when rendering the DTO information. Any
DTO specific or manipulated properties I can then simply add a line or
2 of custom validation in the controller action.

Does this sound about right??


On Nov 13, 11:31 pm, Jonathan Parker <jonathanparkerem...@gmail.com>
wrote:
> I would suggest that the DTO should be quite dumb as well as flat and thus
> not contain any validation.
>

Jonathan Parker

unread,
Nov 18, 2009, 7:00:34 AM11/18/09
to sharp-arc...@googlegroups.com
Hmm, I think it's a case of you can't have it both ways. 1. a dumb DTO layer and 2. flow down validation from the domain objects.
I guess it's a trade-off.

--

You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
To post to this group, send email to sharp-arc...@googlegroups.com.
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=.



cathal

unread,
Nov 18, 2009, 9:22:40 AM11/18/09
to S#arp Architecture
@Jonathan

So 1 quick question for you Jonathan.

In your projects where you're passing a custom DAO between views and
controller, how do you perform the validation. Do you use S#arp's
automatic flushing of errors to the model state by validating the
domain object based on the NHibernate validation attribute
decorations?




On Nov 18, 12:00 pm, Jonathan Parker <jonathanparkerem...@gmail.com>
wrote:
> Hmm, I think it's a case of you can't have it both ways. 1. a dumb DTO layer
> and 2. flow down validation from the domain objects.
> I guess it's a trade-off.
>
> > sharp-architect...@googlegroups.com<sharp-architecture%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages