Search code examples
c#asp.netdto

Should I assign my DTO properties to public variables or call the dto instance directly on my aspx page?


My UI layer calls my business layer which populates a DTO. I need to display properties from the DTO on my ASPX page. Should I create public variables on the code behind page for each of the DTO properties and reference like <%=PublicPropertyName%> OR is it ok to set the DTO instance to public and reference the properties directly like <%=dtoInstance.propertyName%>

Additionally, would it be better if I just created Literal and Label controls for every item on the ASPX page and just populate them from the code behind only?


Solution

  • Using the public variables within the code behind would be somewhat similar to Fowler's Presentation Model pattern. This would allow your DTOs to evolve over time and only require modification to the code that transforms the DTOs and assigns their values to the code behind object. That would definitely be a valid approach.