I am using Hangfire and Autofac in a aspnetcore project. So far so good. I have some
CorrelationContext class that stores a guid (correlationid). I have created a
ICorrelationContextAccessor interface that has a property used to access
I have two ICorrelationContextAccessor implementations:
HttpContextCorrelationContextAccessor gets the
CorrelationContext from the http requestcontext (if in a webapi request)
JobContextCorrelationContextAccessor one gets it from a job's context which is an instanceperlifetime object
My idea was that I could use two containers, one for jobs and one for http requests and register these two accessors as singleinstance in one of them.
var builder = new Autofac.ContainerBuilder();
ApplicationContainer = builder.Build();
var builderForJob = new Autofac.ContainerBuilder();
var JobContainer = builderForJob.Build();
When running jobs though, I see that my
ICorrelationContextAccessor is of type
HttpContextCorrelationAccessor. Why is this? How would I use a different approach to get my
CorrelationContext in a job and a httprequest?