diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs similarity index 85% rename from src/Umbraco.Core/Configuration/ConfigsExtensions.cs rename to src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs index ae3341aff8..275606e8bb 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs @@ -1,5 +1,6 @@ using System.IO; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; using Umbraco.Core.IO; @@ -14,9 +15,9 @@ namespace Umbraco.Core public static class ConfigsExtensions { - public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper) + public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper, ISystemDirectories systemDirectories) { - var configDir = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Config)); + var configDir = new DirectoryInfo(ioHelper.MapPath(systemDirectories.Config)); // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition configs.Add(factory => new GridConfig( diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs similarity index 76% rename from src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs rename to src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs index 2bc1e8d8c2..6f07c474b5 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Web; -using System.Web.Routing; -using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Configuration @@ -26,16 +19,16 @@ namespace Umbraco.Core.Configuration /// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something /// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco". /// - public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings) + public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings, ISystemDirectories systemDirectories) { if (_mvcArea != null) return _mvcArea; - _mvcArea = GetUmbracoMvcAreaNoCache(globalSettings); + _mvcArea = GetUmbracoMvcAreaNoCache(globalSettings, systemDirectories); return _mvcArea; } - internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings) + internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, ISystemDirectories systemDirectories) { if (globalSettings.Path.IsNullOrWhiteSpace()) { @@ -43,8 +36,8 @@ namespace Umbraco.Core.Configuration } var path = globalSettings.Path; - if (path.StartsWith(Current.SystemDirectories.Root)) // beware of TrimStart, see U4-2518 - path = path.Substring(Current.SystemDirectories.Root.Length); + if (path.StartsWith(systemDirectories.Root)) // beware of TrimStart, see U4-2518 + path = path.Substring(systemDirectories.Root.Length); return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); } diff --git a/src/Umbraco.Abstractions/Services/IRuntime.cs b/src/Umbraco.Abstractions/Services/IRuntime.cs index a7944ad256..e846342dbc 100644 --- a/src/Umbraco.Abstractions/Services/IRuntime.cs +++ b/src/Umbraco.Abstractions/Services/IRuntime.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core /// /// The application register. /// The application factory. - IFactory Boot(IRegister register, IConfigsFactory configsFactory); + IFactory Boot(IRegister register); /// /// Gets the runtime state. diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs index 4d8b1cd3aa..1a0cb8d7c5 100644 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -1,22 +1,29 @@ using System.Configuration; -using Umbraco.Core.Composing; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; namespace Umbraco.Core.Configuration { public class ConfigsFactory : IConfigsFactory { + private readonly IIOHelper _ioHelper; + private readonly ISystemDirectories _systemDirectories; + public ConfigsFactory(IIOHelper ioHelper, ISystemDirectories systemDirectories) + { + _ioHelper = ioHelper; + _systemDirectories = systemDirectories; + } public Configs Create() { var configs = new Configs(section => ConfigurationManager.GetSection(section)); - configs.Add(() => new GlobalSettings()); + configs.Add(() => new GlobalSettings(_ioHelper, _systemDirectories)); configs.Add("umbracoConfiguration/settings"); configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); - configs.AddCoreConfigs(Current.IOHelper); + configs.AddCoreConfigs(_ioHelper, _systemDirectories); return configs; } } diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index 0e024346af..ee64cc3842 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -19,6 +19,8 @@ namespace Umbraco.Core.Configuration /// public class GlobalSettings : IGlobalSettings { + private readonly IIOHelper _ioHelper; + private readonly ISystemDirectories _systemDirectories; private string _localTempPath; // TODO these should not be static @@ -29,6 +31,12 @@ namespace Umbraco.Core.Configuration internal const string StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma! internal const string StaticReservedUrls = "~/config/splashes/noNodes.aspx,~/.well-known,"; //must end with a comma! + public GlobalSettings(IIOHelper ioHelper, ISystemDirectories systemDirectories) + { + _ioHelper = ioHelper; + _systemDirectories = systemDirectories; + } + /// /// Used in unit testing to reset all config items that were set with property setters (i.e. did not come from config) /// @@ -141,7 +149,7 @@ namespace Umbraco.Core.Configuration get { return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.Path) - ? Current.IOHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path]) + ? _ioHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path]) : string.Empty; } } @@ -160,7 +168,7 @@ namespace Umbraco.Core.Configuration } set { - SaveSetting(Constants.AppSettings.ConfigurationStatus, value); + SaveSetting(Constants.AppSettings.ConfigurationStatus, value, _ioHelper, _systemDirectories); } } @@ -169,9 +177,9 @@ namespace Umbraco.Core.Configuration /// /// Key of the setting to be saved. /// Value of the setting to be saved. - internal static void SaveSetting(string key, string value) + internal static void SaveSetting(string key, string value, IIOHelper ioHelper, ISystemDirectories systemDirectories) { - var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.SystemDirectories.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", systemDirectories.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -191,9 +199,9 @@ namespace Umbraco.Core.Configuration /// Removes a setting from the configuration file. /// /// Key of the setting to be removed. - internal static void RemoveSetting(string key) + internal static void RemoveSetting(string key, IIOHelper ioHelper, ISystemDirectories systemDirectories) { - var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.SystemDirectories.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", systemDirectories.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -320,7 +328,7 @@ namespace Umbraco.Core.Configuration //case LocalTempStorage.Default: //case LocalTempStorage.Unknown: default: - return _localTempPath = Current.IOHelper.MapPath("~/App_Data/TEMP"); + return _localTempPath = _ioHelper.MapPath("~/App_Data/TEMP"); } } } diff --git a/src/Umbraco.Core/ConventionsHelper.cs b/src/Umbraco.Core/ConventionsHelper.cs index 16ad95b95e..834078f84d 100644 --- a/src/Umbraco.Core/ConventionsHelper.cs +++ b/src/Umbraco.Core/ConventionsHelper.cs @@ -21,7 +21,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Integer, true, Constants.Conventions.Member.FailedPasswordAttempts) { - Name = Constants.Conventions.Member.FailedPasswordAttemptsLabel + Name = Constants.Conventions.Member.FailedPasswordAttemptsLabel, + DataTypeId = Constants.DataTypes.LabelInt } }, { @@ -45,7 +46,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Date, true, Constants.Conventions.Member.LastLockoutDate) { - Name = Constants.Conventions.Member.LastLockoutDateLabel + Name = Constants.Conventions.Member.LastLockoutDateLabel, + DataTypeId = Constants.DataTypes.LabelDateTime } }, { @@ -53,7 +55,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Date, true, Constants.Conventions.Member.LastLoginDate) { - Name = Constants.Conventions.Member.LastLoginDateLabel + Name = Constants.Conventions.Member.LastLoginDateLabel, + DataTypeId = Constants.DataTypes.LabelDateTime } }, { @@ -61,7 +64,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Date, true, Constants.Conventions.Member.LastPasswordChangeDate) { - Name = Constants.Conventions.Member.LastPasswordChangeDateLabel + Name = Constants.Conventions.Member.LastPasswordChangeDateLabel, + DataTypeId = Constants.DataTypes.LabelDateTime } }, { @@ -69,7 +73,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, Constants.Conventions.Member.PasswordAnswer) { - Name = Constants.Conventions.Member.PasswordAnswerLabel + Name = Constants.Conventions.Member.PasswordAnswerLabel, + DataTypeId = Constants.DataTypes.LabelString } }, { @@ -77,7 +82,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, Constants.Conventions.Member.PasswordQuestion) { - Name = Constants.Conventions.Member.PasswordQuestionLabel + Name = Constants.Conventions.Member.PasswordQuestionLabel, + DataTypeId = Constants.DataTypes.LabelString } } }; diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 6918c16295..123793edae 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -53,12 +53,13 @@ namespace Umbraco.Core.Runtime /// Gets the /// protected IIOHelper IOHelper { get; private set; } + protected ISystemDirectories SystemDirectories { get; private set; } /// public IRuntimeState State => _state; /// - public virtual IFactory Boot(IRegister register, IConfigsFactory configsFactory) + public virtual IFactory Boot(IRegister register) { // create and register the essential services // ie the bare minimum required to boot @@ -81,6 +82,10 @@ namespace Umbraco.Core.Runtime if (TypeFinder == null) throw new InvalidOperationException($"The object returned from {nameof(GetTypeFinder)} cannot be null"); + SystemDirectories = GetSystemDirectories(); + if (SystemDirectories == null) + throw new InvalidOperationException($"The object returned from {nameof(GetSystemDirectories)} cannot be null"); + // the boot loader boots using a container scope, so anything that is PerScope will // be disposed after the boot loader has booted, and anything else will remain. // note that this REQUIRES that perWebRequestScope has NOT been enabled yet, else @@ -106,7 +111,7 @@ namespace Umbraco.Core.Runtime ConfigureUnhandledException(); ConfigureApplicationRootPath(); - Boot(register, timer, configsFactory); + Boot(register, timer); } return _factory; @@ -115,7 +120,7 @@ namespace Umbraco.Core.Runtime /// /// Boots the runtime within a timer. /// - protected virtual IFactory Boot(IRegister register, DisposableTimer timer, IConfigsFactory configsFactory) + protected virtual IFactory Boot(IRegister register, DisposableTimer timer) { Composition composition = null; @@ -134,7 +139,7 @@ namespace Umbraco.Core.Runtime var databaseFactory = GetDatabaseFactory(); // configs - var configs = GetConfigs(configsFactory); + var configs = GetConfigs(); // type finder/loader var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(configs.Global().LocalTempPath), ProfilingLogger); @@ -350,6 +355,8 @@ namespace Umbraco.Core.Runtime /// protected virtual IIOHelper GetIOHelper() => Umbraco.Core.IO.IOHelper.Default; + protected virtual ISystemDirectories GetSystemDirectories() + => new SystemDirectories(); /// /// Gets the application caches. @@ -381,9 +388,9 @@ namespace Umbraco.Core.Runtime /// /// Gets the configurations. /// - protected virtual Configs GetConfigs(IConfigsFactory configsFactory) + protected virtual Configs GetConfigs() { - var configs = configsFactory.Create(); + var configs = new ConfigsFactory(IOHelper, SystemDirectories).Create(); return configs; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 6eefa3b8c3..4ac93262da 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -153,10 +153,8 @@ - - diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 9fd1bf46dc..2cd7bef26d 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -52,9 +52,10 @@ namespace Umbraco.Core //if not, then def not back office if (isUmbracoPath == false) return false; + var mvcArea = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); //if its the normal /umbraco path - if (urlPath.InvariantEquals("/" + globalSettings.GetUmbracoMvcArea()) - || urlPath.InvariantEquals("/" + globalSettings.GetUmbracoMvcArea() + "/")) + if (urlPath.InvariantEquals("/" + mvcArea) + || urlPath.InvariantEquals("/" + mvcArea + "/")) { return true; } @@ -75,15 +76,15 @@ namespace Umbraco.Core } //check for special back office paths - if (urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/BackOffice/") - || urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Preview/")) + if (urlPath.InvariantStartsWith("/" + mvcArea + "/BackOffice/") + || urlPath.InvariantStartsWith("/" + mvcArea + "/Preview/")) { return true; } //check for special front-end paths - if (urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Surface/") - || urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Api/")) + if (urlPath.InvariantStartsWith("/" + mvcArea + "/Surface/") + || urlPath.InvariantStartsWith("/" + mvcArea + "/Api/")) { return false; } diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index a57eb9a823..9227d84579 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Scoping; +using Umbraco.Tests.TestHelpers; [assembly:DisableComposer(typeof(Umbraco.Tests.Components.ComponentTests.Composer26))] @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Components private static readonly List Composed = new List(); private static readonly List Initialized = new List(); private static readonly List Terminated = new List(); - private static readonly Configs Configs = new ConfigsFactory().Create(); + private static readonly Configs Configs = TestHelper.GetConfigs(); private static IFactory MockFactory(Action> setup = null) { @@ -70,7 +71,7 @@ namespace Umbraco.Tests.Components public void Boot1A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -109,7 +110,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -125,7 +126,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -140,7 +141,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -157,7 +158,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -180,7 +181,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -215,7 +216,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Mock.Of()); @@ -241,7 +242,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Mock.Of()); diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index bab6a13dad..722260fba7 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.Configurations globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path)); Current.SystemDirectories.Root = rootPath; - Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache()); + Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(new SystemDirectories())); } diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index f15795e299..6bf7e808a9 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Macros //Current.ApplicationContext = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of(), Mock.Of())); Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index e96a8c7915..e263d99cec 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -16,7 +16,7 @@ namespace Umbraco.Tests.Models public void Init() { Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 2a55268c48..836ce54afa 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 48e8de3fab..603cd84a1a 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -18,7 +18,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); } diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index 32ff48ab12..c2651a6ff6 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Models Current.Reset(); - var configs = new ConfigsFactory().Create(); + var configs = TestHelper.GetConfigs(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 7c3bd73692..59f324387a 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -10,6 +10,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; @@ -54,9 +55,9 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new ConfigsFactory().Create(); + var configs = TestHelper.GetConfigs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(); + var globalSettings = new GlobalSettings(IOHelper.Default, new SystemDirectories()); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add(() => globalSettings); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 32f5d06e74..f6ad657a75 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; @@ -49,9 +50,9 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new ConfigsFactory().Create(); + var configs = TestHelper.GetConfigs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(); + var globalSettings = new GlobalSettings(IOHelper.Default, new SystemDirectories()); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add(() => globalSettings); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index daf4f4afe6..b29d86f56b 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -4,6 +4,7 @@ using System.Data; using System.Web.Hosting; using Examine; using Moq; +using NPoco.Expressions; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Compose; @@ -11,6 +12,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.Exceptions; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; @@ -102,9 +104,9 @@ namespace Umbraco.Tests.Runtimes return mock.Object; } - protected override Configs GetConfigs(IConfigsFactory configsFactory) + protected override Configs GetConfigs() { - var configs = configsFactory.Create(); + var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default, new SystemDirectories()).Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; @@ -142,9 +144,9 @@ namespace Umbraco.Tests.Runtimes private IMainDom _mainDom; - public override IFactory Boot(IRegister container, IConfigsFactory configsFactory) + public override IFactory Boot(IRegister container) { - var factory = base.Boot(container, configsFactory); + var factory = base.Boot(container); _mainDom = factory.GetInstance(); return factory; } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 3aa4495601..305143ec0f 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -45,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers logger, false); - var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 9e5995cfb5..c5f169a232 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -36,7 +36,12 @@ namespace Umbraco.Tests.TestHelpers public static Configs GetConfigs() { - return new ConfigsFactory().Create(); + return GetConfigsFactory().Create(); + } + + public static IConfigsFactory GetConfigsFactory() + { + return new ConfigsFactory(IOHelper.Default, new SystemDirectories()); } /// @@ -269,5 +274,7 @@ namespace Umbraco.Tests.TestHelpers ); } + + } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index d11bf8e5d7..fdc43fee59 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -141,7 +141,7 @@ namespace Umbraco.Tests.Testing var register = RegisterFactory.Create(); - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); Composition.RegisterUnique(IOHelper); @@ -229,6 +229,7 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(); Composition.RegisterUnique(); Composition.RegisterUnique(); + Composition.RegisterUnique(); // register back office sections in the order we want them rendered Composition.WithCollectionBuilder().Append() diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index 04226d81f2..4259c8ebae 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -9,6 +9,7 @@ using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; +using Umbraco.Web.Composing; using Umbraco.Web.SignalR; namespace Umbraco.Web @@ -50,7 +51,7 @@ namespace Umbraco.Web /// public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true }); } diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index c2c481e8e4..5da28bd0a5 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -514,7 +514,7 @@ namespace Umbraco.Web.Editors var action = urlHelper.Action("ValidatePasswordResetCode", "BackOffice", new { - area = GlobalSettings.GetUmbracoMvcArea(), + area = GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories), u = userId, r = code }); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 68f234a22a..028eea60e8 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -352,7 +352,7 @@ namespace Umbraco.Web.Editors if (defaultResponse == null) throw new ArgumentNullException("defaultResponse"); if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse"); - ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea()); + ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories)); //check if there is the TempData with the any token name specified, if so, assign to view bag and render the view if (ViewData.FromTempData(TempData, ViewDataExtensions.TokenExternalSignInError) || diff --git a/src/Umbraco.Web/Editors/UsersController.cs b/src/Umbraco.Web/Editors/UsersController.cs index cf81907dda..874bc6bbfa 100644 --- a/src/Umbraco.Web/Editors/UsersController.cs +++ b/src/Umbraco.Web/Editors/UsersController.cs @@ -456,7 +456,7 @@ namespace Umbraco.Web.Editors var action = urlHelper.Action("VerifyInvite", "BackOffice", new { - area = GlobalSettings.GetUmbracoMvcArea(), + area = GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories), invite = inviteToken }); diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs index c680b6e41a..04abb51b6f 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; +using Umbraco.Web.Composing; using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install.InstallSteps @@ -55,7 +56,7 @@ namespace Umbraco.Web.Install.InstallSteps // Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists if (ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName] != null) { - GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName); + GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, Current.IOHelper, Current.SystemDirectories); } else { diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 61a659615f..6c02d18822 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -7,6 +7,7 @@ using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; +using Umbraco.Web.Composing; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -55,7 +56,7 @@ namespace Umbraco.Web.Mvc if (routes == null) throw new ArgumentNullException(nameof(routes)); if (defaultId == null) throw new ArgumentNullException(nameof(defaultId)); - var umbracoArea = globalSettings.GetUmbracoMvcArea(); + var umbracoArea = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); //routes are explicitly named with controller names and IDs var url = umbracoArea + "/" + diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index e72f2cc81a..747ebe61e1 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,4 +1,5 @@ using System.Web.Mvc; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Web.Editors; @@ -26,15 +27,16 @@ namespace Umbraco.Web.Mvc /// public override void RegisterArea(AreaRegistrationContext context) { + context.MapRoute( "Umbraco_preview", - _globalSettings.GetUmbracoMvcArea() + "/preview/{action}/{editor}", + AreaName + "/preview/{action}/{editor}", new {controller = "Preview", action = "Index", editor = UrlParameter.Optional}, new[] { "Umbraco.Web.Editors" }); context.MapRoute( "Umbraco_back_office", - _globalSettings.GetUmbracoMvcArea() + "/{action}/{id}", + AreaName + "/{action}/{id}", new {controller = "BackOffice", action = "Default", id = UrlParameter.Optional}, //limit the action/id to only allow characters - this is so this route doesn't hog all other // routes like: /umbraco/channels/word.aspx, etc... @@ -46,6 +48,6 @@ namespace Umbraco.Web.Mvc new[] {typeof (BackOfficeController).Namespace}); } - public override string AreaName => _globalSettings.GetUmbracoMvcArea(); + public override string AreaName => _globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index e5ad0c0665..4ba1977eb4 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -150,7 +150,7 @@ namespace Umbraco.Web.Runtime SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); // create the front-end route var defaultRoute = RouteTable.Routes.MapRoute( @@ -175,7 +175,7 @@ namespace Umbraco.Web.Runtime SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); // need to find the plugin controllers and route them var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray(); diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index ce420e88c6..2f1ef43e4c 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.Runtime } /// - public override IFactory Boot(IRegister register, IConfigsFactory configsFactory) + public override IFactory Boot(IRegister register) { // create and start asap to profile boot var debug = GlobalSettings.DebugMode; @@ -46,7 +46,7 @@ namespace Umbraco.Web.Runtime _webProfiler = new VoidProfiler(); } - var factory = base.Boot(register, configsFactory); + var factory = base.Boot(register); // now (and only now) is the time to switch over to perWebRequest scopes. // up until that point we may not have a request, and scoped services would diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 24800500a8..dba7798559 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -63,7 +63,7 @@ namespace Umbraco.Web // the boot manager is responsible for registrations var register = GetRegister(); _runtime = GetRuntime(); - _runtime.Boot(register, new ConfigsFactory()); + _runtime.Boot(register); } // called by ASP.NET (auto event wireup) once per app domain