mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#20877: standalone environments have their shell lifetime scope disposed as well
Work Item: 20877
This commit is contained in:
@@ -38,7 +38,7 @@ namespace Orchard.Environment {
|
||||
IExtensionLoaderCoordinator extensionLoaderCoordinator,
|
||||
IExtensionMonitoringCoordinator extensionMonitoringCoordinator,
|
||||
ICacheManager cacheManager,
|
||||
IHostLocalRestart hostLocalRestart ) {
|
||||
IHostLocalRestart hostLocalRestart) {
|
||||
_shellSettingsManager = shellSettingsManager;
|
||||
_shellContextFactory = shellContextFactory;
|
||||
_runningShellTable = runningShellTable;
|
||||
@@ -90,8 +90,9 @@ namespace Orchard.Environment {
|
||||
|
||||
MonitorExtensions();
|
||||
BuildCurrent();
|
||||
|
||||
var shellContext = CreateShellContext(shellSettings);
|
||||
return shellContext.LifetimeScope.CreateWorkContextScope();
|
||||
return new StandaloneEnvironmentWorkContextScopeWrapper(shellContext.LifetimeScope.CreateWorkContextScope(), shellContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,17 +154,17 @@ namespace Orchard.Environment {
|
||||
/// Starts a Shell and registers its settings in RunningShellTable
|
||||
/// </summary>
|
||||
private void ActivateShell(ShellContext context) {
|
||||
Logger.Debug("Activating context for tenant {0}", context.Settings.Name);
|
||||
Logger.Debug("Activating context for tenant {0}", context.Settings.Name);
|
||||
context.Shell.Activate();
|
||||
|
||||
_shellContexts = (_shellContexts ?? Enumerable.Empty<ShellContext>())
|
||||
.Where(c => c.Settings.Name != context.Settings.Name)
|
||||
.Concat(new[] { context })
|
||||
.ToArray();
|
||||
|
||||
.ToArray();
|
||||
|
||||
_runningShellTable.Add(context.Settings);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a transient shell for the default tenant's setup
|
||||
/// </summary>
|
||||
@@ -326,5 +327,33 @@ namespace Orchard.Environment {
|
||||
Logger.Debug("Adding tenant to restart: " + tenant);
|
||||
_tenantsToRestart.GetState().Add(context.Settings);
|
||||
}
|
||||
|
||||
// To be used from CreateStandaloneEnvironment(), also disposes the ShellContext LifetimeScope.
|
||||
private class StandaloneEnvironmentWorkContextScopeWrapper : IWorkContextScope {
|
||||
private readonly ShellContext _shellContext;
|
||||
private readonly IWorkContextScope _workContextScope;
|
||||
|
||||
public WorkContext WorkContext {
|
||||
get { return _workContextScope.WorkContext; }
|
||||
}
|
||||
|
||||
public StandaloneEnvironmentWorkContextScopeWrapper(IWorkContextScope workContextScope, ShellContext shellContext) {
|
||||
_workContextScope = workContextScope;
|
||||
_shellContext = shellContext;
|
||||
}
|
||||
|
||||
public TService Resolve<TService>() {
|
||||
return _workContextScope.Resolve<TService>();
|
||||
}
|
||||
|
||||
public bool TryResolve<TService>(out TService service) {
|
||||
return _workContextScope.TryResolve<TService>(out service);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_workContextScope.Dispose();
|
||||
_shellContext.LifetimeScope.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user