mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding disposable pattern to ShellContext
This commit is contained in:
@@ -92,7 +92,8 @@ namespace Orchard.Environment {
|
||||
BuildCurrent();
|
||||
|
||||
var shellContext = CreateShellContext(shellSettings);
|
||||
return new StandaloneEnvironmentWorkContextScopeWrapper(shellContext.LifetimeScope.CreateWorkContextScope(), shellContext);
|
||||
var workContext = shellContext.LifetimeScope.CreateWorkContextScope();
|
||||
return new StandaloneEnvironmentWorkContextScopeWrapper(workContext, shellContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -215,7 +216,7 @@ namespace Orchard.Environment {
|
||||
if (_shellContexts != null) {
|
||||
foreach (var shellContext in _shellContexts) {
|
||||
shellContext.Shell.Terminate();
|
||||
shellContext.LifetimeScope.Dispose();
|
||||
shellContext.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,7 +353,7 @@ namespace Orchard.Environment {
|
||||
|
||||
public void Dispose() {
|
||||
_workContextScope.Dispose();
|
||||
_shellContext.LifetimeScope.Dispose();
|
||||
_shellContext.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,42 @@
|
||||
using System;
|
||||
using Autofac;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
|
||||
namespace Orchard.Environment.ShellBuilders {
|
||||
public class ShellContext {
|
||||
public class ShellContext : IDisposable {
|
||||
private bool _disposed = false;
|
||||
|
||||
public ShellSettings Settings { get; set; }
|
||||
public ShellDescriptor Descriptor { get; set; }
|
||||
public ShellBlueprint Blueprint { get; set; }
|
||||
public ILifetimeScope LifetimeScope { get; set; }
|
||||
public IOrchardShell Shell { get; set; }
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
if (!_disposed) {
|
||||
|
||||
if (disposing) {
|
||||
LifetimeScope.Dispose();
|
||||
}
|
||||
|
||||
Settings = null;
|
||||
Descriptor = null;
|
||||
Blueprint = null;
|
||||
Shell = null;
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~ShellContext() {
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user