I'm using autofac in an owin-driven web api project. I've come to a place where I need to "Fire and Forget" some processing of data.
This normally isn't an issue. But since the dependencies are controlled by the per-request lifetime scope managed by the autofac middleware. I cannot use un-managed resources (which is what i need to do) in my non-awaited async
method.
//for example...
public async Task<IEnumerable<MyThings>> GetThings(){
var things = await _thingRepo.GetInterestingThingsAsync();
//fire and forget. -- not awaiting
InjectedObject.DoThingsAsync(things);
return things;
}
The problem here is that I need to use other injected resources (un-managed resources) inside DoThingsAsync
. Currently this breaks because they're disposed of when the Owin Request ends.
I could create a child lifetime scope for each invocation but I'm hoping their might be a cleaner way to do such things..