✅ Minimal API: Pass app config to IEndpointRouteBuilder

I am using route builders to map routes for a minimal API, like this:
public static class LicenseApplicationEndpoints
{
    private static EndpointsConfig _config = new EndpointsConfig();

    public static void RegisterLicenseApplicationEndPoints(this IEndpointRouteBuilder routes)
    {
        var group = routes.MapGroup($"{_config.RoutePrefix}/licenseApplications");

        group.MapGet("/forUser{userId:guid}",
            ([FromServices] ILicenseApplicationService service, Guid userId) =>
                service.GetLicenseApplicationsForUser(userId));
    }
}

I'd like to access the app's IConfiguration from within these classes and am hoping there is a better way than reading config values in Program and passing them to each register endpoints method. I'd really like to receive config values or IConfiguration as ctor parameters.
Was this page helpful?