Blog Stats
  • Posts - 62
  • Articles - 1
  • Comments - 41
  • Trackbacks - 63

 

Presentation to Service Layer - to DTO or not in ASP.NET?

So a simple design question to get feedback about what folks think regarding ASP.NET usage of a Service Layer. In an application (non-distributed web app) that wants to implement a Service Layer to provide a simple API for a relatively complex business logic layer, there seem to be two options for communicating data from those clients...in our case a web page.
In the code-behind, we can grab the values from webcontrols and send those primitive types directly to the service layer methods - our basic CRUD functions. It becomes obvious that some methods are going to have a heavy load of parameters so the developer guy gets lazy and just performs the operations directly in the code-behind on the business objects themselves, short-circuiting the Service Layer.
He's heard about Data Transfer Objects DTO, but thought they would be redundant and would always seem to be in a one-to-one relationship with the Domain Objects...so why not just use the Domain Objects directly? Of course, Domain Objects are going to often have complex types as opposed to the DTO's having (usually) just primitive types...following the idea that the Domain maintains entity relationships (not DTO's).
So the purist says "let's do DTO's" and the lazy coder says "it's easier to just hydrate and perform actions on the Domain directly from teh code-behind". So do more folks do a combination of both, only utilizing DTO's when the parameter abundance is overwhelming and makes the code look sloppy?
Naturally, you have to go into java sites/forums to find any serious discussion about these kinds of questions and that was very helpful,but I thot I'd ellicit feedback from ASP.NET folks who have wanted to implement a service layer and keep all domain logic-method calls out of the code-behinds.
It seems overkill to use DTO's between the application logic (service layers) and domain logic (domain layer) in a app that will never be distributed. But DTO's would seem to clean-up all the parameter passing between control values/code-behind and the service layer they will eventually impact.

Feedback

# re: Presentation to Service Layer - to DTO or not in ASP.NET?

Gravatar hi mike

i agreee with u on this..i did some searching on google on this topic and also tried it out on a project..we did noot use DTO's betw service layer and domain model, but it made our code look messy..:-)..so if any1 asks me..i advise them to go for DTO..it pays in the long run...also..i use same DTOs between DAL and BLL. let me knw wat u think of this. 6/13/2006 9:57 AM | vivek

# re: Presentation to Service Layer - to DTO or not in ASP.NET?

Gravatar Hi Vivek, thanks for writing back. I resolved my quandry partially at http://geekswithblogs.net/opiesblog/archive/2006/06/13/81751.aspx
Basically, I opted out of DTO's partially because I am using NHibernate and it seems to me an O/R mapper will remove their usefullness below the service layer. Plus, I just couldn't justify having a parallel framework to maintain just for the sake of slightly cleaner code. Turns out Hibernate in Action book also questions the usefulness of DTO's in a typical situation. I recognize their value for apps that will expose themselves as webservices , but that doesn't apply much to me currently. What I discovered was my question was possibly exposing a design problem with my service layer...finer granularity might be needed for accessing my Domain via the Service Facade to cut down on the passing of large numbers of primitive types for processing. 6/13/2006 12:58 PM | Mike

# re: Presentation to Service Layer - to DTO or not in ASP.NET?

Gravatar hi Mike,

i agree with u..nice posts!

6/13/2006 10:45 PM | vivek

# re: Presentation to Service Layer - to DTO or not in ASP.NET?

Gravatar We've recently started using DTO's.

The main problems were:

- Nhibernate, and people stepping through the object tree without realising the amount of database hits it was incurring. Using a DTO helps control this to a certain extent.
- It de-couples our Model from any interfaces. The interfaces become effectivly dumb, and just display data.

One thing that has been raised though, is presenation logic. Should it be included in a DTO. We have JavaScript widgets as well as .Net ones in our app, and not including such logic, means writing the same presentation logic twice. 11/5/2008 6:47 AM | Rob

Post a comment





 

 

 

Copyright © Mike Nichols