Open bbarry opened 3 years ago
PRs are welcome :)
heh, yeah I'm looking... probably wouldn't get to it for a while so if anybody else wants to try they are welcome.
I'm not really sure what the best approach is. C#9 source generators are implemented as roslyn analyzers, so in theory this project can be changed to an analyzer dependency instead of a runtime dependency (obviously this is a breaking change). Perhaps it would be better to implement it as a separate nuget package?
https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md
Documentation for all this is still pretty sparse. I was also wondering if there was some interest in analyzers for mediatr you might know about?
Hey, I wondered about this myself, so a while back I created another mediator pattern implementation based on source generation myself: https://github.com/martinothamar/Mediator
There are some differences in API from MediatR but the source generation itself is maybe something to look at for a potential implementation here. It does assembly scanning to generate both DI extension method and the mediator implementation itself. Won't have time get into any PR here atm but posting this just in case someone else is considering it 😄
It would be nice to change the reflection done here to a compile time dependency. Instead of
we might add an attribute to our startup class and call a generated method:
The former has significant and growing runtime costs associated as the complexity of the project increases, whereas the latter would generate a function
and thus not be subject to the for loop over
assembliesToScan.SelectMany(a => a.DefinedTypes)
multiple times (project I am working on was apparently looping over the defined types of all assemblies in the bin dir nearly 100 times for various libraries it was using).