views:

606

answers:

2

I have an application with a repository layer (and a nhibernate implementation), service (bussiness) layer, and an asp.net mvc in the web layer.

Because I also need to create a small silverlight application I will create several wcf services. This calls to use DTO's, but I don't know how & where to create them.

I've seen some links (like this one), so it seems that the natural place for the dto's and the mapping procedure is somewhere in my data/repository layer?

But on the other hand when I look at the Fowlers DTO pattern it seems that the mapping is done with the assembler somewhere in the domain layer?

I am confused... What is the best practice to achieve this?

Many thanks!

+3  A: 

This link is a bit obsolete, isn't it? And it just presents a cool stuff, not a natural way to do DTO.

Now we have AutoMapper. Would you put mapping in a separate assembly or not that's up to you.

queen3
A: 

Conceptually, DTOs are usually in between the data layer (since DTOs are dependent on the data layer) and the business layer (if the DTOs are being used to insulate the business layer from the data layer).

If your Silverlight app is going to use your business layer, it seems like it should look something like this:

Silverlight -> WCF -> BL -> DTOs -> DL -> DB

That would make your MVC app potentially look like this:

ASP.NET MVC -> BL -> DTOs -> DL -> DB

That said, there isn't really a single "correct" way to do this. In either app, you could bypass your business layer and/or DTOs if that meshed with your requirements. You could have your ASP.NET MVC app talk to your WCF layer to make the UIs more consistent from a business layer interface perspective.

Many times when you are looking for a best practice, the answer is really "It depends.".

Michael Maddox