question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate route handler-endpoints at compile time via source generator

See original GitHub issue

Currently, 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 as file 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:closed
  • Created 9 months ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DamianEdwardscommented, Jan 23, 2023

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.).

1reaction
Youssef1313commented, Jan 10, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found