Made some changes to the MvcApplication class

- Renamed it to MvcRouteHandler
- Removed required IServiceProvider ctor param.
- The HttpContext flows the application services through to MVC. This does
 require a call to app.UseContainer in order for things to work but that should be fine.
 This will be the pattern we use for all frameworks going forward and we'll need to have some
 good error handling around this area when things aren't wired up properly.
This commit is contained in:
David Fowler 2014-04-15 21:25:32 -07:00
parent 44ee632825
commit 93c9b3419e
3 changed files with 4 additions and 11 deletions

View File

@ -19,7 +19,7 @@ namespace MvcSample.Web
var routes = new RouteCollection() var routes = new RouteCollection()
{ {
DefaultHandler = new MvcApplication(serviceProvider), DefaultHandler = new MvcRouteHandler(),
}; };
// TODO: Add support for route constraints, so we can potentially constrain by existing routes // TODO: Add support for route constraints, so we can potentially constrain by existing routes

View File

@ -113,7 +113,7 @@
<Compile Include="IParameterDescriptorFactory.cs" /> <Compile Include="IParameterDescriptorFactory.cs" />
<Compile Include="IUrlHelper.cs" /> <Compile Include="IUrlHelper.cs" />
<Compile Include="JsonOutputFormatter.cs" /> <Compile Include="JsonOutputFormatter.cs" />
<Compile Include="MvcApplication.cs" /> <Compile Include="MvcRouteHandler.cs" />
<Compile Include="NonActionAttribute.cs" /> <Compile Include="NonActionAttribute.cs" />
<Compile Include="ParameterBindingInfo.cs" /> <Compile Include="ParameterBindingInfo.cs" />
<Compile Include="ParameterBinding\ActionBindingContext.cs" /> <Compile Include="ParameterBinding\ActionBindingContext.cs" />

View File

@ -11,15 +11,8 @@ using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
public class MvcApplication : IRouter public class MvcRouteHandler : IRouter
{ {
private readonly IServiceProvider _serviceProvider;
public MvcApplication([NotNull] IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public string GetVirtualPath([NotNull] VirtualPathContext context) public string GetVirtualPath([NotNull] VirtualPathContext context)
{ {
// The contract of this method is to check that the values coming in from the route are valid; // The contract of this method is to check that the values coming in from the route are valid;
@ -81,7 +74,7 @@ namespace Microsoft.AspNet.Mvc
return null; return null;
} }
var applicationServices = httpContext.ApplicationServices ?? _serviceProvider; var applicationServices = httpContext.ApplicationServices;
var scopeFactory = applicationServices.GetService<IServiceScopeFactory>(); var scopeFactory = applicationServices.GetService<IServiceScopeFactory>();
var scope = scopeFactory.CreateScope(); var scope = scopeFactory.CreateScope();