0

Should I put my DTO objects inside my domain service / business layer?

Can such properties have data annotations, is this good practice? Especially for client side validation with asp.net mvc 2? (I dont have access to asp.net mvc3 otherwise I would have access to the IClientValidator? or something similar interface)...

Otherwise all my valdiation is in c# and I bubble any errors up to the UI or web project

I hope to translate the DTO to Entities inside my domain service layer so answers to the above is appreciated..

1 Answer 1

2

You should put your DTOs in a separate assembly to avoid layer coupling.

Read more here: http://martinfowler.com/eaaCatalog/separatedInterface.html

Can such properties have data annotations, is this good practice

Yes, I think so. Since it enables all layers to validate the object without code duplication. Attributes are also added to sandcastle generated help files which lets everyone reading it see what contract requirements your models/DTOs has.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks... the data annotations I will only really use for asp.net mv2 if I move onto v3 i will use the options available there...
I'm using DataAnnotations in mvc3 too. What other options are you referring to?
client side validation... I think in mvc3 as far as I can remember there is an option to hook onto the client side validation, the way I have done my business logic is in c#, I would implement the relevant interface so client side validation can also be shown to the user... I dont think I understood this correctly and I think I may need to look into this... Do you know a way I could hook onto the client side validation in mvc2 without using data annotations?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.