From c7e0784b13ecebe5bc8f7bd8a4bb47107792a843 Mon Sep 17 00:00:00 2001 From: Piotr Szmyd Date: Fri, 5 Apr 2013 03:53:35 +0200 Subject: [PATCH] Further work on IWorkContextEvents. Swallowing all non-fatal exceptions. Events should be resolved once per context. --HG-- branch : 1.x --- .../DefaultWorkContextAccessorTests.cs | 5 ----- .../DefaultShellContextFactoryTests.cs | 7 +------ .../State/DefaultProcessingEngineTests.cs | 5 ----- .../Mvc/Routes/ShellRouteTests.cs | 6 +----- .../Environment/WorkContextAccessor.cs | 20 ++++++++----------- 5 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/Orchard.Tests/Environment/DefaultWorkContextAccessorTests.cs b/src/Orchard.Tests/Environment/DefaultWorkContextAccessorTests.cs index 3a58a5df5..e70ac0c2e 100644 --- a/src/Orchard.Tests/Environment/DefaultWorkContextAccessorTests.cs +++ b/src/Orchard.Tests/Environment/DefaultWorkContextAccessorTests.cs @@ -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().As(); - builder.RegisterModule(new LoggingModule()); - var stubFactory = new LoggingModuleTests.StubFactory(); - builder.RegisterInstance(stubFactory).As(); builder.RegisterAutoMocking(); } diff --git a/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs b/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs index 421bf0e37..b89e545ea 100644 --- a/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs +++ b/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs @@ -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().As(); builder.RegisterModule(new WorkContextModule()); builder.RegisterType().As(); - builder.RegisterModule(new LoggingModule()); - var stubFactory = new LoggingModuleTests.StubFactory(); - builder.RegisterInstance(stubFactory).As(); - builder.RegisterAutoMocking(MockBehavior.Strict); + builder.RegisterAutoMocking(Moq.MockBehavior.Strict); _container = builder.Build(); } diff --git a/src/Orchard.Tests/Environment/State/DefaultProcessingEngineTests.cs b/src/Orchard.Tests/Environment/State/DefaultProcessingEngineTests.cs index 60dabf2eb..b3b1a009b 100644 --- a/src/Orchard.Tests/Environment/State/DefaultProcessingEngineTests.cs +++ b/src/Orchard.Tests/Environment/State/DefaultProcessingEngineTests.cs @@ -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().As(); builder.RegisterModule(new WorkContextModule()); builder.RegisterType().As(); - builder.RegisterModule(new LoggingModule()); - var stubFactory = new LoggingModuleTests.StubFactory(); - builder.RegisterInstance(stubFactory).As(); builder.RegisterAutoMocking(); _container = builder.Build(); diff --git a/src/Orchard.Tests/Mvc/Routes/ShellRouteTests.cs b/src/Orchard.Tests/Mvc/Routes/ShellRouteTests.cs index 67feb27d2..75fec6f72 100644 --- a/src/Orchard.Tests/Mvc/Routes/ShellRouteTests.cs +++ b/src/Orchard.Tests/Mvc/Routes/ShellRouteTests.cs @@ -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().As(); rootBuilder.RegisterType().As(); rootBuilder.RegisterType().As(); - rootBuilder.RegisterModule(new LoggingModule()); - var stubFactory = new LoggingModuleTests.StubFactory(); - rootBuilder.RegisterInstance(stubFactory).As(); + _rootContainer = rootBuilder.Build(); _containerA = _rootContainer.BeginLifetimeScope( diff --git a/src/Orchard/Environment/WorkContextAccessor.cs b/src/Orchard/Environment/WorkContextAccessor.cs index 6f5e5b17f..a1216f644 100644 --- a/src/Orchard/Environment/WorkContextAccessor.cs +++ b/src/Orchard/Environment/WorkContextAccessor.cs @@ -43,11 +43,10 @@ namespace Orchard.Environment { workLifetime.Resolve>().Value = httpContext; var events = workLifetime.Resolve>(); - var logger = workLifetime.Resolve(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>(); - var logger = workLifetime.Resolve(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 events, ILifetimeScope lifetimeScope, HttpContextBase httpContext, object workContextKey) { _workContext = lifetimeScope.Resolve(); httpContext.Items[workContextKey] = _workContext; _disposer = () => { - var events = lifetimeScope.Resolve>(); - 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 contexts, object workContextKey) { + public ThreadStaticScopeImplementation(IEnumerable events, ILifetimeScope lifetimeScope, ConcurrentDictionary contexts, object workContextKey) { _workContext = lifetimeScope.Resolve(); contexts.AddOrUpdate(workContextKey, _workContext, (a, b) => _workContext); _disposer = () => { - var events = lifetimeScope.Resolve>(); - events.Invoke(e => e.Finished(), logger); + events.Invoke(e => e.Finished(), NullLogger.Instance); WorkContext removedContext; contexts.TryRemove(workContextKey, out removedContext);