Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Having come across similar problems when attempting to use the Windsor IoC container in an ASP.NET MVC app I had to go through the same voyage of discovery to get it working. Here are some of the details that might help someone else.</p> <p>Using this is the initial setup in the Global.asax:</p> <pre><code> if (_container == null) { _container = new WindsorContainer("config/castle.config"); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container)); } </code></pre> <p>And using a WindsorControllerFactory which when asked for a controller instance does:</p> <pre><code> return (IController)_container.Resolve(controllerType); </code></pre> <p>Whilst Windsor was correctly linking up all of the controllers, for some reason parameters were not being passed from the form to the relevant controller action. Instead they were all null, though it was calling the correct action.</p> <p>The default is for the container to pass back singletons, obviously a bad thing for controllers and the cause of the problem:</p> <p><a href="http://www.castleproject.org/monorail/documentation/trunk/integration/windsor.html" rel="nofollow noreferrer">http://www.castleproject.org/monorail/documentation/trunk/integration/windsor.html</a></p> <p>However the documentation does point out that the lifestyle of the controllers can be changed to transient, though it doesn't actually tell you how to do that if you are using a configuration file. Turns out it's easy enough:</p> <pre><code>&lt;component id="home.controller" type="DoYourStuff.Controllers.HomeController, DoYourStuff" lifestyle="transient" /&gt; </code></pre> <p>And without any code changes it should now work as expected (i.e. unique controllers every time provided by the one instance of the container). You can then do all of your IoC configuration in the config file rather than the code like the good boy/girl that I know you are.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload