2

I've been assigned to work on a site that uses MVC for the presentation layer and that talks to a WCF service. The two use DTO's to pass information back and forth.

Currently, DTO's are used throughout the MVC portion (User, Address, Account Information). For example, the User class in MVC has a PersonDTO that contains all the information about the user as well as methods specific to the web (Login):

public class User
{
    public PersonDTO Person { get; set; }
    public void Login { /* Login */ }
}

So to get the users first name, you would do:

var CurrentUser = new User();
var firstName = CurrentUser.Person.First;

Is there a better way of doing this? (It seems like it should be CurrentUser.First)

Other than being wordy, are there any pitfalls of doing this?

Are DTO's meant to bleed into Controller Actions in MVC?

0

2 Answers 2

2

I wrap my DTOs in an additional "ViewModel" class only if there is value added. I don't see a problem having your views bind directly to your DTOs if they contain all the data needed to power the views. An example of when the "viewModel" makes sense is when you have additional UI concerns like combining multiple fields into one etc.

Sign up to request clarification or add additional context in comments.

Comments

1

I normally find that DTOs contain more data than I need, or not enough data. Because of this, I get my DTOs from the service and then map them through Automapper to the view models.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.