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.

using source generators to cut down on endpoint/type discovery time during startup

See original GitHub issue

currently fastendpoints uses assembly scanning to discover endpoints/validators/event handlers/summaries during startup. https://github.com/dj-nitehawk/FastEndpoints/blob/1745ec0254da63d22bfea6d96067d047f0b8943e/Src/Library/Extensions/EndpointData.cs#L54-L70 this obviously takes some milliseconds whenever the app is run, which would not be ideal for serverless/cold start scenarios.

if we can use a source generator to produce a static class with a System.Type[] static property at compile time, we may be able to get rid of the type discovery time.

the end result of the source generation should be something like this:

namespace FastEndpoints
{
    public static class DiscoveredTypes
    {
        public static readonly System.Type[] AllTypes = new System.Type[]
        {
            typeof(UsersNameSpace.MyEndpoint1),
            typeof(UsersNameSpace.MyEndpoint2),
            typeof (UsersNameSpace.MyEndpoint3)
        };
    }
}

if you have experience with source generators, please see if you can implement this. this will be much appreciated by the folk who uses fastendpoints in serveless environments.

i myself got as far as trying to figure out if a ClassDeclarationSyntax implements a given interface such as IEndpoint and failed since it seems like it’s not possible to get a list of interfaces a class implements inside the SyntaxReceiver.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:26 (21 by maintainers)

github_iconTop GitHub Comments

3reactions
nefariuscommented, May 15, 2022

Started working on this in a new branch.

2reactions
snc-softwarecommented, May 25, 2022

@dj-nitehawk that seems to have solved it ha ha

thanks so much for the assist.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source Generators
Source Generators is a C# compiler feature that lets C# developers inspect user code as it is being compiled. Source generators create new ......
Read more >
Introducing C# Source Generators - .NET Blog
Source Generators can improve performance in ways that aren't limited to reflection at runtime to discover types as well. Some scenarios involve ...
Read more >
.NET Handbook | Best practices / Source Generators
It can also shift the controller discovery phase from startup to compile time, reducing startup time. Another usage of source generators can ...
Read more >
Allow for a way to ensure some source generators run ...
We've been using generators for Blazor to generate a strongly typed class that contains all routes of the application so routing isn't stringly ......
Read more >
Mapping ASP.NET Core minimal API endpoints with C# ...
Intro. This will be a very simple post about how we can use C# source generators to map minimal API endpoints automagically.
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