Fix empty RouteData issue in IoC RequestContext

Since we wrap the MvcHandler with our own handler, we need to dig
down the RequestContext instance a bit deeper.

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-04-30 19:49:58 -07:00
parent dd4c4f5730
commit 3f70ab177f
4 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
using System.Web.Routing;
namespace Orchard.Mvc {
public interface IHasRequestContext {
RequestContext RequestContext { get; }
}
}

View File

@@ -48,6 +48,12 @@ namespace Orchard.Mvc {
return mvcHandler.RequestContext;
}
var hasRequestContext = httpContext.Handler as IHasRequestContext;
if (hasRequestContext != null) {
if (hasRequestContext.RequestContext != null)
return hasRequestContext.RequestContext;
}
return new RequestContext(httpContext, new RouteData());
}

View File

@@ -122,7 +122,7 @@ namespace Orchard.Mvc.Routes {
}
}
class HttpHandler : IHttpHandler, IRequiresSessionState {
class HttpHandler : IHttpHandler, IRequiresSessionState, IHasRequestContext {
protected readonly ContainerProvider _containerProvider;
private readonly IHttpHandler _httpHandler;
@@ -144,6 +144,13 @@ namespace Orchard.Mvc.Routes {
_containerProvider.EndRequestLifetime();
}
}
public RequestContext RequestContext {
get {
var mvcHandler = _httpHandler as MvcHandler;
return mvcHandler == null ? null : mvcHandler.RequestContext;
}
}
}
class HttpAsyncHandler : HttpHandler, IHttpAsyncHandler {
@@ -173,7 +180,6 @@ namespace Orchard.Mvc.Routes {
_containerProvider.EndRequestLifetime();
}
}
}
}
}

View File

@@ -197,6 +197,7 @@
<Compile Include="Mvc\Extensions\ControllerExtensions.cs" />
<Compile Include="Mvc\Html\FileRegistrationContextExtensions.cs" />
<Compile Include="Mvc\Extensions\UrlHelperExtensions.cs" />
<Compile Include="Mvc\IHasRequestContext.cs" />
<Compile Include="Mvc\Routes\UrlPrefix.cs" />
<Compile Include="Mvc\Routes\UrlPrefixAdjustedHttpContext.cs" />
<Compile Include="Mvc\Routes\ShellRoute.cs" />