Skip to content

Commit

Permalink
removed UrlHelper.RequestContext and UrlHelper.RouteCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtoroq committed May 19, 2020
1 parent 166184c commit 8e00919
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
26 changes: 9 additions & 17 deletions src/Xcst.AspNet/Framework/UrlHelper.cs
Expand Up @@ -6,33 +6,25 @@
using System.Globalization;
using System.Text;
using System.Web.Mvc.Properties;
using System.Web.Routing;

namespace System.Web.Mvc {

public class UrlHelper {

public RequestContext RequestContext { get; private set; }

public RouteCollection RouteCollection { get; private set; }
readonly HttpContextBase _httpContext;

// The default constructor is intended for use by unit testing only.
public UrlHelper() { }

public UrlHelper(RequestContext requestContext)
: this(requestContext, RouteTable.Routes) { }

public UrlHelper(RequestContext requestContext, RouteCollection routeCollection) {
public UrlHelper(HttpContextBase httpContext) {

if (requestContext is null) throw new ArgumentNullException(nameof(requestContext));
if (routeCollection is null) throw new ArgumentNullException(nameof(routeCollection));
if (httpContext is null) throw new ArgumentNullException(nameof(httpContext));

this.RequestContext = requestContext;
this.RouteCollection = routeCollection;
_httpContext = httpContext;
}

public virtual string Content(string contentPath) =>
GenerateContentUrl(contentPath, this.RequestContext.HttpContext);
GenerateContentUrl(contentPath, _httpContext);

[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "As the return value will used only for rendering, string return value is more appropriate.")]
public static string GenerateContentUrl(string contentPath, HttpContextBase httpContext) {
Expand Down Expand Up @@ -64,9 +56,9 @@ public UrlHelper(RequestContext requestContext)
// the virtual app path and url rewrites

if (String.IsNullOrEmpty(query)) {
return UrlUtil.GenerateClientUrlInternal(this.RequestContext.HttpContext, processedPath);
return UrlUtil.GenerateClientUrlInternal(_httpContext, processedPath);
} else {
return UrlUtil.GenerateClientUrlInternal(this.RequestContext.HttpContext, processedPath) + query;
return UrlUtil.GenerateClientUrlInternal(_httpContext, processedPath) + query;
}
}

Expand All @@ -80,7 +72,7 @@ public UrlHelper(RequestContext requestContext)
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Justification = "Response.Redirect() takes its URI as a string parameter.")]
public virtual bool IsLocalUrl(string url) =>
// TODO this should call the System.Web.dll API once it gets added to the framework and MVC takes a dependency on it.
HttpRequestExtensions.IsUrlLocalToHost(this.RequestContext.HttpContext.Request, url);
HttpRequestExtensions.IsUrlLocalToHost(_httpContext.Request, url);
}

static class UrlUtil {
Expand Down Expand Up @@ -255,7 +247,7 @@ internal static class UrlBuilder {

internal static class UrlRewrite {

static UrlRewriterHelper _urlRewriterHelper = new UrlRewriterHelper();
static readonly UrlRewriterHelper _urlRewriterHelper = new UrlRewriterHelper();

internal static string GenerateClientUrlInternal(HttpContextBase httpContext, string contentPath) {

Expand Down
6 changes: 4 additions & 2 deletions src/Xcst.AspNet/Mvc/XcstViewPage.cs
Expand Up @@ -65,9 +65,11 @@ public abstract class XcstViewPage : XcstPage, IViewDataContainer {
&& ViewContext != null) {
_Url =
#if ASPNETMVC
(ViewContext.Controller as Controller)?.Url ??
(ViewContext.Controller as Controller)?.Url
?? new UrlHelper(ViewContext.RequestContext);
#else
new UrlHelper(Context);
#endif
new UrlHelper(ViewContext.RequestContext);
}
return _Url;
}
Expand Down

0 comments on commit 8e00919

Please sign in to comment.