Я получаю следующее исключение: «Экземпляры не могут быть разрешены, и вложенные сроки жизни не могут быть созданы из этого LifetimeScope, поскольку он уже был удален». когда я пытаюсь разрешить объект из события global.asax Application_EndRequest. Использую Autofac в версии 2.5.2.830
public class Global : System.Web.HttpApplication, IContainerProviderAccessor
{
// Provider that holds the application container.
static Autofac.Integration.Web.IContainerProvider _containerProvider;
// Instance property that will be used by Autofac HttpModules
// to resolve and inject dependencies.
public Autofac.Integration.Web.IContainerProvider ContainerProvider
{
get { return _containerProvider; }
}
protected void Application_Start(object sender, EventArgs e)
{
var builder = new ContainerBuilder();
...
_containerProvider = new ContainerProvider(builder.Build());
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
ISession session = _containerProvider.RequestLifetime.Resolve<ISession>();
session.BeginTransaction();
}
private void Application_EndRequest(object sender, EventArgs e)
{
ISession session = ContainerProvider.RequestLifetime.Resolve<ISession>();
}
Я регистрируюсь таким образом:
builder.Register (x => x.Resolve (). OpenSession ()). As (). InstancePerHttpRequest (); }