Particular / NServiceBus

Build, version, and monitor better microservices with the most powerful service platform for .NET
https://particular.net/nservicebus/
Other
2.08k stars 647 forks source link

Use .NET 5 source generators to build message and handler metadata registry at compile time #6060

Open tmasternak opened 3 years ago

tmasternak commented 3 years ago

NServiceBus endpoint is doing assembly scanning during startup. In scenarios, where assemblies are known and available at compile time (probably the majority of cases) we could use source generators to run the scanning once and provide the results as additional type generated pre-compile-time.

There is probably some impact on the development experience i.e. how long it takes to do the scanning so that this does not impede the F5 experience.

This feature would enable us to have a quicker cold-start experience in Cloud environments like container hosting, Azure Functions, and AWS Lambda.

timbussmann commented 3 years ago

where assemblies are known and available at compile time (probably the majority of cases)

would that be something the user has to explicitly define? I'm not sure how else we can be sure that there will be no assembly to scan?

tmasternak commented 3 years ago

@timbussmann did not dig deep into possible solutions but I see at least 3 options here:

  1. Assume there are no runtime drop-in assemblies and let the user switch back to current behavior with explicit configuration setting
  2. Go the other way round (have an explicit setting to turn the scanning off).
  3. Try to be smart and do the scanning only for the assemblies we did not see at compile time.
DavidBoike commented 3 years ago

It's important to remember that ADSD teaches that the project view in Visual Studio (or wherever compilation and thus source generators are acting) isn't necessarily the same as your deployment view, and that service composition can be done by deploying DLLs together.