Does the transient lifestyle require HttpContext?

I register my component like this:

public static void Register(IWindsorContainer container)
    {
    container.Register(Classes.FromAssembly(Assembly.GetAssembly(typeof(GenericBaseRepository)))
        .InSameNamespaceAs<GenericBaseRepository>()
        .WithService.DefaultInterfaces()
        .LifestyleTransient());
    }

      

Then I resolve this in a piece of code that doesn't have an HttpContext:

var baseRepository = ContainerManager.Container.Resolve<IBaseRepository>();

      

(IBaseRepository is an interface implemented by GenericBaseRepository). It fails with the following message:

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

Which confuses me because the lifestyle I choose is transitional and not PerWebRequest. Of course the HttpContext doesn't exist during the scheduled task, but I don't really need that, I just need an instance of my repository that won't interact with any web request.

So why does Castle Windsor insist on the need for HttpContext when resolving my component?

0


source to share


1 answer


See the full exception message. Your root component may be temporary, but the exception points to one of its dependencies for each web request image.



Have a look at the Windsor diagnostic debugger that can help you identify it.

+3


source