我已经创建了一个ASP.NET MVC应用程序,我试图使用温莎城堡作为我的IOC
然而,当控制器试图解决我得到“内容”和“脚本”为在该“controllerName”参数CreateController(RequestContext requestContext, string controllerName)
方法。 不用说这些都不是控制器。 他们似乎是网站的文件夹
为什么试图注册这些作为控制器?
我怎么忽略这些文件夹?
谢谢
从WindsorControllerFactory例外
由于不能够张贴的图片我已经来形容它 - 它基本上只是说:
“该contentcontroller未找到”
的Global.asax.cs
public static IIocContainer Ioc;
protected void Application_Start()
{
InitialiseIocContainer();
RegisterViewEngine(ViewEngines.Engines);
RegisterRoutes(RouteTable.Routes);
StartProfiling();
}
private void InitialiseIocContainer()
{
IWindsorContainer _container = new WindsorContainer();
var controllerTypes = typeof (GidgetController).Assembly.GetTypes();
foreach (var controllerType in controllerTypes.Where((t=>typeof(IController).IsAssignableFrom(t))))
{
_container.AddComponentLifeStyle(controllerType.Name.ToLower(), controllerType, LifestyleType.Transient);
}
_container.AddComponent("a",typeof(IGidgetService), typeof(GidgetService));
_container.AddComponent("b",typeof(IGidgetRepository), typeof(GidgetRepository));
_container.AddComponent("c",typeof(IGidgetValidator), typeof(GidgetValidator));
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container));
}
windsorControllerFactory.cs
public IController CreateController(RequestContext requestContext, string controllerName)
{
try
{
controllerName = controllerName.ToLower() + "controller";
var controller = _container.Resolve<IController>(controllerName);
return controller;
}
catch (ComponentNotFoundException)
{
throw new HttpException(404, string.Format("The {0} controller was not found", controllerName));
}
}