Further work on IWorkContextEvents. Swallowing all non-fatal exceptions. Events should be resolved once per context.

--HG--
branch : 1.x
This commit is contained in:
Piotr Szmyd
2013-04-05 03:53:35 +02:00
parent f68f72e416
commit c7e0784b13
5 changed files with 10 additions and 33 deletions

View File

@@ -2,9 +2,7 @@
using Autofac;
using NUnit.Framework;
using Orchard.Environment;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Tests.Logging;
using Orchard.Tests.Stubs;
using Orchard.Tests.Utility;
@@ -22,9 +20,6 @@ namespace Orchard.Tests.Environment {
protected override void Register(ContainerBuilder builder) {
builder.RegisterModule(new WorkContextModule());
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterModule(new LoggingModule());
var stubFactory = new LoggingModuleTests.StubFactory();
builder.RegisterInstance(stubFactory).As<ILoggerFactory>();
builder.RegisterAutoMocking();
}

View File

@@ -8,9 +8,7 @@ using Orchard.Environment.ShellBuilders;
using Orchard.Environment.Descriptor;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Tests.Logging;
using Orchard.Tests.Utility;
namespace Orchard.Tests.Environment.ShellBuilders {
@@ -24,10 +22,7 @@ namespace Orchard.Tests.Environment.ShellBuilders {
builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
builder.RegisterModule(new WorkContextModule());
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterModule(new LoggingModule());
var stubFactory = new LoggingModuleTests.StubFactory();
builder.RegisterInstance(stubFactory).As<ILoggerFactory>();
builder.RegisterAutoMocking(MockBehavior.Strict);
builder.RegisterAutoMocking(Moq.MockBehavior.Strict);
_container = builder.Build();
}

View File

@@ -10,9 +10,7 @@ using Orchard.Environment.ShellBuilders;
using Orchard.Environment.State;
using Orchard.Environment.Descriptor.Models;
using Orchard.Events;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Tests.Logging;
using Orchard.Tests.Utility;
namespace Orchard.Tests.Environment.State {
@@ -27,9 +25,6 @@ namespace Orchard.Tests.Environment.State {
builder.RegisterType<DefaultProcessingEngine>().As<IProcessingEngine>();
builder.RegisterModule(new WorkContextModule());
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterModule(new LoggingModule());
var stubFactory = new LoggingModuleTests.StubFactory();
builder.RegisterInstance(stubFactory).As<ILoggerFactory>();
builder.RegisterAutoMocking();
_container = builder.Build();

View File

@@ -10,10 +10,8 @@ using Orchard.Caching;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Mvc.Routes;
using Orchard.Tests.Logging;
using Orchard.Tests.Stubs;
using Orchard.Tests.Utility;
@@ -44,9 +42,7 @@ namespace Orchard.Tests.Mvc.Routes {
rootBuilder.RegisterType<StubCacheManager>().As<ICacheManager>();
rootBuilder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
rootBuilder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
rootBuilder.RegisterModule(new LoggingModule());
var stubFactory = new LoggingModuleTests.StubFactory();
rootBuilder.RegisterInstance(stubFactory).As<ILoggerFactory>();
_rootContainer = rootBuilder.Build();
_containerA = _rootContainer.BeginLifetimeScope(

View File

@@ -43,11 +43,10 @@ namespace Orchard.Environment {
workLifetime.Resolve<WorkContextProperty<HttpContextBase>>().Value = httpContext;
var events = workLifetime.Resolve<IEnumerable<IWorkContextEvents>>();
var logger = workLifetime.Resolve<ILogger>(new TypedParameter(typeof(Type), typeof(HttpContextScopeImplementation)));
events.Invoke(e => e.Started(), logger);
events.Invoke(e => e.Started(), NullLogger.Instance);
return new HttpContextScopeImplementation(
logger,
events,
workLifetime,
httpContext,
_workContextKey);
@@ -62,11 +61,10 @@ namespace Orchard.Environment {
var workLifetime = _lifetimeScope.BeginLifetimeScope("work");
var events = workLifetime.Resolve<IEnumerable<IWorkContextEvents>>();
var logger = workLifetime.Resolve<ILogger>(new TypedParameter(typeof(Type), typeof(ThreadStaticScopeImplementation)));
events.Invoke(e => e.Started(), logger);
events.Invoke(e => e.Started(), NullLogger.Instance);
return new ThreadStaticScopeImplementation(
logger,
events,
workLifetime,
EnsureThreadStaticContexts(),
_workContextKey);
@@ -81,13 +79,12 @@ namespace Orchard.Environment {
readonly WorkContext _workContext;
readonly Action _disposer;
public HttpContextScopeImplementation(ILogger logger, ILifetimeScope lifetimeScope, HttpContextBase httpContext, object workContextKey) {
public HttpContextScopeImplementation(IEnumerable<IWorkContextEvents> events, ILifetimeScope lifetimeScope, HttpContextBase httpContext, object workContextKey) {
_workContext = lifetimeScope.Resolve<WorkContext>();
httpContext.Items[workContextKey] = _workContext;
_disposer = () => {
var events = lifetimeScope.Resolve<IEnumerable<IWorkContextEvents>>();
events.Invoke(e => e.Finished(), logger);
events.Invoke(e => e.Finished(), NullLogger.Instance);
httpContext.Items.Remove(workContextKey);
lifetimeScope.Dispose();
@@ -115,13 +112,12 @@ namespace Orchard.Environment {
readonly WorkContext _workContext;
readonly Action _disposer;
public ThreadStaticScopeImplementation(ILogger logger, ILifetimeScope lifetimeScope, ConcurrentDictionary<object, WorkContext> contexts, object workContextKey) {
public ThreadStaticScopeImplementation(IEnumerable<IWorkContextEvents> events, ILifetimeScope lifetimeScope, ConcurrentDictionary<object, WorkContext> contexts, object workContextKey) {
_workContext = lifetimeScope.Resolve<WorkContext>();
contexts.AddOrUpdate(workContextKey, _workContext, (a, b) => _workContext);
_disposer = () => {
var events = lifetimeScope.Resolve<IEnumerable<IWorkContextEvents>>();
events.Invoke(e => e.Finished(), logger);
events.Invoke(e => e.Finished(), NullLogger.Instance);
WorkContext removedContext;
contexts.TryRemove(workContextKey, out removedContext);