SJMan
SJMan

Reputation: 1607

Castle windsor lifestyle issue

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.

Upvotes: 3

Views: 1088

Answers (1)

ejohnson
ejohnson

Reputation: 711

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

Upvotes: 0

Related Questions