3
votes

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
It seems to me that IApiHraComment still has LifestylePerWebRequest. So if this this components is resolved from the container without Http.Context I expect it to throw. Can you find in the error message which component is causing the exception ?Marwijn
actually I am using IApiHra only . It has other dependencies as well, i tried making them all hybrid but it did not work.IApiHra is causing the exceptionSJMan
@SJMan Did you ever figure this out?Olson.dev
Any solution for this? I am struggling with the same problem.Nanou Ponette

1 Answers

0
votes

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