为什么温莎城堡试图解决我的'内容'和'脚本'文件夹作为控制器? [英] Why is Castle Windsor trying to resolve my 'Content' and 'Scripts' folder as a controller?

查看:173
本文介绍了为什么温莎城堡试图解决我的'内容'和'脚本'文件夹作为控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个ASP.NET MVC应用程序,我试图使用温莎城堡作为我国际奥委会



然而,当控制器试图解决我得到'内容'和'脚本'入'的 CreateController(RequestContext的的RequestContext,串controllerName)方法controllerName'参数。不用说,这些都不是控制器。他们似乎是网站的文件夹



为什么试图注册这些作为控制器?



如何忽略这些文件夹?



感谢



这WindsorControllerFactory例外



由于不能够发布图片我已经来形容它 - 它基本上只是说:




的contentcontroller未找到




的Global.asax.cs

 公共静态IIocContainer的Ioc; 

保护无效的Application_Start()
{
InitialiseIocContainer();
RegisterViewEngine(ViewEngines.Engines);
的RegisterRoutes(RouteTable.Routes);
StartProfiling();
}


私人无效InitialiseIocContainer()
{
IWindsorContainer _container =新WindsorContainer();

VAR controllerTypes = typeof运算(GidgetController).Assembly.GetTypes();
的foreach(在controllerTypes.Where VAR controllerType((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(新WindsorControllerFactory(_container));

}



windsorControllerFactory.cs

 公众一个IController CreateController(RequestContext的的RequestContext,串controllerName)
{

{
controllerName = controllerName.ToLower( )+控制器;
无功控制器= _container.Resolve<一个IController>(controllerName);
返回控制器;
}
赶上(ComponentNotFoundException)
{
抛出新的HttpException(404的String.Format({0}控制器没有被发现,controllerName));

}

}


解决方案

只需使用 MVCContrib



它包括一切整合温莎和ASP.NET MVC中,包括的控制器工厂并的扩展注册控制器的。


I have created an ASP.NET MVC application and am trying to use Castle Windsor as my IOC

However, when the controllers are trying to resolve I am getting 'Content' and 'Scripts' into the 'controllerName' parameter in the CreateController(RequestContext requestContext, string controllerName) method. Needless to say these are not controllers. They appears to be the folders of the web site

Why is it trying to register these as controllers?

How do I ignore these folders??

thanks

exception from WindsorControllerFactory

Due to not being able to post the image I have to describe it - it basically just says

'The contentcontroller was not found'

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));

            }

        }

解决方案

Just use MVCContrib.

It includes everything to integrate Windsor and ASP.NET MVC, including the controller factory and extensions to register controllers.

这篇关于为什么温莎城堡试图解决我的'内容'和'脚本'文件夹作为控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆