I have a WebApi project and in a controller I'm using HostingEnvironment.QueueBackgroundWorkItem to start a job in a separate thread:
public IHttpActionResult DoJob()
{
HostingEnvironment.QueueBackgroundWorkItem(ct =>
{
var service = new MyService(logService, userInfo);
var entity = service.DoJob(ct);
});
return Ok();
}
Currently, in the above I'm using a concrete instance (which I want to replace) of my service . I also use Autofac and for my services, I configured as follows:
builder.RegisterAssemblyTypes(assemblies)
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces()
.InstancePerRequest();
The above registration works fine for all services when using normally within a request.
Will the above registration also work for services when run in a separate thread after the request terminates?