autofac / Autofac.Mvc

ASP.NET MVC integration for Autofac
MIT License
49 stars 23 forks source link

RequestLifetimeProvider stored as static reference in ASP.NET MVC #6

Closed tillig closed 8 years ago

tillig commented 9 years ago

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 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.

Copied from original issue: autofac/Autofac#549

tillig commented 8 years ago

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.