Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack: AppHost does not support accessing the current Request via a Singleton

I'm encountering the following exception when trying using this.SessionAs<T> within one of my services:

"AppHost does not support accessing the current Request via a Singleton"

The offending code is located within the constructor. Strangely, I'm only seeing this when the POST verb is used. I'm not yet sure if this is just a coincidence or not.

My apologies for not providing detailed information at this point. I'm trying to figure out which direction my troubleshooting should take. I'll edit as needed.

Thanks

Update - Stack trace

at ServiceStack.HostContext.GetCurrentRequest() at ServiceStack.SessionFeature.GetOrCreateSession[T](ICacheClient cache, IRequest httpReq, IResponse httpRes) at ServiceStack.Service.SessionAsTUserSession at PeruseServiceStack.Services.Settings.UserService..ctor() at lambda_method(Closure , Container ) at Funq.Container.ResolveImpl[TService](String name, Boolean throwIfMissing)

I will be updating further shortly, I feel like this trace is incomplete.

like image 852
SeanH Avatar asked Oct 22 '25 04:10

SeanH


1 Answers

From the StackTrace it looks like you're trying to access SessionAs<T> in your UserService constructor which you can't do because the Session can only be accessed within the context of a Request and the Service constructor does not have access to the injected IRequest context to be able to access the Session.

So you'd need to move SessionAs<T>() calls out of your constructor to within your Service implementation.

like image 109
mythz Avatar answered Oct 24 '25 19:10

mythz