Castle windsor lifestyle issue

纵饮孤独 提交于 2019-12-10 18:21:17

问题


I am implementing hangFire which is a job scheduling library in my project.

I am facing the same issue as faced in this link

However after replacing LifestylePerWebRequest() with HybridPerWebRequestTransient() I am still getting the same error message:

HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net

Here's a couple of the lines of my dependency installer:

container.Register(Component.For<IApiHra>()
                            .ImplementedBy(typeof(ApiHra))
                            .LifeStyle.HybridPerWebRequestTransient()
                            .IsFallback());

container.Register(Component.For<IApiHraComment>()
                            .ImplementedBy(typeof(ApiHraComment))
                            .LifestylePerWebRequest()
                            .IsFallback());

This is controller installer in windsor controller factory

public class ControllersInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Classes.FromThisAssembly()
                                  .BasedOn<IController>()
                                  .LifestyleTransient());
    }
}

Please let me know if any other information is required.


回答1:


See Krzysztof Kozmic's answer here. Your IApiHra component likely has a PerWebRequestLifestyle dependency.



来源:https://stackoverflow.com/questions/29913941/castle-windsor-lifestyle-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!