May 26, 2011 at 6:30 AM
Edited May 26, 2011 at 5:37 PM
Thanks you for your reply.
I saw the code in Orchard.Framework/Environment/AutofacUtil.
But maybe I misunderstood something, or did not make my point clearly.
Like Nicholas saying here http://nblumhardt.com/2011/01/an-autofac-lifetime-primer/,
To prevent memory and resource leaks, always resolve components from lifetime scopes and dispose the scope at the conclusion of a task
using (var lifetimeScope = container.BeginLifetimeScope())
var r = lifetimeScope.Resolve<IMyResource>();
// r, all of its dependencies and any other components
// created indirectly will be released here
The using statement can ensure disposer execute and the lifetimeScope is released.
But when it is NOT within a single method call, in a web request for example, I saw autofac.integration.mvc's solution is at the Appicstion.EndRquest event, dispose the scope, something like:
public void Init(HttpApplication context)
context.EndRequest += OnEndRequest;
static void OnEndRequest(object sender, EventArgs e)
if (LifetimeScopeProvider != null)
public void EndLifetimeScope()
var lifetimeScope = LifetimeScope;
if (lifetimeScope != null)
Maybe orchard uses a different way to dispose the scope, but i did not understand. Very appreciate it if you can explain.
Or the scope is not must-be diposed explicitly and can be collected by GC?