I have a class that is Registered using InstancePerApiRequest, but I also need to access it outside of the scope of the request. When the class is resolved in the background task I receive the following error: “No scope with a Tag matching ‘AutofacWebRequest’ is visible from the scope in which the instance was requested.”. Adding InstancePerLifetimeScope after InstancePerApiRequest corrects the error, but how does this effect the actual registration. Am I still getting InstancePerApiRequest or did I just override the prior?
Note the task is created in a DelegatingHandler using .ContinueWith.
If this is not correct how can I accomplish this?
In order to handle this I ended up registering them again using Named and AsInstancePerLifetime. So any background task resolves using the named lifetimes and items in the request/response flow use the ones registered with InstancePerApiRequest.