Generate route handler-endpoints at compile time via source generator
See original GitHub issueCurrently, RequestDelegates for associated route handler-based endpoints are generated at runtime using LINQ expressions. This is a process that requires a fair amount of reflection. We can leverage source generation to generate these endpoints via static analysis.
Some of this work has been prototyped in uController and will need to be formalized as part of the official project.
Generator Basics
- Add RequestDelegateGenerator scaffold to aspnetcore repo
- Respect
EnableRequestDelegateGenerator
flag in Web SDK - Refactor code to support marking
GeneratedRouteBuilderExtensions
asfile class
- Set up code and tests for emitting diagnostics from the generator
- Support for a RouteEndpointDataSource implementation that supports a func for populating metadata
- Support for an RouteEndpointDataSource implementation that allows customizing what RDF is called to produce filtered delegate calls
Invoking Handlers
- Support generating correct delegate type signature for a given handler
- Support emitting correct generic-
EndpointFilterInvocationContext
for a given filtered invocation
Issue Analytics
- State:
- Created 9 months ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Is there an efficient way to Generate Folders using ...
Is there an efficient way to make the Source Generators generate folders at compile time, not just files? Note: I know that I...
Read more >Source Generators
With a Source Generator, routing can be strongly typed with the necessary strings being generated as a compile-time detail.
Read more >Solving the source generator 'marker attribute' problem
In both of these cases, the attribute itself is only a marker, used at compile-time, to tell the source generator what to generate....
Read more >Source Generators Will Enable Compile-Time ... - InfoQ
Source generators are a new feature of the C# compiler that enables inspecting user code using compiler-generated metadata and generating ...
Read more >C# Source Generators – a very useful new feature of ... - jenx.si
C# Source Generator can generate new source code at compile time, but it can not change existing one. This means that you can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s an idea we’ve discussed in some other contexts recently but deserves its own issue. We’d likely want it to discover more than just routes created via minimal APIs (e.g. Razor Pages, MVC, etc.).
Fix for https://github.com/dotnet/roslyn-analyzers/issues/6229 is merged now. You can still include an explicit reference if you want to use latest previews, but otherwise, it should be good to have the transitive dependency.