使用Umbraco 7.1.8和Castle Windsor 3.3.0获取每个请求的404。使用Umbraco相当新,并且尚未设置IoC,但温莎对我来说并不陌生。
控制器本身似乎是从容器中解析出来的,容器本身已经注册了正确的(非umbraco)控制器。
我在这里缺少什么?有人能指出我正确的方向吗?
干杯。
public class Global : UmbracoApplication
{
private static IWindsorContainer container;
protected override void OnApplicationStarting(object sender, EventArgs e)
{
base.OnApplicationStarting(sender, e);
container = new WindsorContainer().Install(FromAssembly.This());
UmbracoFilteredControllerFactory.Kernel = container.Kernel;
FilteredControllerFactoriesResolver.Current.InsertType<UmbracoFilteredControllerFactory>(0);
}
温莎控制器工厂
public class WindsorControllerFactory : DefaultControllerFactory
{
protected readonly IKernel Kernel;
public WindsorControllerFactory(IKernel kernel)
{
this.Kernel = kernel;
}
public override void ReleaseController(IController controller)
{
this.Kernel.ReleaseComponent(controller);
}
public override IController CreateController(RequestContext requestContext, string controllerName)
{
var controllerType = GetControllerType(requestContext, controllerName);
return (IController)this.Kernel.Resolve(controllerType);
}
}
过滤工厂
public class UmbracoFilteredControllerFactory : WindsorControllerFactory, IFilteredControllerFactory
{
private static IKernel _kernel;
public UmbracoFilteredControllerFactory()
: base(_kernel)
{
}
public static IKernel Kernel
{
get
{
if (_kernel == null)
{
throw new ArgumentNullException("Set Kernel in WindsorControllerFactory.");
}
return _kernel;
}
set
{
_kernel = value;
}
}
public bool CanHandle(RequestContext request)
{
var controllerType = GetControllerType(request, request.RouteData.Values["controller"].ToString());
return Kernel.HasComponent(controllerType);
}
}