In MVC application we are using windsor container and NUnit testing. Following is the windsor registration code:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
container.Register(Component.For<IHttpContextBaseWrapper>().ImplementedBy<HttpContextBaseWrapper>().LifestylePerWebRequest());
container.Register(Component.For<IWebUtility>().ImplementedBy<WebUtility>().LifestylePerWebRequest());
container.Register(Component.For<IExceptionReporter>().ImplementedBy<ExceptionReporter>().LifestylePerWebRequest());
container.Register(Component.For<ICacheProvider>().ImplementedBy<WebCacheProvider>().LifestylePerWebRequest());
container.Register(Component.For<IEmailNotifier>().ImplementedBy<EmailNotifier>().LifestylePerWebRequest());
container.Register(Component.For<IUserStore<ApplicationUser>>().ImplementedBy<ApplicationUserStore<ApplicationUser>>().LifestylePerWebRequest());
container.Register(Component.For<ApplicationUserManager>().ImplementedBy<ApplicationUserManager>().LifestylePerWebRequest());
}
It works fine with normal web request(from browser) but not working wile calling controller methods from NUnit test cases. It gives following error while resolving service instances.
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
.
If you plan running on IIS in Integrated Pipeline mode, 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.
i tried putting
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
in app.config/web.config. But found same error.