-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Ability to enable API behavior globally #7343
Comments
Yeah, I'd love to find a way to do this π What did you have in mind? (let's try to come up with a plausible idea first) |
I'm just thinking we can add a property, var isApiController = !_apiBehaviorOptions.RequireApiControllerAttribute || controllerModel.Attributes.OfType<IApiBehaviorMetadata>().Any(); It would also be nice if there was a public static IMvcCoreBuilder UseApiConventions(this IMvcCoreBuilder builder, Action<ApiBehaviorOptions> configure)
{
builder.Services.Configure<ApiBehaviorOptions>(options =>
{
options.RequireApiControllerAttribute = false;
configure(options);
});
return builder;
} A couple of things:
What do you think? Am I too far out here? |
Sorry for letting this fall off my radar, I was off having other adventures. The approach here seems pretty reasonable |
@pranavkm, I'm assigning this to you to come up with the desired approach we'd like to take here for now. |
Tangentially related to #7802, but we want to be able to try using tooling (specifically analyzers and codefixes) to help guide users in authoring their API actions. Configuring it using code (the With the convention work, we ended with a solution of allowing an attribute to be placed on the assembly. It does cause you to have to specify it on a per-assembly basis, rather than on a per-application basis, but it seems like smaller price to pay. In this case, we could consider allowing the Thoughts \ concerns? |
Moving it out to preview2. cc @glennc |
@khellang do you care about this as much when a single attribute for the assembly enables the conventions? My hesitation here is, as @pranavkm talks about, we are walking a line that could easily lead to the analyzers not being able to function. Which might be fine for some people, but is generally an important part of the experience. |
An assembly level attribute would probably work as well, but why introduce yet another way of configuring MVC? |
Summarizing our offline chat about this -
|
As mentioned in dotnet/aspnetcore#2846 (comment):
I did a quick scan through the code, but couldn't see how you'd enable the conventions without adding attributes. Is this something you'd consider a PR for?
The text was updated successfully, but these errors were encountered: