In my web.api application I use EntityFramework 6 (EF6), MediatR, and Autofac. I want to Create EF6 DbContext with a lifetime matching MediatR RequestHandlers so that I obtain a unit of work per RequestHandler invocation.I've been looking into Autofac concepts like InstancePerMatchingLifteTimeScope, Owned< Dependency > and also MediatR Handler Decoration using MediatR Pipeline.
I haven't found any solution yet. It seems I need to wrap both Handler Creation and handler invocation inside a AutofacLifeTimeScope tagged with a wellknown-object, so I can register IDBContext with InstancePerMatchingLifeTimeScope(wellknown-object).
Maybe You can propose another solution ?