Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Web API routing doesn't appreciate non-public controllers

$
0
0

Pre-requirements

Create default netcoreapp2.2 web api project (I use Rider, but I believe it doesn't really matter).

Start the project.

Call an action in a controller and ensure that it works.

Change

Change the controller's access modifier from public to internal

Expected behavior

The same api call works

Actual behavior

The same api call return 404

Why I care

I used to close access modifiers as hard as I can. Once I saw developers that references anything from anywhere for no reason, and it was really hard to track. I'd love to have a flow that could warn me about wrong references.

If a class should not be referenced from another project, it's access modifier should be internal. Well, due to that's whatinternal means.

The actual flow seems weird to me: reflection should not think about access modifiers. For example, you are able to (de)serialize any class with any fields.

Unfortunately, I couldn't find a code where the route resolving happens. Could anyone link the file?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>