Whenever you new up a RequestLifetimeScopeProvider in the MVC integration, it sets that provider as a static reference with the RequestLifetimeHttpModule:
public RequestLifetimeScopeProvider(ILifetimeScope container)
{
if (container == null) throw new ArgumentNullException("container");
_container = container;
RequestLifetimeHttpModule.SetLifetimeScopeProvider(this);
}
The problem is that if you happen to want to have more than one AutofacDependencyResolver or RequestLifetimeScopeProvider for whatever reason, they effectively become singletons - creating a new one replaces the disposal semantics for the old one.
It might be better to have RequestLifetimeScopeProvider implement IDisposable and update RequestLifetimeHttpModule to allow a queue of providers. During construction, the RequestLifetimeScopeProvider could add itself to the queue; during disposal it would remove itself from the queue.
This is probably too complicated to manage for the 90% case, especially with a singleton DependencyResolver.Current. I'm going to close this for now and if it comes up again, we can re-open.
From @tillig on July 9, 2014 20:31
Whenever you new up a
RequestLifetimeScopeProvider
in the MVC integration, it sets that provider as a static reference with theRequestLifetimeHttpModule
:The problem is that if you happen to want to have more than one
AutofacDependencyResolver
orRequestLifetimeScopeProvider
for whatever reason, they effectively become singletons - creating a new one replaces the disposal semantics for the old one.It might be better to have
RequestLifetimeScopeProvider
implementIDisposable
and updateRequestLifetimeHttpModule
to allow a queue of providers. During construction, theRequestLifetimeScopeProvider
could add itself to the queue; during disposal it would remove itself from the queue.Copied from original issue: autofac/Autofac#549