Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat Project Layer Should Screen DTO's Live In?
    primarykey
    data
    text
    <p>I have a project where we use screen DTO's to encapsulate the data between the <strong>Service Layer</strong> and the <strong>Presentation Layer</strong>. In our case, the presentation layer is ASP.Net.</p> <p>The only classes that know about the DTO's are the service layer classes and the Pages/Controls that call these services and display the DTO's.</p> <p>The DTO's are almost always Page/Control specific so I feel they belong in the Presentation Layer, but that would mean the Service Layer would have to reference the Presentation Layer in order to use the DTO's. </p> <p>I'm almost thinking that the Service Layer should return richer objects (but not domain entities?) and then the Presentation Layer can take these objects and map them to very specific DTO's for each Page/Control concern.</p> <p>Here's an interface declaration and a DTO so you can see what I'm talking about:</p> <pre><code>public interface IBlogTasks { BlogPostDisplayDTO GetBlogEntryByTitleAndDate(int year, int month, string urlFriendlyTitle); } public class BlogPostDisplayDTO { public string Title { get; set; } public DateTime PostDate { get; set; } public string HtmlContent { get; set; } public string ImageUrl { get; set; } public string Author { get; set; } public int CommentCount { get; set; } public string Permalink { get; set; } } </code></pre> <p><strong>Edit</strong></p> <p>Here's another code sample to describe a use case where the Domain model isn't involved. Maybe this will clarify things a bit. I believe I've overloaded the DTO meaning. I'm not talking about a DTO for the function of transfering an object over the wire. I'm creating DTOs to formalize contracts between communication to my Service Layer. </p> <pre><code>public interface IAuthenticationTasks { bool AuthenticateUser(AuthenticationFormDTO authDTO); } public class AuthenticationFormDTO { public string UserName { get; set; } public string Password { get; set; } public bool persistLogin { get; set; } } </code></pre> <p>Let's say my authentication all of the sudden requires an IP address parameter. I can now add that property to the DTO without having to change my contract interface.</p> <p>I don't want to pass Entities to my Presentation Layer. I don't want my code behind to have the ability to go <code>BlogPost.AddComment(new Comment())</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload