开发者

ASP.NET MVC2 IoC: Looking for an example using CastleWindsor container that works with minimum config

I am looking for an example of how to configure an ASP.NET MVC2 project to use CastleWindsor container to do IoC.

I keep running into problems setting it up, and for every problem there seems to be a solution on-line, but in the end I make so many changes and end up with such a verbose setup to get IoC working using CastleWindsor, that I thought it best to ask this question.

I am looking for the minimum configuration required in the Global.asax page, the Web.config, and if required, what other changes and extension classes are required.

I am not looking to inject into actionfilters at this stage, so just the basics. Preferably not using XML files, but doing it in .NET programatically.

Thank you in advanc开发者_运维问答e...


This is as basic as it gets:

  1. Start a MVC2 project from VS2010
  2. Download MvcContrib for MVC2 (the one that says "extra binaries")
  3. In your project, add a reference to (all these DLLs are included in MvcContrib):

    • Castle.Core.dll
    • Castle.DynamicProxy2.dll
    • Castle.MicroKernel.dll
    • Castle.Windsor.dll
    • MvcContrib.dll
    • MvcContrib.Castle.dll
  4. In your Application_Start(), add these lines (and whatever namespaces are needed):

    var container = new WindsorContainer();
    container.RegisterControllers(typeof(HomeController).Assembly);
    ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜