I am trying to pull a "Message" and show it to the user. A message has a CreatedUserId. When I display the message, I also want to display the users name. (Which is not held on the Message object).
I can think of several ways to do this, please give me some feedback about what to do in this case. Here are some ideas:
- Create an application method "GetForView" which will use the repository for the user, and build a specific ForViewDto.
- Use the default Dto for Message, but add a "username" field, and make AutoMapper fetch the username during mapping.
- The client calls for the message first, then fills in the username with a separate ajax request after. (seems slow)
If 1) seems correct, then my concern is that this is a "for view" thing which isn't really the application layers responsibility, or is it? 2) is probably the solution everyone goes with?
Thanks
2 Answer(s)
-
0
Hi,
You can go with option 2 but you need to name your username field according to AutoMapper mapping rules. Option 1 is also fine I think. Application layer must be responsible for preparing DTOs.
-
0
If you display a message together with the username, then the MessageDTO should contain the username as well.
In my eyes nr 1 and 2 are the same. In the application layer you have "public MessageDTO GetMessage()". The MessageDTO contains the username. The method is not specific for any particular view - you could consume this method from many different presentation layers that wants to show a message. Just skip the "ForView"-part when naming the method 8-)