我正在寻找如何配置 ASP.NET MVC2 项目以使用 CaSTLeWindsor 容器执行 IoC 的示例。
我在设置它时不断遇到问题,对于每个问题似乎都有一个在线解决方案,但最终我做了很多更改并最终得到了如此冗长的设置以使 IoC 使用 CaSTLeWindsor 工作,我认为最好问这个问题。
我正在寻找 Global.asax 页面、Web.config 中所需的最低配置,以及如果需要的话,还需要哪些其他更改和扩展类。
我不打算在这个阶段注入(inject) Action 过滤器,所以只是基础知识。最好不要使用 XML 文件,而是在 .NET 中以编程方式执行。
提前谢谢您...
最佳答案
这是最基本的:
- 从 VS2010 启动 MVC2 项目
- Download MvcContrib对于 MVC2(表示“额外二进制文件”的那个)
在您的项目中,添加对(所有这些 DLL 都包含在 MvcContrib 中)的引用:
- CaSTLe.Core.dll
- CaSTLe.DynamicProxy2.dll
- CaSTLe.MicroKernel.dll
- CaSTLe.Windsor.dll
- MvcContrib.dll
- MvcContrib.CaSTLe.dll
在您的 Application_Start() 中,添加以下行(以及所需的任何命名空间):
var container = new WindsorContainer(); container.RegisterControllers(typeof(HomeController).Assembly); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
关于asp.net-mvc-2 - ASP.NET MVC2 IoC : Looking for an example using CaSTLeWindsor container that works with minimum config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3535214/