Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extending ApiBehaviorOptions with skip SkipStatusCodePages #57597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

onurkanbakirci
Copy link
Contributor

Extending ApiBehaviorOptions with skip SkipStatusCodePages

I added a SkipStatusCodePages property to the ApiBehaviorOptions class to extend its functionality. I then referenced the new SkipStatusCodePagesConvention from the ApiBehaviorApplicationModelProvider class. The SkipStatusCodePagesConvention class adds a SkipStatusCodePagesAttribute to the API controller to disable the skip status code pages feature.

However, I am encountering the following reference error:

error CS0246: The type or namespace name ‘SkipStatusCodePagesAttribute’ could not be found (are you missing a using directive or an assembly reference?)

What could be causing this problem, and how can I resolve it? What might I be missing?

Fixes #45369 , #45260

@onurkanbakirci onurkanbakirci requested a review from a team as a code owner August 29, 2024 15:54
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Aug 29, 2024
@dotnet-policy-service dotnet-policy-service bot added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member labels Aug 29, 2024
@martincostello
Copy link
Member

What could be causing this problem

SkipStatusCodePagesAttribute is defined in Microsoft.AspNetCore.Mvc.ViewFeatures, which Microsoft.AspNetCore.Mvc.Core is a dependency of. You can't depend on it because it would create a circular reference.

Unless the attribute definition were moved down the stack from ViewFeatures to Core, you'll need to define an private implementation of ISkipStatusCodePagesMetadata within Core and use that in the convention.

@onurkanbakirci
Copy link
Contributor Author

onurkanbakirci commented Sep 2, 2024

Thanks for your response @martincostello. Do you think creating a private ISkipStatusCodePagesMetadata interface within Microsoft.AspNetCore.Mvc.Core is a good option, or should I consider different strategies?

@martincostello
Copy link
Member

The only options are to create a private implementation of the interface and use that or for the implementation to be moved to a lower level of the stack. The latter would need approval from the team to move and would need type-forwarding to be set up.

@captainsafia
Copy link
Member

@onurkanbakirci Martin's recommendation for a private implementation of the interface is spot on. It's the general pattern we use for these things. That should allow you to resolve the issue without introducing circular dependencies or requiring another round of API review.

@mkArtakMSFT mkArtakMSFT removed the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Sep 16, 2024
Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add SkipStatusCodePages property to ApiBehaviorOptions
5 participants