0

Using MediatR in ASP.NET Core. I have a Command for editing a user. One of the properties in the Command is based on a SelectList Dropdown that has values pulled from a DB.

Just curious, what do people normally do for that? Do you put the SelectList or IEnumerable<T> as part of the Command? That seems wrong, because it's not really part of the Command.... but I want the Controller to be clean and just have mediator.Send calls in the Controller and handling responses. I don't really want to have to make a DB call outside of the Handler on the GET and on the POST (if validation fails for instance).

I'm curious what do people do in scenarios like this where you have non-editable data that is related but not part of your Command? I haven't really seen any MediatR examples that cover a scenario like this.

Rounder
  • 271
  • 1
  • 6
  • Please can you post a cut down version of your command & handler to illustrate what you mean – Alex Nov 18 '17 at 09:06
  • Thanks for the reply! Appreciate it. Not sure the command and handler will help much. The handler just immediately checks if the Command is valid, and if it's not then returns a result saying it's not valid. The MVC controller then just returns the view back with the ModelState info. A simpler way of explaining my scenario is essentially I need to rehydrate some data on the page if the CommandHandler fails for any reason. Like I need to repopulate a dropdown from a database. Do you put that List in the Command or do you just execute the query in the Controller? – Rounder Nov 19 '17 at 03:03
  • Ah ok, I see (I think) - you could have a second query and populate based on that. You don't have to have just one single command / query in each action – Alex Nov 19 '17 at 23:43

0 Answers0