jezzsantos / saastack

A comprehensive codebase template for starting your real-world, fully featured SaaS web products. On the .NET platform
The Unlicense
15 stars 5 forks source link

Source Generated MediatR Handlers cannot be debugged #7

Closed jezzsantos closed 10 months ago

jezzsantos commented 10 months ago

The MediatR handlers that are generated from the IWebApiService declarations are not debuggable at runtime (to do with how Source Generators work).

The code in the IWebApiService class is also not debuggable since it is not part of the execution pipeline.

This experience could be better for developers.

Solution

A better experience might be achieved if we did this:

  1. Source Generate the MediatR handlers, but instead of including the original code in them, we generate code that calls the original code.
  2. To do this, we would have to instantiate the IWebApiService class (in the handler) and call the appropriate method.
  3. To do that, we need to construct the instance of the class (in the handler) using the selected ctor, and local variables in the selected ctor.

This approach seems feasible because: