Removed unnecessary dependency of IActionSelector in UrlHelper
This commit is contained in:
parent
b622a5b0d3
commit
1c34d88f4c
|
|
@ -18,7 +18,6 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
public class UrlHelper : IUrlHelper
|
public class UrlHelper : IUrlHelper
|
||||||
{
|
{
|
||||||
private readonly IActionContextAccessor _actionContextAccessor;
|
private readonly IActionContextAccessor _actionContextAccessor;
|
||||||
private readonly IActionSelector _actionSelector;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified action context and
|
/// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified action context and
|
||||||
|
|
@ -26,13 +25,9 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="actionContextAccessor">The <see cref="IActionContextAccessor"/> to access the action context
|
/// <param name="actionContextAccessor">The <see cref="IActionContextAccessor"/> to access the action context
|
||||||
/// of the current request.</param>
|
/// of the current request.</param>
|
||||||
/// <param name="actionSelector">The <see cref="IActionSelector"/> to be used for verifying the correctness of
|
public UrlHelper(IActionContextAccessor actionContextAccessor)
|
||||||
/// supplied parameters for a route.
|
|
||||||
/// </param>
|
|
||||||
public UrlHelper(IActionContextAccessor actionContextAccessor, IActionSelector actionSelector)
|
|
||||||
{
|
{
|
||||||
_actionContextAccessor = actionContextAccessor;
|
_actionContextAccessor = actionContextAccessor;
|
||||||
_actionSelector = actionSelector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IDictionary<string, object> AmbientValues => ActionContext.RouteData.Values;
|
protected IDictionary<string, object> AmbientValues => ActionContext.RouteData.Values;
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
var actionContext = GetActionContext(httpContext.Object);
|
var actionContext = GetActionContext(httpContext.Object);
|
||||||
var actionContextAccessor = new ActionContextAccessor() { ActionContext = actionContext };
|
var actionContextAccessor = new ActionContextAccessor() { ActionContext = actionContext };
|
||||||
var mockActionSelector = new Mock<IActionSelector>();
|
var urlHelper = new UrlHelper(actionContextAccessor);
|
||||||
var urlHelper = new UrlHelper(actionContextAccessor, mockActionSelector.Object);
|
|
||||||
var serviceProvider = GetServiceProvider(urlHelper);
|
var serviceProvider = GetServiceProvider(urlHelper);
|
||||||
|
|
||||||
httpContext.Setup(o => o.Response)
|
httpContext.Setup(o => o.Response)
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
var actionContext = GetActionContext(httpContext.Object);
|
var actionContext = GetActionContext(httpContext.Object);
|
||||||
var actionContextAccessor = new ActionContextAccessor() { ActionContext = actionContext };
|
var actionContextAccessor = new ActionContextAccessor() { ActionContext = actionContext };
|
||||||
var mockActionSelector = new Mock<IActionSelector>();
|
var urlHelper = new UrlHelper(actionContextAccessor);
|
||||||
var urlHelper = new UrlHelper(actionContextAccessor, mockActionSelector.Object);
|
|
||||||
var serviceProvider = GetServiceProvider(urlHelper);
|
var serviceProvider = GetServiceProvider(urlHelper);
|
||||||
|
|
||||||
httpContext.Setup(o => o.Response)
|
httpContext.Setup(o => o.Response)
|
||||||
|
|
|
||||||
|
|
@ -884,16 +884,12 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
var context = CreateHttpContext(services, string.Empty);
|
var context = CreateHttpContext(services, string.Empty);
|
||||||
var actionContext = CreateActionContext(context);
|
var actionContext = CreateActionContext(context);
|
||||||
|
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
return new UrlHelper(actionContext);
|
||||||
return new UrlHelper(actionContext, actionSelector.Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelper(IServiceProvider services)
|
private static UrlHelper CreateUrlHelper(IServiceProvider services)
|
||||||
{
|
{
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
return new UrlHelper(services.GetRequiredService<IActionContextAccessor>());
|
||||||
return new UrlHelper(
|
|
||||||
services.GetRequiredService<IActionContextAccessor>(),
|
|
||||||
actionSelector.Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelper(string host)
|
private static UrlHelper CreateUrlHelper(string host)
|
||||||
|
|
@ -904,8 +900,7 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
|
|
||||||
var actionContext = CreateActionContext(context);
|
var actionContext = CreateActionContext(context);
|
||||||
|
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
return new UrlHelper(actionContext);
|
||||||
return new UrlHelper(actionContext, actionSelector.Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelper(string host, string protocol, IRouter router)
|
private static UrlHelper CreateUrlHelper(string host, string protocol, IRouter router)
|
||||||
|
|
@ -917,14 +912,12 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
|
|
||||||
var actionContext = CreateActionContext(context, router);
|
var actionContext = CreateActionContext(context, router);
|
||||||
|
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
return new UrlHelper(actionContext);
|
||||||
return new UrlHelper(actionContext, actionSelector.Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelper(IActionContextAccessor contextAccessor)
|
private static UrlHelper CreateUrlHelper(IActionContextAccessor contextAccessor)
|
||||||
{
|
{
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
return new UrlHelper(contextAccessor);
|
||||||
return new UrlHelper(contextAccessor, actionSelector.Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelper(string appBase, IRouter router)
|
private static UrlHelper CreateUrlHelper(string appBase, IRouter router)
|
||||||
|
|
@ -933,8 +926,7 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
var context = CreateHttpContext(services, appBase);
|
var context = CreateHttpContext(services, appBase);
|
||||||
var actionContext = CreateActionContext(context, router);
|
var actionContext = CreateActionContext(context, router);
|
||||||
|
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
return new UrlHelper(actionContext);
|
||||||
return new UrlHelper(actionContext, actionSelector.Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelperWithRouteCollection(IServiceProvider services, string appPrefix)
|
private static UrlHelper CreateUrlHelperWithRouteCollection(IServiceProvider services, string appPrefix)
|
||||||
|
|
|
||||||
|
|
@ -472,8 +472,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
var contextAccessor = GetContextAccessor(serviceProvider, routeData);
|
var contextAccessor = GetContextAccessor(serviceProvider, routeData);
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
var urlHelper = new UrlHelper(contextAccessor);
|
||||||
var urlHelper = new UrlHelper(contextAccessor, actionSelector.Object);
|
|
||||||
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
|
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
|
||||||
serviceProvider = serviceCollection.BuildServiceProvider();
|
serviceProvider = serviceCollection.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
@ -494,8 +493,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
};
|
};
|
||||||
|
|
||||||
var contextAccessor = GetContextAccessor(serviceProvider, routeData);
|
var contextAccessor = GetContextAccessor(serviceProvider, routeData);
|
||||||
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
|
var urlHelper = new UrlHelper(contextAccessor);
|
||||||
var urlHelper = new UrlHelper(contextAccessor, actionSelector.Object);
|
|
||||||
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
|
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
|
||||||
serviceProvider = serviceCollection.BuildServiceProvider();
|
serviceProvider = serviceCollection.BuildServiceProvider();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,8 @@ namespace UrlHelperWebSite
|
||||||
|
|
||||||
public CustomUrlHelper(
|
public CustomUrlHelper(
|
||||||
IActionContextAccessor contextAccessor,
|
IActionContextAccessor contextAccessor,
|
||||||
IActionSelector actionSelector,
|
|
||||||
IOptions<AppOptions> appOptions)
|
IOptions<AppOptions> appOptions)
|
||||||
: base(contextAccessor, actionSelector)
|
: base(contextAccessor)
|
||||||
{
|
{
|
||||||
_appOptions = appOptions;
|
_appOptions = appOptions;
|
||||||
_httpContext = contextAccessor.ActionContext.HttpContext;
|
_httpContext = contextAccessor.ActionContext.HttpContext;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue