Are HostContext and ServiceStackHost.Instance the same object?

Hello,
I’ve got a strange problem during a deploy in a production enviorment… I got an exception in a class telling that it was unable to resolve ICacheClient (which was correctly registered)

I’ve replaced in my class

public sealed class ModuleResolver : IModuleResolver
{
   
    //readonly ICacheClient _appSettingsCache = HostContext.Resolve<ICacheClient>();
   ...
}

with

readonly ICacheClient _appSettingsCache = ServiceStackHost.Instance.Resolve<ICacheClient>();

And it works… the ICacheClient was registered inside AppHost.cs Configure using the passed container

Thanks in advance
Paolo

It’s likely due to order of execution since HostContext.Resolve is effectively doing the same thing. Try lazy loading it:

public sealed class ModuleResolver : IModuleResolver
{
   
    ICacheClient _appSettingsCache;
    public ICacheClient Cache => _appSettingsCache 
        ?? (_appSettingsCache = HostContext.Resolve<ICacheClient>());
}