asp.net-mvc-2 - ASP.NET MVC2 IoC : Looking for an example using CaSTLeWindsor container that works with minimum config

标签 asp.net-mvc-2 castle-windsor ioc-container

我正在寻找如何配置 ASP.NET MVC2 项目以使用 CaSTLeWindsor 容器执行 IoC 的示例。

我在设置它时不断遇到问题,对于每个问题似乎都有一个在线解决方案,但最终我做了很多更改并最终得到了如此冗长的设置以使 IoC 使用 CaSTLeWindsor 工作,我认为最好问这个问题。

我正在寻找 Global.asax 页面、Web.config 中所需的最低配置,以及如果需要的话,还需要哪些其他更改和扩展类。

我不打算在这个阶段注入(inject) Action 过滤器,所以只是基础知识。最好不要使用 XML 文件,而是在 .NET 中以编程方式执行。

提前谢谢您...

最佳答案

这是最基本的:

  1. 从 VS2010 启动 MVC2 项目
  2. Download MvcContrib对于 MVC2(表示“额外二进制文件”的那个)
  3. 在您的项目中,添加对(所有这些 DLL 都包含在 MvcContrib 中)的引用:

    • CaSTLe.Core.dll
    • CaSTLe.DynamicProxy2.dll
    • CaSTLe.MicroKernel.dll
    • CaSTLe.Windsor.dll
    • MvcContrib.dll
    • MvcContrib.CaSTLe.dll
  4. 在您的 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/

相关文章:

c# - 如何让用户在 asp.net mvc 2 中异步下载多个文件?

javascript - 西类牙语特殊字符如 á ó 显示时显示困惑或垃圾值

asp.net-mvc - MVC - 在帖子中更改模型值

asp.net-mvc - MVC3 模型与 CaSTLe 绑定(bind)

c# - 具有依赖注入(inject)的单例

c# - 如何使用 CaSTLe Windsor 通过 WPF 应用程序实现正确的 Di

c# - 根据Route在Controller中注入(inject)不同的实现

asp.net 请求.form

c# - 第一次使用 IoC 因为我碰壁了,请解释一下 'behind the scenes'

c# - 简单的注入(inject)器打开通用装饰器