Adding disposable pattern to ShellContext

This commit is contained in:
Sebastien Ros
2014-08-12 15:47:37 -07:00
parent ecb9918964
commit 60ee35837b
2 changed files with 33 additions and 4 deletions

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}
}