3

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.

Community
  • 1
  • 1
SJMan
  • 1,547
  • 2
  • 14
  • 37
  • 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 Apr 29 '15 at 08:23
  • 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 exception – SJMan Apr 29 '15 at 08:55
  • @SJMan Did you ever figure this out? – Olson.dev Sep 29 '16 at 18:59
  • Any solution for this? I am struggling with the same problem. – Nanou Ponette Aug 03 '17 at 12:42

1 Answers1

0

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

ejohnson
  • 655
  • 7
  • 18