views:

194

answers:

1

Here is the scenario:

  1. There are some domain objects
  2. There are some WCF services exposing business services that interact with these domain objects
  3. There is a WPF application that is the UI, which calls the WCF services

A pretty common set-up I would have thought. I am thinking of using DTOs between the WCF service and WPF app. There would be a mapper to map between the domain objects and the DTO on the WCF service layer. You then receive this DTO object on the client and then map this to the ViewModel used by the WPF app.

Does this look sensible?

Thanks

+1  A: 

As it should be done in my book. You don't use domain entities in your UI layer.

Look into AutoMapper to aid with the mapping back and forth.

BennyM
Doesn't the ViewModel contain domain entities though? For example, a customer domain entity would be on the server and the client as it would contain common validation?
Jon Archway
I've never done so. If the validation is the same I've put that outside of the domain entities into a separate validator. The only thing I share between my client and server are the wcf contracts. You gain flexibility on the server and the client that way.If however, you don't foresee your client application changing without the server and don't think other clients are imaginable you can share the domain entities with your client but then why use dto's, you could just wrap the domain entities in your viewmodel. I don't advocate this route though, had too many bad experiences.
BennyM
So how would you perform something like validation then? So, you have a domain entity that has some kind of business rule validation. You want this to execute on both the client and the server. Would you not expose this domain entity at both the client and the server to use the same validation and therefore maintain consistency? Thanks
Jon Archway