Skip to content

Support strongly typed builders with IEndpointConventionBuilder #8902

Closed
@JamesNK

Description

@JamesNK

Map extensions that hang off IEndpointRouteBuilder return IEndpointConventionBuilder. This is fine and good.

Can we imagine scenarios where someone wants to return a more strongly typed builder? For example, from gRPC's MapGrpcService I return an GrpcEndpointRouteBuilder. It implements convention builder but there is also some gRPC specific stuff on there, and gRPC extension methods.

public class GrpcEndpointRouteBuilder : IEndpointConventionBuilder
{
    public GrpcEndpointRouteBuilder ConfigureCrazyGrpcStuff(Action a)
    {
        a();
        return this;
    }
}

Today all our IEndpointConventionBuilder extension methods return IEndpointConventionBuilder which would make using a strongly typed builder difficult.

routes.MapGrpcService<MyService>()
    .RequireAuthorization("policy")
    .ConfigureCrazyGrpcStuff(() => {}) // error, reference is no longer the gRPC builder

Should our extension methods be more like:

public TBuilder RequireAuthorization<TBuilder>(TBuilder builder, string policyName) where TBuilder : IEndpointConventionBuilder
{
    // stuff
    return builder;
}

// @davidfowl @rynowak

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions