Mvc: Property naming of HttpContext is inconsistent across View and Controller

Created on 5 May 2016  路  12Comments  路  Source: aspnet/Mvc

In a Controller, the HttpContext is accessed through the HttpContext property, but in a view it is accessed through Context. This seems a little inconsistent. It's not too bad since IntelliSense makes it pretty clear.

Certainly doesn't seem RC2-blocking, but it felt a little odd while I was testing.

by design

Most helpful comment

You guys already made a breaking change with removing the "Http" prefix from some action results like "HttpBadRequest". The explanation was that the Core 1.0 is a new framework and it is fine. I believe for consistency, this one here can be made "HttpContext" in the views.

All 12 comments

We should look at what the naming was in MVC 5.x. I vaguely recall that we kept this naming, inconsistent or not, due to legacy.

I checked and it's the same as MVC 5.x, and we did keep it consistent on purpose.

Sounds like a good enough reason to me :). Thanks for checking!

Well it's a pretty bad reason really, but, you know, because reasons 馃槃

Maybe we need to add a [PlzJustStopThisIsTheWayItIsBecauseBackCompat] attribute so we can have a tool auto-respond to these kind of issues.

Or we just make the breaking changes now, while we can ;)

+1 for breaking all the things!!! :dancers:

I guess, at this point no one cares about further breaking changes, especially if they can be fixed with search&replace.

Honestly, I'm not sure if I can still deal with a stable API. I'm afraid working with RTM will get really boring. How should I start my day without my build server telling me that stuff broke again?!? :D

You guys already made a breaking change with removing the "Http" prefix from some action results like "HttpBadRequest". The explanation was that the Core 1.0 is a new framework and it is fine. I believe for consistency, this one here can be made "HttpContext" in the views.

@ivaylokenov the distinction we've made on these types of breaking changes is whether an app's code is likely to reference this type by name or not. In the case of Context/HttpContext it's quite often in user's code, so it could be an annoying change. The ActionResult types however appear less frequently in code. Most code uses the "factory" methods on Controller, e.g. return BadRequest(...) as opposed to return new BadRequestResult(...) (or whatever). So the actual type name is normally hidden.

@Eilon I was talking about the factory methods in the controller class too. This was the breaking change and I believe a lot of apps used these:
https://github.com/aspnet/Mvc/commit/75c05be2f71837c1094eb42ad8c283979bbdfbef
And this was the comment I was refering too:
https://github.com/aspnet/Mvc/issues/4085#issuecomment-183446741
I believe both changes (the action result and the HTTP context) are just rename refactorings so they should be OK.

EDIT: Well, I can see that your arm was twisted the last time (https://github.com/aspnet/Mvc/issues/4085#issuecomment-185866897) so I see your point here... :laughing:

@ivaylokenov wow, your memory is far better than mine!

@Eilon Well, I am stalking these repositories like they are my own. I know more than 60% of the code maybe. There is no better place for C# design and performance know-how in my opinion. 馃憤

Was this page helpful?
0 / 5 - 0 ratings