ASP.NET Core 2 with Autofac: Background Jobs Fail to Resolve

Tags: #<Tag:0x00007f23564a96a8> #<Tag:0x00007f23564a9540> #<Tag:0x00007f23564a9450>

I’m porting an application from .NET 4.6 over to .NET Core 2.0 with Hangfire.AspNetCore 1.6.15, Hangfire.Autofac 2.3.1, and Autofac.AspNetCore.Multitenant 1.0.0. I have a few services that started out (before introduction of Hangfire) as per request. Once Hangfire was introduced, I registered this using recommendation outlined here:

Prior (in .NET 4.6) I was using InstancePerMatchingLifetimeScope like:

var requestTag = MatchingScopeLifetimeTags.RequestLifetimeScopeTag;
var jobTag = AutofacJobActivator.LifetimeScopeTag;
builder.RegisterType().InstancePerMatchingLifetimeScope(requestTag, jobTag);

With the migration to .NET Core now, I’ve now switched these over to use InstancePerLifetimeScope. From the web side, all is well. I can inject dependencies without issue. If I attempt to inject the same component in the context of a background job, I’m met with:

In terms of my Startup code, I’m registering Hangfire as follows:

                .UseFilter(new BaseJobContextFilter());

I did not use the autofac activator given I am returning the AutofacServiceProvider in Startup#ConfigureServices override. I’m hoping someone can point me to an example or documentation that might illustrate what I’ve messed up.