diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 13112eb63c..6e09f7eb2b 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -40,22 +40,16 @@ namespace Umbraco.Core protected PluginManager PluginManager { get; private set; } private IServiceContainer _appStartupEvtContainer; - private bool _isInitialized = false; - private bool _isStarted = false; - private bool _isComplete = false; + private bool _isInitialized; + private bool _isStarted; + private bool _isComplete; private readonly UmbracoApplicationBase _umbracoApplication; protected ApplicationContext ApplicationContext { get; private set; } protected CacheHelper ApplicationCache { get; private set; } - protected UmbracoApplicationBase UmbracoApplication - { - get { return _umbracoApplication; } - } + protected UmbracoApplicationBase UmbracoApplication => _umbracoApplication; - protected ServiceContainer Container - { - get { return _umbracoApplication.Container; } - } + protected ServiceContainer Container => Current.Container; // fixme kill protected IServiceProvider ServiceProvider { get; private set; } @@ -78,13 +72,16 @@ namespace Umbraco.Core if (_isInitialized) throw new InvalidOperationException("The boot manager has already been initialized"); + // the logger has been created by UmbracoApplicationBase + // fixme why not the profiling logger etc?! OR have them all created by the boot manager? //Create logger/profiler, and their resolvers, these are special resolvers that can be resolved before frozen so we can start logging - LoggerResolver.Current = new LoggerResolver(_umbracoApplication.Logger) { CanResolveBeforeFrozen = true }; - var profiler = CreateProfiler(); - ProfilerResolver.Current = new ProfilerResolver(profiler) { CanResolveBeforeFrozen = true }; - ProfilingLogger = new ProfilingLogger(_umbracoApplication.Logger, profiler); + var logger = Current.Logger; - ProfilingLogger = ProfilingLogger?? new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler); + var profiler = CreateProfiler(); + Container.RegisterInstance(profiler); // fixme - re-registered?! + //ProfilerResolver.Current = new ProfilerResolver(profiler) { CanResolveBeforeFrozen = true }; + + ProfilingLogger = new ProfilingLogger(logger, profiler); ApplicationCache = CreateApplicationCache(); @@ -154,7 +151,6 @@ namespace Umbraco.Core internal virtual void ConfigureCoreServices(ServiceContainer container) { //Logging - container.RegisterInstance(_umbracoApplication.Logger); container.RegisterInstance(ProfilingLogger.Profiler); container.RegisterInstance(ProfilingLogger); @@ -457,7 +453,7 @@ namespace Umbraco.Core .Append(PluginManager.ResolveTypes()); // use the new DefaultShortStringHelper - Container.RegisterSingleton(factory + Container.RegisterSingleton(factory => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance()))); UrlSegmentProviderCollectionBuilder.Register(Container) diff --git a/src/Umbraco.Core/DependencyInjection/Current.cs b/src/Umbraco.Core/DependencyInjection/Current.cs index 90be5815ee..5b0f179bf1 100644 --- a/src/Umbraco.Core/DependencyInjection/Current.cs +++ b/src/Umbraco.Core/DependencyInjection/Current.cs @@ -2,8 +2,8 @@ using LightInject; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Dictionary; +using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Strings; @@ -40,7 +40,11 @@ namespace Umbraco.Core.DependencyInjection internal static void Reset() { _container = null; + _shortStringHelper = null; + _logger = null; + _profiler = null; + Resetted?.Invoke(null, EventArgs.Empty); } @@ -81,25 +85,28 @@ namespace Umbraco.Core.DependencyInjection public static ICultureDictionaryFactory CultureDictionaryFactory => Container.GetInstance(); + // fixme - refactor + // we don't want Umbraco to die because the container has not been properly initialized, + // for some too-important things such as IShortStringHelper or loggers, so if it's not + // registered we setup a default one. We should really refactor our tests so that it does + // not happen, but hey... + private static IShortStringHelper _shortStringHelper; public static IShortStringHelper ShortStringHelper - { - get - { - // fixme - refactor - // we don't want Umbraco to die because the resolver hasn't been initialized - // as the ShortStringHelper is too important, so as long as it's not there - // already, we use a default one. That should never happen, but... in can, in - // some tests - we should really cleanup our tests and get rid of this! + => _shortStringHelper ?? (_shortStringHelper = _container?.TryGetInstance() + ?? new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(UmbracoConfig.For.UmbracoSettings()))); - if (_shortStringHelper != null) return _shortStringHelper; - var reg = HasContainer ? Container.GetAvailableService() : null; - return _shortStringHelper = reg == null - ? new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(UmbracoConfig.For.UmbracoSettings())) - : Container.GetInstance(); - } - } + private static ILogger _logger; + private static IProfiler _profiler; + + public static ILogger Logger + => _logger ?? (_logger = _container?.TryGetInstance() + ?? new DebugDiagnosticsLogger()); + + public static IProfiler Profiler + => _profiler ?? (_profiler = _container?.TryGetInstance() + ?? new LogProfiler(Logger)); #endregion } diff --git a/src/Umbraco.Core/DisposableTimer.cs b/src/Umbraco.Core/DisposableTimer.cs index 79d33c2826..5b365c5ec3 100644 --- a/src/Umbraco.Core/DisposableTimer.cs +++ b/src/Umbraco.Core/DisposableTimer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Web; +using Umbraco.Core.DependencyInjection; using Umbraco.Core.Logging; namespace Umbraco.Core @@ -113,9 +114,9 @@ namespace Umbraco.Core public static DisposableTimer TraceDuration(Type loggerType, Func startMessage, Func completeMessage) { return new DisposableTimer( - LoggerResolver.Current.Logger, + Current.Logger, LogType.Info, - ProfilerResolver.HasCurrent ? ProfilerResolver.Current.Profiler : null, + Current.Profiler, loggerType, startMessage(), completeMessage()); @@ -157,9 +158,9 @@ namespace Umbraco.Core public static DisposableTimer TraceDuration(Type loggerType, string startMessage, string completeMessage) { return new DisposableTimer( - LoggerResolver.Current.Logger, + Current.Logger, LogType.Info, - ProfilerResolver.HasCurrent ? ProfilerResolver.Current.Profiler : null, + Current.Profiler, loggerType, startMessage, completeMessage); @@ -212,9 +213,9 @@ namespace Umbraco.Core public static DisposableTimer DebugDuration(Type loggerType, string startMessage, string completeMessage) { return new DisposableTimer( - LoggerResolver.Current.Logger, + Current.Logger, LogType.Debug, - ProfilerResolver.HasCurrent ? ProfilerResolver.Current.Profiler : null, + Current.Profiler, loggerType, startMessage, completeMessage); @@ -225,9 +226,9 @@ namespace Umbraco.Core public static DisposableTimer DebugDuration(Type loggerType, Func startMessage, Func completeMessage) { return new DisposableTimer( - LoggerResolver.Current.Logger, + Current.Logger, LogType.Debug, - ProfilerResolver.HasCurrent ? ProfilerResolver.Current.Profiler : null, + Current.Profiler, loggerType, startMessage(), completeMessage()); diff --git a/src/Umbraco.Core/Logging/LogHelper.cs b/src/Umbraco.Core/Logging/LogHelper.cs index c789beb489..e45beca6b4 100644 --- a/src/Umbraco.Core/Logging/LogHelper.cs +++ b/src/Umbraco.Core/Logging/LogHelper.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using System.Web; using log4net; +using Umbraco.Core.DependencyInjection; namespace Umbraco.Core.Logging { @@ -10,7 +11,7 @@ namespace Umbraco.Core.Logging /// Used for logging, ILogger should be used instead but this is available for static access to logging /// /// - /// this wraps ILogger + /// this wraps ILogger /// public static class LogHelper { @@ -23,24 +24,21 @@ namespace Umbraco.Core.Logging /// public static void Error(string message, Exception exception) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Error(message, exception); + Current.Logger.Error(message, exception); } public static void Error(Type callingType, string message, Exception exception) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Error(callingType, message, exception); + Current.Logger.Error(callingType, message, exception); } #endregion - #region Warn + #region Warn public static void Warn(Type callingType, string message, params Func[] formatItems) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Warn(callingType, message, formatItems); + Current.Logger.Warn(callingType, message, formatItems); } [Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")] @@ -54,8 +52,7 @@ namespace Umbraco.Core.Logging HttpContext.Current.Trace.Warn(callingType.Name, string.Format(message, formatItems.Select(x => x.Invoke()).ToArray())); } - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Warn(callingType, message, formatItems); + Current.Logger.Warn(callingType, message, formatItems); } @@ -75,13 +72,12 @@ namespace Umbraco.Core.Logging { HttpContext.Current.Trace.Warn( callingType.Name, - string.Format(message, formatItems.Select(x => x.Invoke()).ToArray()), + string.Format(message, formatItems.Select(x => x.Invoke()).ToArray()), e); } - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.WarnWithException(callingType, message, e, formatItems); - } + Current.Logger.WarnWithException(callingType, message, e, formatItems); + } /// /// Adds a warn log @@ -109,7 +105,7 @@ namespace Umbraco.Core.Logging public static void WarnWithException(string message, bool showHttpTrace, Exception e, params Func[] formatItems) { WarnWithException(typeof(T), message, showHttpTrace, e, formatItems); - } + } #endregion @@ -132,8 +128,7 @@ namespace Umbraco.Core.Logging /// public static void Info(Type callingType, Func generateMessage) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Info(callingType, generateMessage); + Current.Logger.Info(callingType, generateMessage); } /// @@ -144,8 +139,7 @@ namespace Umbraco.Core.Logging /// The format items. public static void Info(Type type, string generateMessageFormat, params Func[] formatItems) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Info(type, generateMessageFormat, formatItems); + Current.Logger.Info(type, generateMessageFormat, formatItems); } /// @@ -158,10 +152,12 @@ namespace Umbraco.Core.Logging public static void Info(string generateMessageFormat, params Func[] formatItems) { Info(typeof(T), generateMessageFormat, formatItems); - } + } + #endregion #region Debug + /// /// Debugs a message, only generating the message if tracing is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled. /// @@ -180,8 +176,7 @@ namespace Umbraco.Core.Logging /// public static void Debug(Type callingType, Func generateMessage) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Debug(callingType, generateMessage); + Current.Logger.Debug(callingType, generateMessage); } /// @@ -192,8 +187,7 @@ namespace Umbraco.Core.Logging /// The format items. public static void Debug(Type type, string generateMessageFormat, params Func[] formatItems) { - if (LoggerResolver.HasCurrent == false || LoggerResolver.Current.HasValue == false) return; - LoggerResolver.Current.Logger.Debug(type, generateMessageFormat, formatItems); + Current.Logger.Debug(type, generateMessageFormat, formatItems); } /// @@ -223,12 +217,11 @@ namespace Umbraco.Core.Logging { HttpContext.Current.Trace.Write( typeof(T).Name, - string.Format(generateMessageFormat, formatItems.Select(x => x()).ToArray())); - } + string.Format(generateMessageFormat, formatItems.Select(x => x()).ToArray())); + } Debug(typeof(T), generateMessageFormat, formatItems); } #endregion - } } diff --git a/src/Umbraco.Core/Logging/LoggerResolver.cs b/src/Umbraco.Core/Logging/LoggerResolver.cs deleted file mode 100644 index eb27639df0..0000000000 --- a/src/Umbraco.Core/Logging/LoggerResolver.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Umbraco.Core.ObjectResolution; - -namespace Umbraco.Core.Logging -{ - /// - /// The logger resolver - /// - /// - /// NOTE: This is a 'special' resolver in that it gets initialized before most other things, it cannot use IoC so it cannot implement ContainerObjectResolverBase - /// - public sealed class LoggerResolver : SingleObjectResolverBase - { - public LoggerResolver(ILogger logger) - : base(logger) - { - - } - - /// - /// Gets the current logger - /// - public ILogger Logger - { - get { return Value; } - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Logging/OwinLoggerFactory.cs b/src/Umbraco.Core/Logging/OwinLoggerFactory.cs index c60ecd1f04..101efd4a16 100644 --- a/src/Umbraco.Core/Logging/OwinLoggerFactory.cs +++ b/src/Umbraco.Core/Logging/OwinLoggerFactory.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.Owin.Logging; +using Umbraco.Core.DependencyInjection; namespace Umbraco.Core.Logging { @@ -16,9 +13,7 @@ namespace Umbraco.Core.Logging /// public Microsoft.Owin.Logging.ILogger Create(string name) { - return new OwinLogger( - LoggerResolver.HasCurrent ? LoggerResolver.Current.Logger : new DebugDiagnosticsLogger(), - new Lazy(() => Type.GetType(name) ?? typeof (OwinLogger))); + return new OwinLogger(Current.Logger, new Lazy(() => Type.GetType(name) ?? typeof (OwinLogger))); } } } diff --git a/src/Umbraco.Core/Logging/ProfilerResolver.cs b/src/Umbraco.Core/Logging/ProfilerResolver.cs deleted file mode 100644 index e7be06450d..0000000000 --- a/src/Umbraco.Core/Logging/ProfilerResolver.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Umbraco.Core.ObjectResolution; - -namespace Umbraco.Core.Logging -{ - /// - /// A resolver exposing the current profiler - /// - /// - /// NOTE: This is a 'special' resolver in that it gets initialized before most other things, it cannot use IoC so it cannot implement ContainerObjectResolverBase - /// - internal class ProfilerResolver : SingleObjectResolverBase - { - /// - /// Constructor - /// - /// - public ProfilerResolver(IProfiler profiler) - : base(profiler) - { - - } - - /// - /// Method allowing to change the profiler during startup - /// - /// - internal void SetProfiler(IProfiler profiler) - { - Value = profiler; - } - - /// - /// Gets the current profiler - /// - public IProfiler Profiler - { - get { return Value; } - } - - - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Manifest/ManifestWatcher.cs b/src/Umbraco.Core/Manifest/ManifestWatcher.cs index 24dff148be..879e096e83 100644 --- a/src/Umbraco.Core/Manifest/ManifestWatcher.cs +++ b/src/Umbraco.Core/Manifest/ManifestWatcher.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Web; using Umbraco.Core.Logging; @@ -8,64 +9,62 @@ namespace Umbraco.Core.Manifest { internal class ManifestWatcher : DisposableObject { + private static readonly object Locker = new object(); + private static volatile bool _isRestarting; + private readonly ILogger _logger; private readonly List _fws = new List(); - private static volatile bool _isRestarting = false; - private static readonly object Locker = new object(); public ManifestWatcher(ILogger logger) { - if (logger == null) throw new ArgumentNullException("logger"); + if (logger == null) throw new ArgumentNullException(nameof(logger)); _logger = logger; } public void Start(params string[] packageFolders) { - foreach (var packageFolder in packageFolders) + foreach (var packageFolder in packageFolders.Where(IsWatchable)) { - if (Directory.Exists(packageFolder) && File.Exists(Path.Combine(packageFolder, "package.manifest"))) + // for some reason *.manifest doesn't work + var fsw = new FileSystemWatcher(packageFolder, "*package.*") { - //NOTE: for some reason *.manifest doesn't work! - var fsw = new FileSystemWatcher(packageFolder, "*package.*") - { - IncludeSubdirectories = false, - NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite - }; - _fws.Add(fsw); - fsw.Changed += FswChanged; - fsw.EnableRaisingEvents = true; - } + IncludeSubdirectories = false, + NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite + }; + + _fws.Add(fsw); + + fsw.Changed += FswChanged; + fsw.EnableRaisingEvents = true; } } - void FswChanged(object sender, FileSystemEventArgs e) + private static bool IsWatchable(string folder) { - if (e.Name.InvariantContains("package.manifest")) - { - //Ensure the app is not restarted multiple times for multiple saving during the same app domain execution - if (_isRestarting == false) - { - lock (Locker) - { - if (_isRestarting == false) - { - _isRestarting = true; + return Directory.Exists(folder) && File.Exists(Path.Combine(folder, "package.manifest")); + } - _logger.Info("manifest has changed, app pool is restarting (" + e.FullPath + ")"); - HttpRuntime.UnloadAppDomain(); - Dispose(); - } - } - } + private void FswChanged(object sender, FileSystemEventArgs e) + { + if (e.Name.InvariantContains("package.manifest") == false) return; + + // ensure the app is not restarted multiple times for multiple + // savings during the same app domain execution - restart once + lock (Locker) + { + if (_isRestarting) return; + + _isRestarting = true; + _logger.Info("manifest has changed, app pool is restarting (" + e.FullPath + ")"); + HttpRuntime.UnloadAppDomain(); + Dispose(); // uh? if the app restarts then this should be disposed anyways? } } protected override void DisposeResources() { foreach (var fw in _fws) - { fw.Dispose(); - } } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Plugins/PluginManager.cs b/src/Umbraco.Core/Plugins/PluginManager.cs index d1f4d81cae..09c219a0fb 100644 --- a/src/Umbraco.Core/Plugins/PluginManager.cs +++ b/src/Umbraco.Core/Plugins/PluginManager.cs @@ -110,15 +110,14 @@ namespace Umbraco.Core.Plugins return LazyInitializer.EnsureInitialized(ref _instance, ref _hasInstance, ref _instanceLocker, () => { var appctx = ApplicationContext.Current; - var cacheProvider = appctx == null + var cacheProvider = appctx == null // fixme - should Current have an ApplicationCache? ? new NullCacheProvider() : appctx.ApplicationCache.RuntimeCache; ProfilingLogger profilingLogger; if (appctx == null) { - var logger = LoggerResolver.HasCurrent ? LoggerResolver.Current.Logger : new DebugDiagnosticsLogger(); - var profiler = ProfilerResolver.HasCurrent ? ProfilerResolver.Current.Profiler : new LogProfiler(logger); - profilingLogger = new ProfilingLogger(logger, profiler); + // fixme - should Current have a ProfilingLogger? + profilingLogger = new ProfilingLogger(DependencyInjection.Current.Logger, DependencyInjection.Current.Profiler); } else { diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 52fcca55e5..d2d3dc456d 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -489,7 +489,6 @@ - @@ -1032,7 +1031,6 @@ - diff --git a/src/Umbraco.Core/UmbracoApplicationBase.cs b/src/Umbraco.Core/UmbracoApplicationBase.cs index e306e076d3..fe0a13809c 100644 --- a/src/Umbraco.Core/UmbracoApplicationBase.cs +++ b/src/Umbraco.Core/UmbracoApplicationBase.cs @@ -20,28 +20,57 @@ namespace Umbraco.Core /// public abstract class UmbracoApplicationBase : HttpApplication { + /// + /// Gets a boot manager. + /// + protected abstract IBootManager GetBootManager(); /// - /// Umbraco application's IoC container + /// Gets a logger. /// - internal ServiceContainer Container { get; private set; } - - private ILogger _logger; - - /// - /// Constructor - /// - protected UmbracoApplicationBase() + protected virtual ILogger GetLogger() { - // beware! this code can run more that once - // so it is NOT the right place to initialize global stuff such as the container - // - // however, it is OK to initialize app-local stuff - - if (Current.HasContainer) - Container = Current.Container; + return Logger.CreateWithDefaultLog4NetConfiguration(); } + /// + /// Boots up the Umbraco application. + /// + internal void StartApplication(object sender, EventArgs e) + { + // create the container for the application, and configure. + // the boot manager is responsible for registrations + var container = new ServiceContainer(); + container.ConfigureUmbracoCore(); // also sets Current.Container + + // register the essential stuff, + // ie the global application logger + // (profiler etc depend on boot manager) + var logger = GetLogger(); + container.RegisterInstance(logger); + + // take care of unhandled exceptions - there is nothing we can do to + // prevent the entire w3wp process to go down but at least we can try + // and log the exception + AppDomain.CurrentDomain.UnhandledException += (_, args) => + { + var exception = (Exception)args.ExceptionObject; + var isTerminating = args.IsTerminating; // always true? + + var msg = "Unhandled exception in AppDomain"; + if (isTerminating) msg += " (terminating)"; + logger.Error(msg, exception); + }; + + // boot + GetBootManager() + .Initialize() + .Startup(appContext => OnApplicationStarting(sender, e)) + .Complete(appContext => OnApplicationStarted(sender, e)); + } + + #region Events + public event EventHandler ApplicationStarting; public event EventHandler ApplicationStarted; @@ -49,43 +78,13 @@ namespace Umbraco.Core /// Called when the HttpApplication.Init() is fired, allows developers to subscribe to the HttpApplication events /// /// - /// Needs to be static otherwise null refs occur - though I don't know why + /// Needs to be static otherwise null refs occur - though I don't know why FIXME wtf? /// public static event EventHandler ApplicationInit; public static event EventHandler ApplicationError; public static event EventHandler ApplicationEnd; - /// - /// Boots up the Umbraco application - /// - internal void StartApplication(object sender, EventArgs e) - { - // create the container for the application, and configure. - // the boot managers are responsible for registrations - Container = new ServiceContainer(); - Container.ConfigureUmbracoCore(); - - //take care of unhandled exceptions - there is nothing we can do to - // prevent the entire w3wp process to go down but at least we can try - // and log the exception - AppDomain.CurrentDomain.UnhandledException += (_, args) => - { - var exception = (Exception) args.ExceptionObject; - var isTerminating = args.IsTerminating; // always true? - - var msg = "Unhandled exception in AppDomain"; - if (isTerminating) msg += " (terminating)"; - LogHelper.Error(msg, exception); - }; - - //boot up the application - GetBootManager() - .Initialize() - .Startup(appContext => OnApplicationStarting(sender, e)) - .Complete(appContext => OnApplicationStarted(sender, e)); - } - /// /// Initializes the Umbraco application /// @@ -118,19 +117,15 @@ namespace Umbraco.Core /// protected virtual void OnApplicationStarting(object sender, EventArgs e) { - if (ApplicationStarting != null) + try { - try - { - ApplicationStarting(sender, e); - } - catch (Exception ex) - { - LogHelper.Error("An error occurred in an ApplicationStarting event handler", ex); - throw; - } + ApplicationStarting?.Invoke(sender, e); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred in an ApplicationStarting event handler", ex); + throw; } - } /// @@ -140,17 +135,14 @@ namespace Umbraco.Core /// protected virtual void OnApplicationStarted(object sender, EventArgs e) { - if (ApplicationStarted != null) + try { - try - { - ApplicationStarted(sender, e); - } - catch (Exception ex) - { - LogHelper.Error("An error occurred in an ApplicationStarted event handler", ex); - throw; - } + ApplicationStarted?.Invoke(sender, e); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred in an ApplicationStarted event handler", ex); + throw; } } @@ -161,17 +153,14 @@ namespace Umbraco.Core /// private void OnApplicationInit(object sender, EventArgs e) { - if (ApplicationInit != null) + try { - try - { - ApplicationInit(sender, e); - } - catch (Exception ex) - { - LogHelper.Error("An error occurred in an ApplicationInit event handler", ex); - throw; - } + ApplicationInit?.Invoke(sender, e); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred in an ApplicationInit event handler", ex); + throw; } } @@ -182,8 +171,7 @@ namespace Umbraco.Core /// protected virtual void OnApplicationError(object sender, EventArgs e) { - var handler = ApplicationError; - if (handler != null) handler(this, EventArgs.Empty); + ApplicationError?.Invoke(this, EventArgs.Empty); } protected void Application_Error(object sender, EventArgs e) @@ -199,7 +187,7 @@ namespace Umbraco.Core return; } - Logger.Error("An unhandled exception occurred", exc); + Current.Logger.Error("An unhandled exception occurred", exc); OnApplicationError(sender, e); } @@ -211,8 +199,7 @@ namespace Umbraco.Core /// protected virtual void OnApplicationEnd(object sender, EventArgs e) { - var handler = ApplicationEnd; - if (handler != null) handler(this, EventArgs.Empty); + ApplicationEnd?.Invoke(this, EventArgs.Empty); } protected void Application_End(object sender, EventArgs e) @@ -248,34 +235,22 @@ namespace Umbraco.Core runtime, null); - var shutdownMsg = string.Format("{0}\r\n\r\n_shutDownMessage={1}\r\n\r\n_shutDownStack={2}", - HostingEnvironment.ShutdownReason, - shutDownMessage, - shutDownStack); + var shutdownMsg = $"{HostingEnvironment.ShutdownReason}\r\n\r\n_shutDownMessage={shutDownMessage}\r\n\r\n_shutDownStack={shutDownStack}"; - Logger.Info("Application shutdown. Details: " + shutdownMsg); + Current.Logger.Info("Application shutdown. Details: " + shutdownMsg); } catch (Exception) { //if for some reason that fails, then log the normal output - Logger.Info("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason); + Current.Logger.Info("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason); } } OnApplicationEnd(sender, e); - //Last thing to do is shutdown log4net + // last thing to do is shutdown log4net LogManager.Shutdown(); } - protected abstract IBootManager GetBootManager(); - - /// - /// Returns the logger instance for the application - this will be used throughout the entire app - /// - public virtual ILogger Logger - { - get { return _logger ?? (_logger = Logging.Logger.CreateWithDefaultLog4NetConfiguration()); } - } - + #endregion } } diff --git a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs index 782bd811bf..49bf42d9e0 100644 --- a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs +++ b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs @@ -29,8 +29,10 @@ namespace Umbraco.Tests.BootManagers public override void TearDown() { base.TearDown(); + ResolverCollection.ResetAll(); TestApplicationEventHandler.Reset(); + Resolution.Reset(); Current.Reset(); } @@ -41,19 +43,16 @@ namespace Umbraco.Tests.BootManagers /// public class TestApp : UmbracoApplicationBase { + private readonly ILogger _logger = Mock.Of(); + protected override IBootManager GetBootManager() { - return new TestBootManager(this, new ProfilingLogger(Mock.Of(), Mock.Of())); + return new TestBootManager(this, new ProfilingLogger(_logger, Mock.Of())); } - private ILogger _logger; - - /// - /// Returns the logger instance for the application - this will be used throughout the entire app - /// - public override ILogger Logger + protected override ILogger GetLogger() { - get { return _logger ?? (_logger = Mock.Of()); } + return _logger; } } @@ -64,12 +63,12 @@ namespace Umbraco.Tests.BootManagers { public TestBootManager(UmbracoApplicationBase umbracoApplication, ProfilingLogger logger) : base(umbracoApplication, logger) - { - } + { } internal override void ConfigureCoreServices(ServiceContainer container) { base.ConfigureCoreServices(container); + container.Register(factory => SettingsForTests.GetDefault()); container.Register(factory => new DatabaseContext( factory.GetInstance(), diff --git a/src/Umbraco.Tests/MockTests.cs b/src/Umbraco.Tests/MockTests.cs index f42f135dee..6858c615f7 100644 --- a/src/Umbraco.Tests/MockTests.cs +++ b/src/Umbraco.Tests/MockTests.cs @@ -23,6 +23,7 @@ using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests { @@ -32,13 +33,13 @@ namespace Umbraco.Tests [SetUp] public void Setup() { - Umbraco.Web.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); + Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); } [TearDown] public void TearDown() { - Umbraco.Web.Current.UmbracoContextAccessor = null; + Current.Reset(); } [Test] @@ -77,10 +78,10 @@ namespace Umbraco.Tests TestObjects.GetServiceContextMock(), CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(logger, Mock.Of())); - + Assert.Pass(); } - + [Test] public void Can_Assign_App_Context_Singleton() { @@ -96,7 +97,7 @@ namespace Umbraco.Tests { ApplicationContext.EnsureContext( new ApplicationContext( - CacheHelper.CreateDisabledCacheHelper(), + CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())), true); var appCtx = new ApplicationContext( @@ -120,7 +121,7 @@ namespace Umbraco.Tests Mock.Of(), Enumerable.Empty(), true); - + Assert.AreEqual(umbCtx, UmbracoContext.Current); } diff --git a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs index eef43c0f10..d138f3f72f 100644 --- a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs +++ b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs @@ -10,12 +10,10 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories; -using Umbraco.Core.Persistence.UnitOfWork; -using Umbraco.Core.Profiling; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests.Services { @@ -32,11 +30,16 @@ namespace Umbraco.Tests.Services protected override void FreezeResolution() { - ProfilerResolver.Current = new ProfilerResolver(new TestProfiler()); - + Container.Register(); base.FreezeResolution(); } + [Test] + public void Profiler() + { + Assert.IsInstanceOf(Current.Profiler); + } + [Test] public void Retrieving_All_Content_In_Site() { diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 329fbbbec6..98f49a8b8c 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -272,18 +272,6 @@ namespace Umbraco.Tests.TestHelpers var cache = new NullCacheProvider(); var enableRepositoryEvents = behavior != null && behavior.EnableRepositoryEvents; - if (enableRepositoryEvents && LoggerResolver.HasCurrent == false) - { - // XmlStore wants one if handling events - LoggerResolver.Current = new LoggerResolver(Mock.Of()) - { - CanResolveBeforeFrozen = true - }; - ProfilerResolver.Current = new ProfilerResolver(new LogProfiler(Mock.Of())) - { - CanResolveBeforeFrozen = true - }; - } ContentTypesCache = new PublishedContentTypeCache( ApplicationContext.Services.ContentTypeService, diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs index 6bbf0644c1..4848ca6e1b 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs @@ -1,4 +1,6 @@ using NUnit.Framework; +using Umbraco.Core.DependencyInjection; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests.TestHelpers { @@ -14,14 +16,14 @@ namespace Umbraco.Tests.TestHelpers public virtual void Initialize() { SettingsForTests.Reset(); - Umbraco.Web.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); + Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); } [TearDown] public virtual void TearDown() { SettingsForTests.Reset(); - Umbraco.Web.Current.UmbracoContextAccessor = null; + Current.Reset(); } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index c264076d9a..3c90bccb67 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -27,13 +27,13 @@ namespace Umbraco.Tests.Web.Mvc [SetUp] public void SetUp() { - Umbraco.Web.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); + Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); } [TearDown] public void TearDown() { - Umbraco.Web.Current.UmbracoContextAccessor = null; + Current.Reset(); } private MethodInfo GetRenderMvcControllerIndexMethodFromCurrentType(Type currType) diff --git a/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs index 41c133b6b7..9c16d6dbb6 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Models; using Umbraco.Web.Mvc; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests.Web.Mvc { @@ -18,13 +19,13 @@ namespace Umbraco.Tests.Web.Mvc [SetUp] public void SetUp() { - Umbraco.Web.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); + Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); } [TearDown] public void TearDown() { - Umbraco.Web.Current.UmbracoContextAccessor = null; + Current.Reset(); } [Test] diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index 040ddc0abb..4d4fbd4fb8 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -23,6 +23,7 @@ using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests.Web.Mvc { @@ -32,13 +33,13 @@ namespace Umbraco.Tests.Web.Mvc [SetUp] public void SetUp() { - Umbraco.Web.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); + Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); } [TearDown] public void TearDown() { - Umbraco.Web.Current.UmbracoContextAccessor = null; + Current.Reset(); } [Test] diff --git a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs index 5d6dfdf2e3..448742d3df 100644 --- a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs +++ b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs @@ -19,6 +19,7 @@ using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests.Web { @@ -28,7 +29,7 @@ namespace Umbraco.Tests.Web [TearDown] public void TearDown() { - Umbraco.Web.Current.UmbracoContextAccessor = null; + Current.Reset(); } [Test] diff --git a/src/Umbraco.Web/Current.cs b/src/Umbraco.Web/Current.cs index b306a3a6e5..063c762ada 100644 --- a/src/Umbraco.Web/Current.cs +++ b/src/Umbraco.Web/Current.cs @@ -4,6 +4,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Dictionary; using Umbraco.Core.Events; +using Umbraco.Core.Logging; using Umbraco.Core.Macros; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence.Migrations; @@ -65,7 +66,7 @@ namespace Umbraco.Web get { if (_facadeAccessor != null) return _facadeAccessor; - return (_facadeAccessor = Container.GetInstance()); + return _facadeAccessor = Container.GetInstance(); } set { _facadeAccessor = value; } // for tests } @@ -89,7 +90,7 @@ namespace Umbraco.Web get { if (_umbracoContextAccessor != null) return _umbracoContextAccessor; - return (_umbracoContextAccessor = Container.GetInstance()); + return _umbracoContextAccessor = Container.GetInstance(); } set { _umbracoContextAccessor = value; } // for tests } @@ -199,41 +200,33 @@ namespace Umbraco.Web // proxy Core for convenience - public static UrlSegmentProviderCollection UrlSegmentProviders - => Container.GetInstance(); + public static UrlSegmentProviderCollection UrlSegmentProviders => CoreCurrent.UrlSegmentProviders; - public static CacheRefresherCollection CacheRefreshers - => Container.GetInstance(); + public static CacheRefresherCollection CacheRefreshers => CoreCurrent.CacheRefreshers; - public static PropertyEditorCollection PropertyEditors - => Container.GetInstance(); + public static PropertyEditorCollection PropertyEditors => CoreCurrent.PropertyEditors; - public static ParameterEditorCollection ParameterEditors - => Container.GetInstance(); + public static ParameterEditorCollection ParameterEditors => CoreCurrent.ParameterEditors; - internal static ValidatorCollection Validators - => Container.GetInstance(); + internal static ValidatorCollection Validators => CoreCurrent.Validators; - internal static PackageActionCollection PackageActions - => Container.GetInstance(); + internal static PackageActionCollection PackageActions => CoreCurrent.PackageActions; - internal static PropertyValueConverterCollection PropertyValueConverters - => Container.GetInstance(); + internal static PropertyValueConverterCollection PropertyValueConverters => CoreCurrent.PropertyValueConverters; - internal static IPublishedContentModelFactory PublishedContentModelFactory - => Container.GetInstance(); + internal static IPublishedContentModelFactory PublishedContentModelFactory => CoreCurrent.PublishedContentModelFactory; - public static IServerMessenger ServerMessenger - => Container.GetInstance(); + public static IServerMessenger ServerMessenger => CoreCurrent.ServerMessenger; - public static IServerRegistrar ServerRegistrar - => Container.GetInstance(); + public static IServerRegistrar ServerRegistrar => CoreCurrent.ServerRegistrar; - public static ICultureDictionaryFactory CultureDictionaryFactory - => Container.GetInstance(); + public static ICultureDictionaryFactory CultureDictionaryFactory => CoreCurrent.CultureDictionaryFactory; - public static IShortStringHelper ShortStringHelper - => Container.GetInstance(); + public static IShortStringHelper ShortStringHelper => CoreCurrent.ShortStringHelper; + + public static ILogger Logger => CoreCurrent.Logger; + + public static IProfiler Profiler => CoreCurrent.Profiler; #endregion } diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 0741848827..acbcf18e79 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web /// public static IHtmlString RenderProfiler(this HtmlHelper helper) { - return new HtmlString(ProfilerResolver.Current.Profiler.Render()); + return new HtmlString(Current.Profiler.Render()); } /// diff --git a/src/Umbraco.Web/Mvc/ProfilingView.cs b/src/Umbraco.Web/Mvc/ProfilingView.cs index d0913a5259..c7a31a7829 100644 --- a/src/Umbraco.Web/Mvc/ProfilingView.cs +++ b/src/Umbraco.Web/Mvc/ProfilingView.cs @@ -1,6 +1,7 @@ using System.IO; using System.Web.Mvc; using Umbraco.Core.Logging; +using Umbraco.Web; namespace Umbraco.Core.Profiling { @@ -20,7 +21,7 @@ namespace Umbraco.Core.Profiling public void Render(ViewContext viewContext, TextWriter writer) { - using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.Render: {1}", _name, _viewPath))) + using (Current.Profiler.Step(string.Format("{0}.Render: {1}", _name, _viewPath))) { _inner.Render(viewContext, writer); } diff --git a/src/Umbraco.Web/Mvc/ProfilingViewEngine.cs b/src/Umbraco.Web/Mvc/ProfilingViewEngine.cs index 9b1f4e7528..27ec66805a 100644 --- a/src/Umbraco.Web/Mvc/ProfilingViewEngine.cs +++ b/src/Umbraco.Web/Mvc/ProfilingViewEngine.cs @@ -1,5 +1,6 @@ using System.Web.Mvc; using Umbraco.Core.Logging; +using Umbraco.Web; namespace Umbraco.Core.Profiling { @@ -16,7 +17,7 @@ namespace Umbraco.Core.Profiling public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { - using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindPartialView, {1}, {2}", _name, partialViewName, useCache))) + using (Current.Profiler.Step(string.Format("{0}.FindPartialView, {1}, {2}", _name, partialViewName, useCache))) { return WrapResult(Inner.FindPartialView(controllerContext, partialViewName, useCache)); } @@ -24,7 +25,7 @@ namespace Umbraco.Core.Profiling public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { - using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindView, {1}, {2}, {3}", _name, viewName, masterName, useCache))) + using (Current.Profiler.Step(string.Format("{0}.FindView, {1}, {2}, {3}", _name, viewName, masterName, useCache))) { return WrapResult(Inner.FindView(controllerContext, viewName, masterName, useCache)); } @@ -40,7 +41,7 @@ namespace Umbraco.Core.Profiling public void ReleaseView(ControllerContext controllerContext, IView view) { - using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.ReleaseView, {1}", _name, view.GetType().Name))) + using (Current.Profiler.Step(string.Format("{0}.ReleaseView, {1}", _name, view.GetType().Name))) { Inner.ReleaseView(controllerContext, view); } diff --git a/src/Umbraco.Web/Mvc/UmbracoPageResult.cs b/src/Umbraco.Web/Mvc/UmbracoPageResult.cs index da4cb198ac..f1282c7464 100644 --- a/src/Umbraco.Web/Mvc/UmbracoPageResult.cs +++ b/src/Umbraco.Web/Mvc/UmbracoPageResult.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Mvc [Obsolete("Use the ctor specifying all depenendencies instead")] public UmbracoPageResult() - : this(new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler)) + : this(new ProfilingLogger(Current.Logger, Current.Profiler)) { } diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStore.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStore.cs index 28d5c71881..88078a3d56 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStore.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStore.cs @@ -135,7 +135,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache { if (SyncToXmlFile == false) return; - var logger = LoggerResolver.Current.Logger; + var logger = Current.Logger; // there's always be one task keeping a ref to the runner // so it's safe to just create it as a local var here diff --git a/src/Umbraco.Web/UI/Pages/BasePage.cs b/src/Umbraco.Web/UI/Pages/BasePage.cs index b9eec4982b..70d387fcd5 100644 --- a/src/Umbraco.Web/UI/Pages/BasePage.cs +++ b/src/Umbraco.Web/UI/Pages/BasePage.cs @@ -54,7 +54,7 @@ namespace Umbraco.Web.UI.Pages /// public ProfilingLogger ProfilingLogger { - get { return _logger ?? (_logger = new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler)); } + get { return _logger ?? (_logger = new ProfilingLogger(Current.Logger, Current.Profiler)); } } private ProfilingLogger _logger; diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 1a224c5cd0..533ec6c440 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -1,58 +1,44 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Web; -using System.Web.Hosting; -using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.IO; -using Umbraco.Core.Logging; using Umbraco.Core.Manifest; -using Umbraco.Web.Routing; - namespace Umbraco.Web { /// - /// The Umbraco global.asax class + /// Represents the Umbraco global.asax class. /// public class UmbracoApplication : UmbracoApplicationBase { + // if configured and in debug mode, a ManifestWatcher watches App_Plugins folders for + // package.manifest chances and restarts the application on any change private ManifestWatcher _mw; protected override void OnApplicationStarted(object sender, EventArgs e) { base.OnApplicationStarted(sender, e); - if (ApplicationContext.Current.IsConfigured && GlobalSettings.DebugMode) - { - var appPluginFolder = IOHelper.MapPath("~/App_Plugins/"); - if (Directory.Exists(appPluginFolder)) - { - _mw = new ManifestWatcher(LoggerResolver.Current.Logger); - _mw.Start(Directory.GetDirectories(IOHelper.MapPath("~/App_Plugins/"))); - } - } + if (ApplicationContext.Current.IsConfigured == false || GlobalSettings.DebugMode == false) + return; + + var appPlugins = IOHelper.MapPath("~/App_Plugins/"); + if (Directory.Exists(appPlugins) == false) return; + + _mw = new ManifestWatcher(Current.Logger); + _mw.Start(Directory.GetDirectories(appPlugins)); } protected override void OnApplicationEnd(object sender, EventArgs e) { base.OnApplicationEnd(sender, e); - - if (_mw != null) - { - _mw.Dispose(); - } + _mw?.Dispose(); } protected override IBootManager GetBootManager() { - return new WebBootManager(this); + return new WebBootManager(this); } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs index fb9668488c..1b0742bef3 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs @@ -347,7 +347,7 @@ namespace umbraco.presentation.developer.packages _installer.InstallCleanUp(packageId, dir); // Update ClientDependency version - var clientDependencyConfig = new Umbraco.Core.Configuration.ClientDependencyConfiguration(LoggerResolver.Current.Logger); + var clientDependencyConfig = new Umbraco.Core.Configuration.ClientDependencyConfiguration(Current.Logger); var clientDependencyUpdated = clientDependencyConfig.IncreaseVersionNumber(); //clear the tree cache - we'll do this here even though the browser will reload, but just in case it doesn't can't hurt.