'Create WebApplication extension method in external library

I'm trying to create an extension method to register some routes in an external library using C# .NET 6.

I can'f find a way to do it because i cannot reference Microsoft.AspNetCore.App.Ref where the WebApplication class is defined.

Has anyone encountered this problem and found a solution?



Solution 1:[1]

You can try to use IApplicationBuilder from Microsoft.AspNetCore.Http.Abstractions to create external method for WebApplication.

public static class ExtentionForWebApplication
{
    public static void ExtendWebApplication(this IApplicationBuilder app)
    {
        //Here you can use features from WebApplication
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1