Posts tagged windsor
Posts tagged windsor
28 notes &
Whowh, that’s a nice error:
Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule To fix this add <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" /> to the <httpModules> section on your web.config. Windsor also detected you're running IIS in Integrated Pipeline mode. This means that you also need to add the module to the <modules> section under <system.webServer>. Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file.
That doesn’t make sense… After some fumbling around I got the next error message:
An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'
And after that another error in log4net configuration. Eventually colleague Mark helped me figure out the following was the underlying problem:
log4net version 1.2.11 has a different publicKeyToken then 1.2.10
So when I upgraded my nuget files, log4net 1.2.11 got downloaded and referenced. But castle.windsor was looking for 1.2.10, and didn’t see the similarity with 1.2.11. And so it epically failed :( For some reason it did work on my machine, but not on the live server, which didn’t help.
What can we learn from this?
It took me 2 hours to figure out what was wrong. And all that because I let castle.windsor do the dependency injection via public properties. This just ended up with CollectionObjectService being null:
public CollectionObjectService CollectionObjectService { get; set; } public SynchronizerService() { }
When I re-wrote it so the services use constructors to get their dependencies injected, the error that actually told me what was wrong turned up:
public CollectionObjectService CollectionObjectService { get; private set; } public SynchronizerService(CollectionObjectService coService) { this.CollectionObjectService = coService; }