C# castle windsor在自托管web api中使用时出现异常

C# castle windsor在自托管web api中使用时出现异常,c#,asp.net-web-api,owin,castle-windsor,self-hosting,C#,Asp.net Web Api,Owin,Castle Windsor,Self Hosting,我在自托管Web Api中使用Castle Windsor和OwinSelfHost,但当我调用controllerit的示例Get方法时,它只返回一个字符串,我在实现IDependencyScope的WindsorDependencyScope类的GetService方法中遇到以下异常: 看起来您忘了注册http模块Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule 要解决此问题,请添加 转到web.config上的部分。 如果

我在自托管Web Api中使用Castle Windsor和OwinSelfHost,但当我调用controllerit的示例Get方法时,它只返回一个字符串,我在实现IDependencyScope的WindsorDependencyScope类的GetService方法中遇到以下异常:

看起来您忘了注册http模块Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule 要解决此问题,请添加 转到web.config上的部分。 如果计划以集成管道模式在IIS上运行,则还需要将模块添加到下的部分。 或者,确保您的GAC中有Microsoft.Web.Infrastructure、Version=1.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35程序集。它由ASP.NET MVC3或WebMatrix安装,Windsor将能够自动注册模块,而无需向配置文件添加任何内容


有什么解决办法吗?

我能找到问题所在。在ControllerInstaller类中,使用了导致问题的LifestylePerWebRequest生活方式。我不知道确切的技术原因,但当使用Windsor castle与Owin组成Web Api 2+自托管时,我们应该使用Lifestyle Scope而不是Lifestyle PerWebRequest。以下是正确的安装程序代码: 公共类控制器安装程序:IWindsorInstaller { public void InstallIWindsorContainer容器,IConfigurationStore存储 { container.RegisterClasses.FromThis程序集 .Pick.Ift=>t.Name.EndsWithController .Configureconfigurer=>configurer.NamedConfigure.Implementation.Name //.LifestylePerWebRequest/--这导致了错误 .生活方式范围//正确的 ; } }