using source generators to cut down on endpoint/type discovery time during startup
See original GitHub issuecurrently 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:
- Created a year ago
- Comments:26 (21 by maintainers)
Top GitHub Comments
Started working on this in a new branch.
@dj-nitehawk that seems to have solved it ha ha
thanks so much for the assist.