Last post Aug 09, 2019 08:27 AM by PatriceSc
Aug 09, 2019 08:07 AM|snowinmars|LINK
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 the controller's access modifier from public to
The same api call works
The same api call return 404
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 what
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?
Aug 09, 2019 08:27 AM|PatriceSc|LINK
Try arround https://stackoverflow.com/questions/43739794/asp-net-core-overriding-the-default-controllerfactory as well as
https://github.com/aspnet/AspNetCore/tree/master/src and should find the relevant place and
how to plug your own logic.
As any design decision it could be discussed. They likely considered the end result ie technically speaking your code IS called from outside of the assembly. Note also that if your controller is using an internal
method it could be then exposed unexpectedly.
Here it seems it would be best to discusss with the developer about why it is bad and how it could be done otherwise rather than hoping this technical change would improve his programming skills.
I would definitively keep the default convention... Depending on your VS edition you have tools what could help (you are using the Community Edition ?)