martinothamar/Mediator

Suggestion: Consider moving the analyzing to a dedicated analyzer

panoukos41 opened this issue · 2 comments

I believe this could make/promote creating libraries easier, here is an example:

I have the following projects:

  • Application (Requests)
  • Application.App (Handlers) 🤣
  • Identity (Requests)
  • Identity.App (Handlers)
  • Web (Minimal api aspnetcore etc.) gets the handlers and generates the mediator.

Now if my handlers don't implement a certain request I get a warning in the web project. If the analyzer was seperate I could get warnings on each handler project that could make it easier to develop different handler project if any reason for it rises and it would make it clearer that the generator goes to the consuming project as it's the only project needing to generate/consume the mediator the other packages use the analyzer to get help on implementing!

Again this is a suggestion as one can just use a sample project to get such warnings.

Hi! If the analyzer for example was added only to Application in this case, where the request is defined, it couldn't necessarily know that there was no handler. The handler could come from a reference that only Web sees right?

I feel like this starts to break down when things are split into different projects. The reason it's in the source generator itself currently is because that's the only place we have the whole context (and when it can actually be invoked).

I know that it's a little confusing when the diagnostics report on something from a different project t hough... Mediator follows roughly the same contract and behavior as MediatR, which is reflection based, so things get a bit iffy sometimes. A sourcegenerated-first design would probably constrain things a bit more so that we didn't end up in as many confusing situations. But that would have to be a new library 😄

Hey thanks for taking the time to answer me and I am happy to see your thoughts on this, no problem with me I just wanted to point it out as a potentials solution to this edge case problem :P

I will close this issue as to not contaminate your issues 😄