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
DNN-10462: Added support for DnnUrlHelper in DnnController for MVC #1925
Changes from 1 commit
671dfd2
c1365d6
3e59867
d104dff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,21 @@ public DnnUrlHelper(ViewContext viewContext) | |
{ | ||
} | ||
|
||
public DnnUrlHelper(RequestContext requestContext, IDnnController controller) | ||
{ | ||
Requires.NotNull("controller", controller); | ||
|
||
UrlHelper = new UrlHelper(requestContext); | ||
_controller = controller; | ||
|
||
if (_controller == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need this check in this Constructor. I can't think of a case in which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it was more or less copied and pasted from the other constructor. I'll update and push new changes |
||
{ | ||
throw new InvalidOperationException("The DnnUrlHelper class can only be used in Views that inherit from DnnWebViewPage"); | ||
} | ||
|
||
ModuleContext = _controller.ModuleContext; | ||
} | ||
|
||
public DnnUrlHelper(ViewContext viewContext, RouteCollection routeCollection) | ||
{ | ||
Requires.NotNull("viewContext", viewContext); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this property here? System.Web.Mvc.Controller already has the Url property which is being overridden by using the new keyword in DnnController.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know the
DnnUrlHelper
does not inherit from theSystem.Web.Mvc.UrlHelper
UrlHelper
which are different objects. This is why I chose to create theDnnUrlHelper
inside theIDnnController
. This way if someone is using the interface they will have access to the appropriateDnnUrlHelper
.See DnnUrlHelper from the platform code. Snippet below:
Taking a closer look at the
System.Web.Mvc
UrlHelper. It appears we can take our currentDnnUrlHelper
and inherit from it and override all theAction
methods. Without making this change we will not be able to properly override theUrl
property in theDnnController
Here are some proposed changes based off the feedback provided:
DnnUrlHelper
to inherit and override theSystem.Web.Mvc.UrlHelper
DnnUrlHelper
from theIDnnController
System.Web.Mvc.UrlHelper
or omitted completlyInitialize()
method and set theSystem.Web.Mvc.UrlHelper
equal to our implementation ofDnnUrlHelper
If these changes all make sense to you, I'll go ahead and update the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahoefling Regarding
DnnUrlHelper
inIDnnController
since you are using new and same property name, it automatically hides theUrlHelper
fromSystem.Web.Mvc.Controller
. We are doing same forUser
property as well. Further, I can agree on the point of reuse the helper ifIDnnController
is used but I don't see much usage of implementing it alone. But we can still leave it the way you did it assuming it to be better way of hiding the property in this scenario.Regarding inheriting from
UrlHelper
, We can do that way but we can not just override the implementation ofAction
methods and leave others untouched. If we want to inherit fromUrlHelper
then all other methods should be overridden and implemented in a way that they are useful for DNN MVC framework. We don't want to include methods inDnnUrlHelper
which are not useful and will create incorrect results.If you still want to use that approach then that will need to implement all the methods from
UrlHelper
, verify the proper working for them and add test cases for all of them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amarjit-dhunna wrote:
It sounds like the first approach is an established best practice that we have used for the
User
object. Based on your feedback I think it will be best to use the new opperator to hide the the base implementation ofUrlHelper
so module devs will get just the workingDnnUrlHelper
.I believe it to be best to keep the
IDnnController
the way currently proposed in this PR. Since theController
class uses a different object for theUrl
property (UrlHelper
vsDnnUrlHelper
) it will be difficult to write any generic code around theIDnnController
where the developer would want to leverage theDnnUrlHelper
.@amarjit-dhunna wrote:
I completely agree with you and while this may be a great solution in the future i think it would be best handled in another PR that expands upon the changes here. This may be something I am willing to pick up after we get through this change.
Action Items I have gathered from this discussion:
IDnnUrlHelper
on theIDnnController
Please sign off on this direction if you are okay with it and I'll update the PR when ready
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. So only task pending for you is to add unit tests to cover the new code.