Clean ASP.NET Core API using MediatR and CQRS | Setup

I meant that, when you write your business logic and need a User model, you write yourself an interface, IGetUserQuery, with a single method that returns the model you need. You inject that and continue with your logic. Then you make a class, GetUserQuery that implements this interface(preferably in separate project to keep it Clean and so that your Domain is still the center piece of your application), that itself contains whatever orm you use and logic needed for retrieval(DbContex f.e.) and mapping of that User entity. Now, if you use assembly scanning DI to register all *Query and all *Command as interfaces they implement, you spend no more time at configuring anything, otherwide you have to add this query manually(one line in startup). You injected yourself a Query/Command, you can get straight to it's implementation easily, it perfectly abstracted away the data access from you(since it also takes care of mapping database entity towards your domain model). It's reusable and very easily swappable, thus you can easily test your business logic, since it requires you to mock an interface with single method which quite clearlt describes the contract.

/r/dotnet Thread Parent Link - youtu.be