asp.net-coremediatr

What kind of commands/queries can be created with MediatR?


What kind of commands/queries can be created with MediatR? I understand that I can add CRUD operations but what about signing in, getting user claims, sending mails etc.? I can add them too? Are there any rules about that?

Is application layer structure on the picture correct?

Application layer


Solution

  • The folder structure seems alright.

    About what should be a command and what should not.

    In MediatR terms, command is something that will change state of the application somehow or have other side effect other than providing just some information, and so it is used to usually alter data in storage of some sort (be it SFTP, Azure blob storage, database).

    Query is just to retrieve some information (from 3rd party API, from your database, from your caluclation, whatever).

    So accordingly to above, what is not just retrieving data, should be a command. So, email notifications or sign in - I would make it a command. And getting user claims - query.

    But there are not any strict rules around that.

    And there's also one more thing in MediatR to keep in mind: INotification, which is meant to trigger some handler with MediatR, but there's no response.