How to inject IRequest into my own type?

I have a custom type that is registered in the appHost.Config() in the usual way.

However, this class needs access to the IRequest of each request (actually, it really just needs access to the current IAuthSession, and we currently do that by doing a IRequest.GetSession())

We have tried this, of course:

public override void Configure(Container container)
        {
            container.Register<ICurrentCaller>(x => new AuthSessionCurrentCaller
            {
                Request = request,
            }).ReusedWithin(ReuseScope.Request);
... other types
        }

but IRequest is of course not available in this context, so we have also tried this:

public override void Configure(Container container)
        {
            GlobalRequestFilters.Add((request, response, dto) =>
            {
                container.Register<ICurrentCaller>(x => new AuthSessionCurrentCaller
                {
                    Request = request,
                }).ReusedWithin(ReuseScope.Request);
            });
... other types
        }

but this is not reliable for whatever reason. The ICurrentCaller is injected into our base service class where it is used throughout all our services, and we sometimes get the wrong IRequest instance on subsequent calls to our API.

public abstract class ServiceBase : ServiceStack.Service
{
    public ICurrentCaller Caller { get; set; }

... operations etc
}

How can I get access to the IRequest in an instance of a AuthSessionCurrentCaller type, so I can call IRequest.GetSession() for every request?

The Container should be immutable after initialization. The IRequest is only available in the context of an incoming request which should be passed into your deps via a param from your Service from base.Request property, you can use HostContext.TryGetCurrentRequest() to get a IRequest wrapper for the current request but that only works in ASP.NET Hosts and is therefore not recommended.

I found a resolution that had already been discussed, that has helped in my case: Stackoverflow

For anyone doing the same, I made some improvements to it that (a) make it recursive for all your types (and their dependencies), and (b) do less work, by excluding types that will never implement IRequiresRequest. Since this code is doing heaps of reflection work every request.

        private static readonly string[] ExcludedInjectionNamespaces =
        {
            @"System",
            @"Microsoft",
            @"ServiceStack"
        };

        public static void InjectRequestIntoServiceDependencies(this object instance, IRequest request)
        {
            var instanceType = instance.GetType();
            var ns = instanceType.Namespace;
            if (ns != null && ExcludedInjectionNamespaces.Any(ex => ns.StartsWith(ex)))
            {
                return;
            }

            var injectableProperties = instanceType.GetPublicProperties();

            foreach (var prop in injectableProperties)
            {
                if (!prop.CanRead
                    || !prop.CanWrite)
                {
                    continue;
                }

                var getMethod = prop.GetGetMethod();
                if (getMethod == null)
                {
                    continue;
                }

                try
                {
                    var dependency = getMethod.Invoke(instance, new object[0]);

                    var requiresRequestDependency = dependency as IRequiresRequest;
                    if (requiresRequestDependency != null)
                    {
                        requiresRequestDependency.Request = request;
                    }

                    if (dependency != null)
                    {
                        dependency.InjectRequestIntoServiceDependencies(request);
                    }
                }
                catch (TargetInvocationException)
                {
                    //Ignore 
                }
            }
        }

Although, would like to try and avoid having to catch the exceptions if possible.