From a3e84ea3a8311d824aec4fc51eaf922477244dcd Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 19 Aug 2020 14:14:01 +0100 Subject: [PATCH 01/58] (WIP) migrated TourSettings to use IOptions pattern for configuration. --- .../AspNetCoreConfigsFactory.cs | 2 +- .../Models/TourSettings.cs | 20 +++---------------- .../Controllers/TourController.cs | 8 +++++--- .../UmbracoCoreServiceCollectionExtensions.cs | 5 +++-- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index 0cacab9e1d..02e9303c9a 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -21,7 +21,7 @@ namespace Umbraco.Configuration { var configs = new Configs(); - configs.Add(() => new TourSettings(_configuration)); + //configs.Add(() => new TourSettings(_configuration)); configs.Add(() => new CoreDebugSettings(_configuration)); configs.Add(() => new RequestHandlerSettings(_configuration)); configs.Add(() => new SecuritySettings(_configuration)); diff --git a/src/Umbraco.Configuration/Models/TourSettings.cs b/src/Umbraco.Configuration/Models/TourSettings.cs index 9fe1814ff5..a9cfaa8987 100644 --- a/src/Umbraco.Configuration/Models/TourSettings.cs +++ b/src/Umbraco.Configuration/Models/TourSettings.cs @@ -1,21 +1,7 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class TourSettings : ITourSettings + public class TourSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Tours:"; - private readonly IConfiguration _configuration; - - public TourSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string Type { get; set; } - - public bool EnableTours => _configuration.GetValue(Prefix+"EnableTours", true); + public bool EnableTours { get; set; } = true; } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/TourController.cs b/src/Umbraco.Web.BackOffice/Controllers/TourController.cs index f85bdb1bd5..c74cf41daf 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/TourController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/TourController.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Newtonsoft.Json; +using Umbraco.Configuration.Models; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; @@ -19,21 +21,21 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly TourFilterCollection _filters; private readonly IHostingEnvironment _hostingEnvironment; - private readonly ITourSettings _tourSettings; + private readonly TourSettings _tourSettings; private readonly IWebSecurity _webSecurity; private readonly IContentTypeService _contentTypeService; public TourController( TourFilterCollection filters, IHostingEnvironment hostingEnvironment, - ITourSettings tourSettings, + IOptionsSnapshot tourSettings, IWebSecurity webSecurity, IContentTypeService contentTypeService) { _filters = filters; _hostingEnvironment = hostingEnvironment; - _tourSettings = tourSettings; + _tourSettings = tourSettings.Value; _webSecurity = webSecurity; _contentTypeService = contentTypeService; } diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index d18275ca7f..94e9062902 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -16,6 +16,7 @@ using Serilog; using Serilog.Extensions.Hosting; using Serilog.Extensions.Logging; using Umbraco.Configuration; +using Umbraco.Configuration.Models; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; @@ -105,10 +106,10 @@ namespace Umbraco.Extensions { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); + var configsFactory = new AspNetCoreConfigsFactory(configuration); - var configs = configsFactory.Create(); - services.AddSingleton(configs); return services; From 0f6e18023faecb7e7837a9074f7feef1db47ffc1 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 20 Aug 2020 08:24:23 +0100 Subject: [PATCH 02/58] Amended most configuration settings classes to public POCOs without interfaces, and loaded into services collection via loading the configuration section. --- .../AspNetCoreConfigsFactory.cs | 36 ++++---- .../Models/ActiveDirectorySettings.cs | 17 +--- .../Models/ContentImagingSettings.cs | 36 ++++++++ .../Models/ContentNotificationSettings.cs | 9 ++ .../Models/ContentSettings.cs | 79 +++++----------- .../Models/CoreDebugSettings.cs | 22 +---- .../Models/ExceptionFilterSettings.cs | 18 +--- .../Models/GlobalSettings.cs | 89 ++++++------------- .../Models/HostingSettings.cs | 24 +++-- .../Models/ImagingCacheSettings.cs | 16 ++++ .../Models/ImagingResizeSettings.cs | 13 +++ .../Models/ImagingSettings.cs | 25 +----- .../Models/IndexCreatorSettings.cs | 19 +--- .../Models/KeepAliveSettings.cs | 20 +---- .../Models/LoggingSettings.cs | 18 +--- .../MemberPasswordConfigurationSettings.cs | 35 ++------ .../Models/ModelsBuilderConfig.cs | 50 +++++------ .../Models/NuCacheSettings.cs | 18 +--- .../Models/RuntimeSettings.cs | 18 +--- .../Models/SecuritySettings.cs | 32 ++----- .../Models/SmtpSettings.cs | 21 +++++ .../Models/TypeFinderSettings.cs | 19 +--- .../UserPasswordConfigurationSettings.cs | 32 ++----- .../Models/WebRoutingSettings.cs | 39 +++----- .../UmbracoCoreServiceCollectionExtensions.cs | 25 ++++-- 25 files changed, 284 insertions(+), 446 deletions(-) create mode 100644 src/Umbraco.Configuration/Models/ContentImagingSettings.cs create mode 100644 src/Umbraco.Configuration/Models/ContentNotificationSettings.cs create mode 100644 src/Umbraco.Configuration/Models/ImagingCacheSettings.cs create mode 100644 src/Umbraco.Configuration/Models/ImagingResizeSettings.cs create mode 100644 src/Umbraco.Configuration/Models/SmtpSettings.cs diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index 02e9303c9a..b388579687 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -22,27 +22,27 @@ namespace Umbraco.Configuration var configs = new Configs(); //configs.Add(() => new TourSettings(_configuration)); - configs.Add(() => new CoreDebugSettings(_configuration)); + //configs.Add(() => new CoreDebugSettings(_configuration)); configs.Add(() => new RequestHandlerSettings(_configuration)); - configs.Add(() => new SecuritySettings(_configuration)); - configs.Add(() => new UserPasswordConfigurationSettings(_configuration)); - configs.Add(() => new MemberPasswordConfigurationSettings(_configuration)); - configs.Add(() => new KeepAliveSettings(_configuration)); - configs.Add(() => new ContentSettings(_configuration)); + //configs.Add(() => new SecuritySettings(_configuration)); + //configs.Add(() => new UserPasswordConfigurationSettings(_configuration)); + //configs.Add(() => new MemberPasswordConfigurationSettings(_configuration)); + //configs.Add(() => new KeepAliveSettings(_configuration)); + //configs.Add(() => new ContentSettings(_configuration)); configs.Add(() => new HealthChecksSettings(_configuration)); - configs.Add(() => new LoggingSettings(_configuration)); - configs.Add(() => new ExceptionFilterSettings(_configuration)); - configs.Add(() => new ActiveDirectorySettings(_configuration)); - configs.Add(() => new RuntimeSettings(_configuration)); - configs.Add(() => new TypeFinderSettings(_configuration)); - configs.Add(() => new NuCacheSettings(_configuration)); - configs.Add(() => new WebRoutingSettings(_configuration)); - configs.Add(() => new IndexCreatorSettings(_configuration)); - configs.Add(() => new ModelsBuilderConfig(_configuration)); - configs.Add(() => new HostingSettings(_configuration)); - configs.Add(() => new GlobalSettings(_configuration)); + //configs.Add(() => new LoggingSettings(_configuration)); + //configs.Add(() => new ExceptionFilterSettings(_configuration)); + //configs.Add(() => new ActiveDirectorySettings(_configuration)); + //configs.Add(() => new RuntimeSettings(_configuration)); + //configs.Add(() => new TypeFinderSettings(_configuration)); + //configs.Add(() => new NuCacheSettings(_configuration)); + //configs.Add(() => new WebRoutingSettings(_configuration)); + //configs.Add(() => new IndexCreatorSettings(_configuration)); + //configs.Add(() => new ModelsBuilderConfig(_configuration)); + //configs.Add(() => new HostingSettings(_configuration)); + //configs.Add(() => new GlobalSettings(_configuration)); configs.Add(() => new ConnectionStrings(_configuration)); - configs.Add(() => new ImagingSettings(_configuration)); + //configs.Add(() => new ImagingSettings(_configuration)); return configs; } diff --git a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs index 015fb17a8e..d7d2de1490 100644 --- a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs +++ b/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs @@ -1,19 +1,10 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; +using System.Text.Json.Serialization; namespace Umbraco.Configuration.Models { - internal class ActiveDirectorySettings : IActiveDirectorySettings + public class ActiveDirectorySettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "ActiveDirectory:"; - private readonly IConfiguration _configuration; - - public ActiveDirectorySettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string ActiveDirectoryDomain => _configuration.GetValue(Prefix+"Domain"); + [JsonPropertyName("Domain")] + public string ActiveDirectoryDomain { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/ContentImagingSettings.cs b/src/Umbraco.Configuration/Models/ContentImagingSettings.cs new file mode 100644 index 0000000000..f38e4194e8 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ContentImagingSettings.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Configuration.Models +{ + public class ContentImagingSettings + { + private static readonly ImagingAutoFillUploadField[] DefaultImagingAutoFillUploadField = +{ + new ImagingAutoFillUploadField + { + Alias = Constants.Conventions.Media.File, + WidthFieldAlias = Constants.Conventions.Media.Width, + HeightFieldAlias = Constants.Conventions.Media.Height, + ExtensionFieldAlias = Constants.Conventions.Media.Extension, + LengthFieldAlias = Constants.Conventions.Media.Bytes, + } + }; + + public IEnumerable ImageFileTypes { get; set; } = new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }; + + [JsonPropertyName("AutoFillImageProperties")] + public IEnumerable ImageAutoFillProperties { get; set; } = DefaultImagingAutoFillUploadField; + + private class ImagingAutoFillUploadField : IImagingAutoFillUploadField + { + public string Alias { get; set; } + public string WidthFieldAlias { get; set; } + public string HeightFieldAlias { get; set; } + public string LengthFieldAlias { get; set; } + public string ExtensionFieldAlias { get; set; } + } + } +} diff --git a/src/Umbraco.Configuration/Models/ContentNotificationSettings.cs b/src/Umbraco.Configuration/Models/ContentNotificationSettings.cs new file mode 100644 index 0000000000..96f6baddff --- /dev/null +++ b/src/Umbraco.Configuration/Models/ContentNotificationSettings.cs @@ -0,0 +1,9 @@ +namespace Umbraco.Configuration.Models +{ + public class ContentNotificationSettings + { + public string NotificationEmailAddress { get; set; } + + public bool DisableHtmlEmail { get; set; } = false; + } +} diff --git a/src/Umbraco.Configuration/Models/ContentSettings.cs b/src/Umbraco.Configuration/Models/ContentSettings.cs index 6c9b986dd1..945dc14728 100644 --- a/src/Umbraco.Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Configuration/Models/ContentSettings.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Serialization; using Microsoft.Extensions.Configuration; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; @@ -8,7 +9,7 @@ using Umbraco.Core.Macros; namespace Umbraco.Configuration.Models { - internal class ContentSettings : IContentSettings + public class ContentSettings { private const string Prefix = Constants.Configuration.ConfigPrefix + "Content:"; private const string NotificationsPrefix = Prefix + "Notifications:"; @@ -16,64 +17,35 @@ namespace Umbraco.Configuration.Models private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; - private static readonly ImagingAutoFillUploadField[] DefaultImagingAutoFillUploadField = - { - new ImagingAutoFillUploadField - { - Alias = Constants.Conventions.Media.File, - WidthFieldAlias = Constants.Conventions.Media.Width, - HeightFieldAlias =Constants.Conventions.Media.Height, - ExtensionFieldAlias =Constants.Conventions.Media.Extension, - LengthFieldAlias =Constants.Conventions.Media.Bytes, - } - }; + public ContentNotificationSettings Notifications { get; set; } - private readonly IConfiguration _configuration; + public ContentImagingSettings Imaging { get; set; } - public ContentSettings(IConfiguration configuration) - { - _configuration = configuration; - } + public bool ResolveUrlsFromTextString { get; set; } = false; - public string NotificationEmailAddress => - _configuration.GetValue(NotificationsPrefix+"Email"); + // TODO: to retain previous configuration structure, this should come from a nested collection, + // "Errors:Error404". Although we can use JsonPropertyName to map when the JSON field name differs + // from the one in this class, not sure how we'd "flatten" a collection like this. + [JsonPropertyName("Error404")] + public IEnumerable Error404Collection { get; set; } - public bool DisableHtmlEmail => - _configuration.GetValue(NotificationsPrefix+"DisableHtmlEmail", false); + // public IEnumerable Error404Collection => _configuration + // .GetSection(Prefix + "Errors:Error404") + // .GetChildren() + // .Select(x => new ContentErrorPage(x)); - public IEnumerable ImageFileTypes => _configuration.GetValue( - ImagingPrefix+"ImageFileTypes", new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }); + public string PreviewBadge { get; set; } = DefaultPreviewBadge; - public IEnumerable ImageAutoFillProperties => - _configuration.GetValue(ImagingPrefix+"AutoFillImageProperties", - DefaultImagingAutoFillUploadField); + [JsonPropertyName("MacroErrors")] + public MacroErrorBehaviour MacroErrorBehaviour { get; set; } = MacroErrorBehaviour.Inline; + public IEnumerable DisallowedUploadFiles { get; set; } = new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }; - public bool ResolveUrlsFromTextString => - _configuration.GetValue(Prefix+"ResolveUrlsFromTextString", false); + public IEnumerable AllowedUploadFiles { get; set; } = Array.Empty(); - public IEnumerable Error404Collection => _configuration - .GetSection(Prefix+"Errors:Error404") - .GetChildren() - .Select(x => new ContentErrorPage(x)); + public bool ShowDeprecatedPropertyEditors { get; set; } = false; - public string PreviewBadge => _configuration.GetValue(Prefix+"PreviewBadge", DefaultPreviewBadge); - - public MacroErrorBehaviour MacroErrorBehaviour => - _configuration.GetValue(Prefix+"MacroErrors", MacroErrorBehaviour.Inline); - - public IEnumerable DisallowedUploadFiles => _configuration.GetValue( - Prefix+"DisallowedUploadFiles", - new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }); - - public IEnumerable AllowedUploadFiles => - _configuration.GetValue(Prefix+"AllowedUploadFiles", Array.Empty()); - - public bool ShowDeprecatedPropertyEditors => - _configuration.GetValue(Prefix+"ShowDeprecatedPropertyEditors", false); - - public string LoginBackgroundImage => - _configuration.GetValue(Prefix+"LoginBackgroundImage", "assets/img/login.jpg"); + public string LoginBackgroundImage { get; set; } = "assets/img/login.jpg"; private class ContentErrorPage : IContentErrorPage { @@ -106,14 +78,5 @@ namespace Umbraco.Configuration.Models public bool HasContentKey { get; } public string Culture { get; set; } } - - private class ImagingAutoFillUploadField : IImagingAutoFillUploadField - { - public string Alias { get; set; } - public string WidthFieldAlias { get; set; } - public string HeightFieldAlias { get; set; } - public string LengthFieldAlias { get; set; } - public string ExtensionFieldAlias { get; set; } - } } } diff --git a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs b/src/Umbraco.Configuration/Models/CoreDebugSettings.cs index 6d6c0eaf0d..e95a432dd4 100644 --- a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs +++ b/src/Umbraco.Configuration/Models/CoreDebugSettings.cs @@ -1,23 +1,9 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class CoreDebugSettings : ICoreDebugSettings + public class CoreDebugSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Core:Debug:"; - private readonly IConfiguration _configuration; + public bool LogUncompletedScopes { get; set; } = false; - public CoreDebugSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool LogUncompletedScopes => - _configuration.GetValue(Prefix+"LogUncompletedScopes", false); - - public bool DumpOnTimeoutThreadAbort => - _configuration.GetValue(Prefix+"DumpOnTimeoutThreadAbort", false); + public bool DumpOnTimeoutThreadAbort { get; set; } = false; } } diff --git a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs b/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs index 581daf9f40..d5fe64abce 100644 --- a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs +++ b/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs @@ -1,19 +1,7 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class ExceptionFilterSettings : IExceptionFilterSettings + public class ExceptionFilterSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "ExceptionFilter:"; - private readonly IConfiguration _configuration; - - public ExceptionFilterSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool Disabled => _configuration.GetValue(Prefix+"Disabled", false); + public bool Disabled { get; set; } = false; } } diff --git a/src/Umbraco.Configuration/Models/GlobalSettings.cs b/src/Umbraco.Configuration/Models/GlobalSettings.cs index 908ba71590..fcedd504c9 100644 --- a/src/Umbraco.Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Configuration/Models/GlobalSettings.cs @@ -1,9 +1,4 @@ -using System; -using System.Linq; -using System.Net.Mail; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; +using System.Text.Json.Serialization; namespace Umbraco.Configuration.Models { @@ -11,91 +6,57 @@ namespace Umbraco.Configuration.Models /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information /// from web.config appsettings /// - internal class GlobalSettings : IGlobalSettings + public class GlobalSettings { - private const string Prefix = Constants.Configuration.ConfigGlobalPrefix; - 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! - private readonly IConfiguration _configuration; + public string ReservedUrls { get; set; } = StaticReservedUrls; - public GlobalSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string ReservedUrls => _configuration.GetValue(Prefix + "ReservedUrls", StaticReservedUrls); - public string ReservedPaths => _configuration.GetValue(Prefix + "ReservedPaths", StaticReservedPaths); + public string ReservedPaths { get; set; } = StaticReservedPaths; // TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings - public string ConfigurationStatus - { - get => _configuration.GetValue(Prefix + "ConfigurationStatus"); - set => throw new NotImplementedException("We should remove this and only use the value from database"); - } + // TODO: previously this would throw on set, but presumably we can't do that if we do still want this in config. + public string ConfigurationStatus { get; set; } - public int TimeOutInMinutes => _configuration.GetValue(Prefix + "TimeOutInMinutes", 20); - public string DefaultUILanguage => _configuration.GetValue(Prefix + "DefaultUILanguage", "en-US"); + public int TimeOutInMinutes { get; set; } = 20; - public bool HideTopLevelNodeFromPath => - _configuration.GetValue(Prefix + "HideTopLevelNodeFromPath", false); + public string DefaultUILanguage { get; set; } = "en-US"; - public bool UseHttps => _configuration.GetValue(Prefix + "UseHttps", false); - public int VersionCheckPeriod => _configuration.GetValue(Prefix + "VersionCheckPeriod", 7); - public string UmbracoPath => _configuration.GetValue(Prefix + "UmbracoPath", "~/umbraco"); - public string UmbracoCssPath => _configuration.GetValue(Prefix + "UmbracoCssPath", "~/css"); + public bool HideTopLevelNodeFromPath { get; set; } = false; - public string UmbracoScriptsPath => - _configuration.GetValue(Prefix + "UmbracoScriptsPath", "~/scripts"); + public bool UseHttps { get; set; } = false; - public string UmbracoMediaPath => _configuration.GetValue(Prefix + "UmbracoMediaPath", "~/media"); + public int VersionCheckPeriod { get; set; } = 7; - public bool InstallMissingDatabase => - _configuration.GetValue(Prefix + "InstallMissingDatabase", false); + public string UmbracoPath { get; set; } = "~/umbraco"; - public bool InstallEmptyDatabase => _configuration.GetValue(Prefix + "InstallEmptyDatabase", false); + public string UmbracoCssPath { get; set; } = "~/css"; - public bool DisableElectionForSingleServer => - _configuration.GetValue(Prefix + "DisableElectionForSingleServer", false); + public string UmbracoScriptsPath { get; set; } = "~/scripts"; - public string RegisterType => _configuration.GetValue(Prefix + "RegisterType", string.Empty); + public string UmbracoMediaPath { get; set; } = "~/media"; - public string DatabaseFactoryServerVersion => - _configuration.GetValue(Prefix + "DatabaseFactoryServerVersion", string.Empty); + public bool InstallMissingDatabase { get; set; } = false; - public string MainDomLock => _configuration.GetValue(Prefix + "MainDomLock", string.Empty); + public bool InstallEmptyDatabase { get; set; } = false; - public string NoNodesViewPath => - _configuration.GetValue(Prefix + "NoNodesViewPath", "~/config/splashes/NoNodes.cshtml"); + public bool DisableElectionForSingleServer { get; set; } = false; - public bool IsSmtpServerConfigured => - _configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")?.GetChildren().Any() ?? false; + public string RegisterType { get; set; } = string.Empty; - public ISmtpSettings SmtpSettings => - new SmtpSettingsImpl(_configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")); + public string DatabaseFactoryServerVersion { get; set; } = string.Empty; - private class SmtpSettingsImpl : ISmtpSettings - { - private readonly IConfigurationSection _configurationSection; + public string MainDomLock { get; set; } = string.Empty; - public SmtpSettingsImpl(IConfigurationSection configurationSection) - { - _configurationSection = configurationSection; - } + public string NoNodesViewPath { get; set; } = "~/config/splashes/NoNodes.cshtml"; - public string From => _configurationSection.GetValue("From"); - public string Host => _configurationSection.GetValue("Host"); - public int Port => _configurationSection.GetValue("Port"); - public string PickupDirectoryLocation => _configurationSection.GetValue("PickupDirectoryLocation"); - public SmtpDeliveryMethod DeliveryMethod => _configurationSection.GetValue("DeliveryMethod"); + public bool IsSmtpServerConfigured => !string.IsNullOrWhiteSpace(SmtpSettings?.Host); - public string Username => _configurationSection.GetValue("Username"); - - public string Password => _configurationSection.GetValue("Password"); - } + [JsonPropertyName("Smtp")] + public SmtpSettings SmtpSettings { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/HostingSettings.cs b/src/Umbraco.Configuration/Models/HostingSettings.cs index f0fbcf4cab..e096a207da 100644 --- a/src/Umbraco.Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Configuration/Models/HostingSettings.cs @@ -1,22 +1,17 @@ -using Microsoft.Extensions.Configuration; +using System.Text.Json.Serialization; +using Microsoft.Extensions.Configuration; using Umbraco.Core; using Umbraco.Core.Configuration; namespace Umbraco.Configuration.Models { - internal class HostingSettings : IHostingSettings + public class HostingSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Hosting:"; - private readonly IConfiguration _configuration; - - public HostingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - /// - public LocalTempStorage LocalTempStorageLocation => - _configuration.GetValue(Prefix+"LocalTempStorage", LocalTempStorage.Default); + /// + /// Gets the configuration for the location of temporary files. + /// + [JsonPropertyName("LocalTempStorage")] + public LocalTempStorage LocalTempStorageLocation { get; set; } = LocalTempStorage.Default; public string ApplicationVirtualPath => null; @@ -24,6 +19,7 @@ namespace Umbraco.Configuration.Models /// Gets a value indicating whether umbraco is running in [debug mode]. /// /// true if [debug mode]; otherwise, false. - public bool DebugMode => _configuration.GetValue(Prefix+"Debug", false); + [JsonPropertyName("Debug")] + public bool DebugMode { get; set; } = false; } } diff --git a/src/Umbraco.Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Configuration/Models/ImagingCacheSettings.cs new file mode 100644 index 0000000000..05e3cb4677 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ImagingCacheSettings.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; + +namespace Umbraco.Configuration.Models +{ + public class ImagingCacheSettings + { + public int MaxBrowserCacheDays { get; set; } = 7; + + public int MaxCacheDays { get; set; } = 365; + + public uint CachedNameLength { get; set; } = 7; + + [JsonPropertyName("Folder")] + public string CacheFolder { get; set; } = "../App_Data/Cache"; + } +} diff --git a/src/Umbraco.Configuration/Models/ImagingResizeSettings.cs b/src/Umbraco.Configuration/Models/ImagingResizeSettings.cs new file mode 100644 index 0000000000..1d7424c4f2 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ImagingResizeSettings.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace Umbraco.Configuration.Models +{ + public class ImagingResizeSettings + { + [JsonPropertyName("MaxWidth")] + public int MaxResizeWidth { get; set; } = 5000; + + [JsonPropertyName("MaxHeight")] + public int MaxResizeHeight { get; set; } = 5000; + } +} diff --git a/src/Umbraco.Configuration/Models/ImagingSettings.cs b/src/Umbraco.Configuration/Models/ImagingSettings.cs index 4a9501b2ba..36a63d7766 100644 --- a/src/Umbraco.Configuration/Models/ImagingSettings.cs +++ b/src/Umbraco.Configuration/Models/ImagingSettings.cs @@ -1,26 +1,9 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class ImagingSettings : IImagingSettings + public class ImagingSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Imaging:"; - private const string CachePrefix = Prefix + "Cache:"; - private const string ResizePrefix = Prefix + "Resize:"; - private readonly IConfiguration _configuration; + public ImagingCacheSettings Cache { get; set; } - public ImagingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int MaxBrowserCacheDays => _configuration.GetValue(CachePrefix + "MaxBrowserCacheDays", 7); - public int MaxCacheDays => _configuration.GetValue(CachePrefix + "MaxCacheDays", 365); - public uint CachedNameLength => _configuration.GetValue(CachePrefix + "CachedNameLength", (uint) 8); - public string CacheFolder => _configuration.GetValue(CachePrefix + "Folder", "../App_Data/Cache"); - public int MaxResizeWidth => _configuration.GetValue(ResizePrefix + "MaxWidth", 5000); - public int MaxResizeHeight => _configuration.GetValue(ResizePrefix + "MaxHeight", 5000); + public ImagingResizeSettings Resize { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs b/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs index b4bb000552..7738527ed7 100644 --- a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs +++ b/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs @@ -1,20 +1,7 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class IndexCreatorSettings : IIndexCreatorSettings + public class IndexCreatorSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Examine:"; - private readonly IConfiguration _configuration; - - public IndexCreatorSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string LuceneDirectoryFactory => - _configuration.GetValue(Prefix + "LuceneDirectoryFactory"); + public string LuceneDirectoryFactory { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs b/src/Umbraco.Configuration/Models/KeepAliveSettings.cs index 04194e1a3c..c6f0b9a98c 100644 --- a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs +++ b/src/Umbraco.Configuration/Models/KeepAliveSettings.cs @@ -1,23 +1,11 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Configuration.Models { - internal class KeepAliveSettings : IKeepAliveSettings + public class KeepAliveSettings : IKeepAliveSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "KeepAlive:"; - private readonly IConfiguration _configuration; + public bool DisableKeepAliveTask { get; set; } = false; - public KeepAliveSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool DisableKeepAliveTask => - _configuration.GetValue(Prefix + "DisableKeepAliveTask", false); - - public string KeepAlivePingUrl => _configuration.GetValue(Prefix + "KeepAlivePingUrl", - "{umbracoApplicationUrl}/api/keepalive/ping"); + public string KeepAlivePingUrl { get; set; } = "{umbracoApplicationUrl}/api/keepalive/ping"; } } diff --git a/src/Umbraco.Configuration/Models/LoggingSettings.cs b/src/Umbraco.Configuration/Models/LoggingSettings.cs index b05fe03875..9cc0a084d2 100644 --- a/src/Umbraco.Configuration/Models/LoggingSettings.cs +++ b/src/Umbraco.Configuration/Models/LoggingSettings.cs @@ -1,19 +1,7 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class LoggingSettings : ILoggingSettings + public class LoggingSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Logging:"; - private readonly IConfiguration _configuration; - - public LoggingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int MaxLogAge => _configuration.GetValue(Prefix + "MaxLogAge", -1); + public int MaxLogAge { get; set; } = -1; } } diff --git a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs index 5a8313a351..32bed610fb 100644 --- a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs +++ b/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs @@ -1,38 +1,21 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core; namespace Umbraco.Configuration.Models { - internal class MemberPasswordConfigurationSettings : IMemberPasswordConfiguration + public class MemberPasswordConfigurationSettings { - private const string Prefix = Constants.Configuration.ConfigSecurityPrefix + "MemberPassword:"; - private readonly IConfiguration _configuration; + public int RequiredLength { get; set; } = 10; - public MemberPasswordConfigurationSettings(IConfiguration configuration) - { - _configuration = configuration; - } + public bool RequireNonLetterOrDigit { get; set; } = false; - public int RequiredLength => - _configuration.GetValue(Prefix + "RequiredLength", 10); + public bool RequireDigit { get; set; } = false; - public bool RequireNonLetterOrDigit => - _configuration.GetValue(Prefix + "RequireNonLetterOrDigit", false); + public bool RequireLowercase { get; set; } = false; - public bool RequireDigit => - _configuration.GetValue(Prefix + "RequireDigit", false); + public bool RequireUppercase { get; set; } = false; - public bool RequireLowercase => - _configuration.GetValue(Prefix + "RequireLowercase", false); + public string HashAlgorithmType { get; set; } = Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName; - public bool RequireUppercase => - _configuration.GetValue(Prefix + "RequireUppercase", false); - - public string HashAlgorithmType => - _configuration.GetValue(Prefix + "HashAlgorithmType", Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName); // TODO: Need to change to current format when we do members - - public int MaxFailedAccessAttemptsBeforeLockout => - _configuration.GetValue(Prefix + "MaxFailedAccessAttemptsBeforeLockout", 5); + public int MaxFailedAccessAttemptsBeforeLockout { get; set; } = 5; } } diff --git a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs b/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs index d111dbba70..d580ba1b7c 100644 --- a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs +++ b/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs @@ -7,20 +7,9 @@ namespace Umbraco.Configuration.Models /// /// Represents the models builder configuration. /// - internal class ModelsBuilderConfig : IModelsBuilderConfig + public class ModelsBuilderConfig { - private const string Prefix = Constants.Configuration.ConfigModelsBuilderPrefix; - private readonly IConfiguration _configuration; - - /// - /// Initializes a new instance of the class. - /// - public ModelsBuilderConfig(IConfiguration configuration) - { - _configuration = configuration; - } - - public string DefaultModelsDirectory => "~/App_Data/Models"; + public static string DefaultModelsDirectory => "~/App_Data/Models"; /// /// Gets a value indicating whether the whole models experience is enabled. @@ -29,25 +18,26 @@ namespace Umbraco.Configuration.Models /// If this is false then absolutely nothing happens. /// Default value is false which means that unless we have this setting, nothing happens. /// - public bool Enable => _configuration.GetValue(Prefix+"Enable", false); + public bool Enable { get; set; } = false; /// /// Gets the models mode. /// - public ModelsMode ModelsMode => - _configuration.GetValue(Prefix+"ModelsMode", ModelsMode.Nothing); + public ModelsMode ModelsMode { get; set; } = ModelsMode.Nothing; /// /// Gets the models namespace. /// /// That value could be overriden by other (attribute in user's code...). Return default if no value was supplied. - public string ModelsNamespace => _configuration.GetValue(Prefix+"ModelsNamespace"); + public string ModelsNamespace { get; set; } /// /// Gets a value indicating whether we should enable the models factory. /// /// Default value is true because no factory is enabled by default in Umbraco. - public bool EnableFactory => _configuration.GetValue(Prefix+"EnableFactory", true); + public bool EnableFactory { get; set; } = true; + + private bool _flagOutOfDateModels; /// /// Gets a value indicating whether we should flag out-of-date models. @@ -57,15 +47,26 @@ namespace Umbraco.Configuration.Models /// setting is activated the ~/App_Data/Models/ood.txt file is then created. When models are /// generated through the dashboard, the files is cleared. Default value is false. /// - public bool FlagOutOfDateModels => - _configuration.GetValue(Prefix+"FlagOutOfDateModels", false) && !ModelsMode.IsLive(); + public bool FlagOutOfDateModels + { + get => _flagOutOfDateModels; + + set + { + if (!ModelsMode.IsLive()) + { + _flagOutOfDateModels = false; + } + + _flagOutOfDateModels = value; + } + } /// /// Gets the models directory. /// /// Default is ~/App_Data/Models but that can be changed. - public string ModelsDirectory => - _configuration.GetValue(Prefix+"ModelsDirectory", "~/App_Data/Models"); + public string ModelsDirectory { get; set; } = DefaultModelsDirectory; /// /// Gets a value indicating whether to accept an unsafe value for ModelsDirectory. @@ -74,13 +75,12 @@ namespace Umbraco.Configuration.Models /// An unsafe value is an absolute path, or a relative path pointing outside /// of the website root. /// - public bool AcceptUnsafeModelsDirectory => - _configuration.GetValue(Prefix+"AcceptUnsafeModelsDirectory", false); + public bool AcceptUnsafeModelsDirectory { get; set; } = false; /// /// Gets a value indicating the debug log level. /// /// 0 means minimal (safe on live site), anything else means more and more details (maybe not safe). - public int DebugLevel => _configuration.GetValue(Prefix+"DebugLevel", 0); + public int DebugLevel { get; set; } = 0; } } diff --git a/src/Umbraco.Configuration/Models/NuCacheSettings.cs b/src/Umbraco.Configuration/Models/NuCacheSettings.cs index 51b8b1fe08..0077146620 100644 --- a/src/Umbraco.Configuration/Models/NuCacheSettings.cs +++ b/src/Umbraco.Configuration/Models/NuCacheSettings.cs @@ -1,19 +1,7 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class NuCacheSettings : INuCacheSettings + public class NuCacheSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "NuCache:"; - private readonly IConfiguration _configuration; - - public NuCacheSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string BTreeBlockSize => _configuration.GetValue(Prefix+"BTreeBlockSize"); + public string BTreeBlockSize { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/RuntimeSettings.cs b/src/Umbraco.Configuration/Models/RuntimeSettings.cs index ef129030b6..367a6c53a3 100644 --- a/src/Umbraco.Configuration/Models/RuntimeSettings.cs +++ b/src/Umbraco.Configuration/Models/RuntimeSettings.cs @@ -1,19 +1,9 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class RuntimeSettings : IRuntimeSettings + public class RuntimeSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Runtime:"; - private readonly IConfiguration _configuration; - public RuntimeSettings(IConfiguration configuration) - { - _configuration = configuration; - } + public int? MaxQueryStringLength { get; set; } - public int? MaxQueryStringLength => _configuration.GetValue(Prefix+"MaxRequestLength"); - public int? MaxRequestLength => _configuration.GetValue(Prefix+"MaxRequestLength"); + public int? MaxRequestLength { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/SecuritySettings.cs b/src/Umbraco.Configuration/Models/SecuritySettings.cs index 297c95b1af..12ea6b7c17 100644 --- a/src/Umbraco.Configuration/Models/SecuritySettings.cs +++ b/src/Umbraco.Configuration/Models/SecuritySettings.cs @@ -1,33 +1,17 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class SecuritySettings : ISecuritySettings + public class SecuritySettings { - private const string Prefix = Constants.Configuration.ConfigSecurityPrefix; - private readonly IConfiguration _configuration; + public bool KeepUserLoggedIn { get; set; } = false; - public SecuritySettings(IConfiguration configuration) - { - _configuration = configuration; - } + public bool HideDisabledUsersInBackoffice { get; set; } = false; - public bool KeepUserLoggedIn => _configuration.GetValue(Prefix + "KeepUserLoggedIn", false); + public bool AllowPasswordReset { get; set; } = true; - public bool HideDisabledUsersInBackoffice => - _configuration.GetValue(Prefix + "HideDisabledUsersInBackoffice", false); + public string AuthCookieName { get; set; } = "UMB_UCONTEXT"; - public bool AllowPasswordReset => - _configuration.GetValue(Prefix + "AllowPasswordResetAllowPasswordReset", true); + public string AuthCookieDomain { get; set; } - public string AuthCookieName => - _configuration.GetValue(Prefix + "AuthCookieName", "UMB_UCONTEXT"); - - public string AuthCookieDomain => - _configuration.GetValue(Prefix + "AuthCookieDomain"); - - public bool UsernameIsEmail => _configuration.GetValue(Prefix + "UsernameIsEmail", true); + public bool UsernameIsEmail { get; set; } = true; } } diff --git a/src/Umbraco.Configuration/Models/SmtpSettings.cs b/src/Umbraco.Configuration/Models/SmtpSettings.cs new file mode 100644 index 0000000000..c4a874c5ae --- /dev/null +++ b/src/Umbraco.Configuration/Models/SmtpSettings.cs @@ -0,0 +1,21 @@ +using System.Net.Mail; + +namespace Umbraco.Configuration.Models +{ + public class SmtpSettings + { + public string From { get; set; } + + public string Host { get; set; } + + public int Port { get; set; } + + public string PickupDirectoryLocation { get; set; } + + public SmtpDeliveryMethod DeliveryMethod { get; set; } + + public string Username { get; set; } + + public string Password { get; set; } + } +} diff --git a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs b/src/Umbraco.Configuration/Models/TypeFinderSettings.cs index 8a1f7ac9e0..65690f9668 100644 --- a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs +++ b/src/Umbraco.Configuration/Models/TypeFinderSettings.cs @@ -1,20 +1,7 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models +namespace Umbraco.Configuration.Models { - internal class TypeFinderSettings : ITypeFinderSettings + public class TypeFinderSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "TypeFinder:"; - private readonly IConfiguration _configuration; - - public TypeFinderSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string AssembliesAcceptingLoadExceptions => - _configuration.GetValue(Prefix+"AssembliesAcceptingLoadExceptions"); + public string AssembliesAcceptingLoadExceptions { get; set; } } } diff --git a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs index 25ce3e3d9a..81724f9259 100644 --- a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs +++ b/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs @@ -1,36 +1,22 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; +using Umbraco.Core; using Umbraco.Core.Configuration; namespace Umbraco.Configuration.Models { - internal class UserPasswordConfigurationSettings : IUserPasswordConfiguration + public class UserPasswordConfigurationSettings { - private const string Prefix = Constants.Configuration.ConfigSecurityPrefix + "UserPassword:"; - private readonly IConfiguration _configuration; + public int RequiredLength { get; set; } = 10; - public UserPasswordConfigurationSettings(IConfiguration configuration) - { - _configuration = configuration; - } + public bool RequireNonLetterOrDigit { get; set; } = false; - public int RequiredLength => _configuration.GetValue(Prefix + "RequiredLength", 10); + public bool RequireDigit { get; set; } = false; - public bool RequireNonLetterOrDigit => - _configuration.GetValue(Prefix + "RequireNonLetterOrDigit", false); + public bool RequireLowercase { get; set; } = false; - public bool RequireDigit => _configuration.GetValue(Prefix + "RequireDigit", false); + public bool RequireUppercase { get; set; } = false; - public bool RequireLowercase => - _configuration.GetValue(Prefix + "RequireLowercase", false); + public string HashAlgorithmType { get; set; } = Constants.Security.AspNetCoreV3PasswordHashAlgorithmName; - public bool RequireUppercase => - _configuration.GetValue(Prefix + "RequireUppercase", false); - - public string HashAlgorithmType => - _configuration.GetValue(Prefix + "HashAlgorithmType", Constants.Security.AspNetCoreV3PasswordHashAlgorithmName); - - public int MaxFailedAccessAttemptsBeforeLockout => - _configuration.GetValue(Prefix + "MaxFailedAccessAttemptsBeforeLockout", 5); + public int MaxFailedAccessAttemptsBeforeLockout { get; set; } = 5; } } diff --git a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs b/src/Umbraco.Configuration/Models/WebRoutingSettings.cs index 9ac856ca9f..d0e36b4241 100644 --- a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs +++ b/src/Umbraco.Configuration/Models/WebRoutingSettings.cs @@ -1,42 +1,23 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Configuration.Models { - internal class WebRoutingSettings : IWebRoutingSettings + public class WebRoutingSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "WebRouting:"; - private readonly IConfiguration _configuration; + public bool TrySkipIisCustomErrors { get; set; } = false; - public WebRoutingSettings(IConfiguration configuration) - { - _configuration = configuration; - } + public bool InternalRedirectPreservesTemplate { get; set; } = false; - public bool TrySkipIisCustomErrors => - _configuration.GetValue(Prefix + "TrySkipIisCustomErrors", false); + public bool DisableAlternativeTemplates { get; set; } = false; - public bool InternalRedirectPreservesTemplate => - _configuration.GetValue(Prefix + "InternalRedirectPreservesTemplate", false); + public bool ValidateAlternativeTemplates { get; set; } = false; - public bool DisableAlternativeTemplates => - _configuration.GetValue(Prefix + "DisableAlternativeTemplates", false); + public bool DisableFindContentByIdPath { get; set; } = false; - public bool ValidateAlternativeTemplates => - _configuration.GetValue(Prefix + "ValidateAlternativeTemplates", false); + public bool DisableRedirectUrlTracking { get; set; } = false; - public bool DisableFindContentByIdPath => - _configuration.GetValue(Prefix + "DisableFindContentByIdPath", false); + public string UrlProviderMode { get; set; } = UrlMode.Auto.ToString(); - public bool DisableRedirectUrlTracking => - _configuration.GetValue(Prefix + "DisableRedirectUrlTracking", false); - - public string UrlProviderMode => - _configuration.GetValue(Prefix + "UrlProviderMode", UrlMode.Auto.ToString()); - - public string UmbracoApplicationUrl => - _configuration.GetValue(Prefix + "UmbracoApplicationUrl"); + public string UmbracoApplicationUrl { get; set; } } } diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 94e9062902..cbc374f93b 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -1,12 +1,9 @@ using System; using System.Data.Common; using System.Data.SqlClient; -using System.Globalization; using System.IO; -using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; @@ -28,13 +25,11 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Runtime; using Umbraco.Web.Common.AspNetCore; -using Umbraco.Web.Common.Extensions; using Umbraco.Web.Common.Profiler; +using CoreDebugSettings = Umbraco.Configuration.Models.CoreDebugSettings; namespace Umbraco.Extensions { - - public static class UmbracoCoreServiceCollectionExtensions { /// @@ -107,6 +102,24 @@ namespace Umbraco.Extensions if (configuration == null) throw new ArgumentNullException(nameof(configuration)); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Core:Debug")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigModelsBuilderPrefix)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging:")); var configsFactory = new AspNetCoreConfigsFactory(configuration); var configs = configsFactory.Create(); From e3a44c6717cf11946ae923636f1f145017bde549 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 20 Aug 2020 22:18:50 +0100 Subject: [PATCH 03/58] Moved configuration setting POCOs into Umbraco.Core and adjusted references. Amended injection of some settings to use IOptionsSnapshot. --- .../AspNetCoreConfigsFactory.cs | 2 +- ...nsions.cs => ContentSettingsExtensions.cs} | 16 ++++---- .../Models/ActiveDirectorySettings.cs | 2 +- .../Models/ContentImagingSettings.cs | 2 +- .../Models/ContentNotificationSettings.cs | 2 +- .../Configuration}/Models/ContentSettings.cs | 10 ++--- .../Models/CoreDebugSettings.cs | 2 +- .../Models/ExceptionFilterSettings.cs | 2 +- .../Configuration}/Models/GlobalSettings.cs | 2 +- .../Configuration}/Models/HostingSettings.cs | 5 +-- .../Models/ImagingCacheSettings.cs | 2 +- .../Models/ImagingResizeSettings.cs | 5 ++- .../Configuration}/Models/ImagingSettings.cs | 2 +- .../Models/IndexCreatorSettings.cs | 2 +- .../Models/KeepAliveSettings.cs | 2 +- .../Configuration}/Models/LoggingSettings.cs | 2 +- .../MemberPasswordConfigurationSettings.cs | 5 ++- .../Models/ModelsBuilderConfig.cs | 6 +-- .../Configuration}/Models/NuCacheSettings.cs | 2 +- .../Configuration}/Models/RuntimeSettings.cs | 2 +- .../Configuration}/Models/SecuritySettings.cs | 2 +- .../Configuration}/Models/SmtpSettings.cs | 2 +- .../Configuration}/Models/TourSettings.cs | 2 +- .../Models/TypeFinderSettings.cs | 2 +- .../UserPasswordConfigurationSettings.cs | 4 +- .../Models/WebRoutingSettings.cs | 2 +- src/Umbraco.Core/Editors/BackOfficeModel.cs | 38 ------------------- src/Umbraco.Core/Models/MediaExtensions.cs | 6 +-- src/Umbraco.Core/Scheduling/KeepAlive.cs | 15 ++++++-- src/Umbraco.Core/Templates/HtmlUrlParser.cs | 9 +++-- src/Umbraco.Core/Umbraco.Core.csproj | 2 + .../BackOffice/BackOfficeUserManager.cs | 7 ++-- .../Configuration/JsonConfigManipulator.cs | 1 + .../EmailNotificationMethod.cs | 18 ++++++--- .../Install/InstallSteps/NewInstallStep.cs | 25 ++++++++---- .../Enrichers/ThreadAbortExceptionEnricher.cs | 9 +++-- .../Media/UploadAutoFillProperties.cs | 19 ++++++++-- .../Models/Mapping/DataTypeMapDefinition.cs | 9 +++-- .../Mapping/MemberTabsAndPropertiesMapper.cs | 13 ++++--- .../Repositories/Implement/UserRepository.cs | 35 ++++++++++++++++- .../FileUploadPropertyEditor.cs | 27 +++++++++++-- .../FileUploadPropertyValueEditor.cs | 26 +++++++++++-- .../ImageCropperPropertyEditor.cs | 34 +++++++++++++++-- .../ImageCropperPropertyValueEditor.cs | 14 +++++-- .../UploadFileTypeValidator.cs | 16 +++++--- .../Routing/ContentFinderByConfigured404.cs | 17 ++++++--- .../Scheduling/LogScrubber.cs | 15 ++++++-- .../Scheduling/SchedulerComponent.cs | 18 ++++----- src/Umbraco.Infrastructure/Scoping/Scope.cs | 10 ++--- .../Scoping/ScopeProvider.cs | 14 ++++--- .../Services/Implement/NotificationService.cs | 23 ++++++----- .../Umbraco.Infrastructure.csproj | 3 +- src/Umbraco.Tests.Common/TestHelperBase.cs | 3 +- .../Repositories/UserRepositoryTest.cs | 5 ++- .../ContentElementDefaultTests.cs | 2 +- .../UmbracoSettings/ContentElementTests.cs | 3 +- .../Components/ComponentTests.cs | 3 +- src/Umbraco.Tests/Models/MediaXmlTest.cs | 3 +- .../Repositories/UserRepositoryTest.cs | 3 +- .../Routing/MediaUrlProviderTests.cs | 7 ++-- .../BackOfficeOwinUserManagerTests.cs | 10 +++-- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 3 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 3 +- .../Controllers/AuthenticationController.cs | 24 ++++++------ .../Controllers/BackOfficeServerVariables.cs | 37 +++++++++--------- .../Controllers/CurrentUserController.cs | 21 +++++----- .../Controllers/DataTypeController.cs | 19 +++++----- .../Controllers/ImagesController.cs | 10 +++-- .../Controllers/MediaController.cs | 35 +++++++++-------- .../Controllers/MemberController.cs | 22 +++++------ .../Controllers/TinyMceController.cs | 12 +++--- .../Controllers/TourController.cs | 3 +- .../Controllers/UsersController.cs | 36 +++++++++--------- ...coBackOfficeServiceCollectionExtensions.cs | 5 ++- .../Mapping/MediaMapDefinition.cs | 14 +++---- .../ConfigureBackOfficeCookieOptions.cs | 18 ++++----- .../ConfigureBackOfficeIdentityOptions.cs | 7 ++-- .../AspNetCore/UmbracoViewPage.cs | 5 ++- .../UmbracoCoreServiceCollectionExtensions.cs | 2 +- .../Filters/ModelBindingExceptionFilter.cs | 9 +++-- .../Macros/MacroRenderer.cs | 10 ++--- .../Runtime/AspNetCoreComposer.cs | 4 +- .../Editors/AuthenticationController.cs | 31 +++++++-------- .../Editors/BackOfficeController.cs | 27 ++++++------- .../Editors/BackOfficeServerVariables.cs | 26 ++++++------- .../BackOfficeCookieAuthenticationProvider.cs | 28 ++++++-------- .../Security/BackOfficeOwinUserManager.cs | 11 +++--- .../Security/GetUserSecondsMiddleWare.cs | 15 ++++---- src/Umbraco.Web/UmbracoDefaultOwinStartup.cs | 8 ++-- .../CDF/ClientDependencyComponent.cs | 12 +++--- 90 files changed, 575 insertions(+), 433 deletions(-) rename src/Umbraco.Core/Configuration/{UmbracoSettings/ContentSectionExtensions.cs => ContentSettingsExtensions.cs} (74%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ActiveDirectorySettings.cs (81%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ContentImagingSettings.cs (96%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ContentNotificationSettings.cs (79%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ContentSettings.cs (92%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/CoreDebugSettings.cs (79%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ExceptionFilterSettings.cs (69%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/GlobalSettings.cs (98%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/HostingSettings.cs (84%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ImagingCacheSettings.cs (89%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ImagingResizeSettings.cs (74%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ImagingSettings.cs (77%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/IndexCreatorSettings.cs (70%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/KeepAliveSettings.cs (86%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/LoggingSettings.cs (67%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/MemberPasswordConfigurationSettings.cs (77%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ModelsBuilderConfig.cs (95%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/NuCacheSettings.cs (68%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/RuntimeSettings.cs (76%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/SecuritySettings.cs (90%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/SmtpSettings.cs (90%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/TourSettings.cs (68%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/TypeFinderSettings.cs (72%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/UserPasswordConfigurationSettings.cs (82%) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/WebRoutingSettings.cs (93%) delete mode 100644 src/Umbraco.Core/Editors/BackOfficeModel.cs diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index b388579687..45d6498ff4 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; using ConnectionStrings = Umbraco.Configuration.Models.ConnectionStrings; -using CoreDebugSettings = Umbraco.Configuration.Models.CoreDebugSettings; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Configuration { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs similarity index 74% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs rename to src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs index d100eb0a74..1c24d0eb6c 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs +++ b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs @@ -1,9 +1,11 @@ using System; using System.Linq; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration.UmbracoSettings; -namespace Umbraco.Core.Configuration.UmbracoSettings +namespace Umbraco.Core.Configuration { - public static class ContentSectionExtensions + public static class ContentSettingsExtensions { /// /// Gets a value indicating whether the file extension corresponds to an image. @@ -11,12 +13,12 @@ namespace Umbraco.Core.Configuration.UmbracoSettings /// The file extension. /// /// A value indicating whether the file extension corresponds to an image. - public static bool IsImageFile(this IContentSettings contentConfig, string extension) + public static bool IsImageFile(this ContentSettings contentConfig, string extension) { if (contentConfig == null) throw new ArgumentNullException(nameof(contentConfig)); if (extension == null) return false; extension = extension.TrimStart('.'); - return contentConfig.ImageFileTypes.InvariantContains(extension); + return contentConfig.Imaging.ImageFileTypes.InvariantContains(extension); } /// @@ -24,7 +26,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings /// held in settings. /// Allow upload if extension is whitelisted OR if there is no whitelist and extension is NOT blacklisted. /// - public static bool IsFileAllowedForUpload(this IContentSettings contentSettings, string extension) + public static bool IsFileAllowedForUpload(this ContentSettings contentSettings, string extension) { return contentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)) || (contentSettings.AllowedUploadFiles.Any() == false && @@ -37,9 +39,9 @@ namespace Umbraco.Core.Configuration.UmbracoSettings /// /// The property type alias. /// The auto-fill configuration for the specified property alias, or null. - public static IImagingAutoFillUploadField GetConfig(this IContentSettings contentSettings, string propertyTypeAlias) + public static IImagingAutoFillUploadField GetConfig(this ContentSettings contentSettings, string propertyTypeAlias) { - var autoFillConfigs = contentSettings.ImageAutoFillProperties; + var autoFillConfigs = contentSettings.Imaging.ImageAutoFillProperties; return autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias); } } diff --git a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs similarity index 81% rename from src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs rename to src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs index d7d2de1490..4eb2c774bf 100644 --- a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ActiveDirectorySettings { diff --git a/src/Umbraco.Configuration/Models/ContentImagingSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs similarity index 96% rename from src/Umbraco.Configuration/Models/ContentImagingSettings.cs rename to src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs index f38e4194e8..7ec8bf219f 100644 --- a/src/Umbraco.Configuration/Models/ContentImagingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ContentImagingSettings { diff --git a/src/Umbraco.Configuration/Models/ContentNotificationSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs similarity index 79% rename from src/Umbraco.Configuration/Models/ContentNotificationSettings.cs rename to src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs index 96f6baddff..0ae1ffd991 100644 --- a/src/Umbraco.Configuration/Models/ContentNotificationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ContentNotificationSettings { diff --git a/src/Umbraco.Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs similarity index 92% rename from src/Umbraco.Configuration/Models/ContentSettings.cs rename to src/Umbraco.Core/Configuration/Models/ContentSettings.cs index 945dc14728..d1664c2985 100644 --- a/src/Umbraco.Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -1,19 +1,13 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text.Json.Serialization; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Macros; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ContentSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Content:"; - private const string NotificationsPrefix = Prefix + "Notifications:"; - private const string ImagingPrefix = Prefix + "Imaging:"; private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; @@ -47,6 +41,7 @@ namespace Umbraco.Configuration.Models public string LoginBackgroundImage { get; set; } = "assets/img/login.jpg"; + /* private class ContentErrorPage : IContentErrorPage { public ContentErrorPage(IConfigurationSection configurationSection) @@ -78,5 +73,6 @@ namespace Umbraco.Configuration.Models public bool HasContentKey { get; } public string Culture { get; set; } } + */ } } diff --git a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs b/src/Umbraco.Core/Configuration/Models/CoreDebugSettings.cs similarity index 79% rename from src/Umbraco.Configuration/Models/CoreDebugSettings.cs rename to src/Umbraco.Core/Configuration/Models/CoreDebugSettings.cs index e95a432dd4..2b13609509 100644 --- a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/CoreDebugSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class CoreDebugSettings { diff --git a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs b/src/Umbraco.Core/Configuration/Models/ExceptionFilterSettings.cs similarity index 69% rename from src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs rename to src/Umbraco.Core/Configuration/Models/ExceptionFilterSettings.cs index d5fe64abce..6b8f74bef0 100644 --- a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ExceptionFilterSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ExceptionFilterSettings { diff --git a/src/Umbraco.Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs similarity index 98% rename from src/Umbraco.Configuration/Models/GlobalSettings.cs rename to src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index fcedd504c9..6a7411c733 100644 --- a/src/Umbraco.Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { /// /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information diff --git a/src/Umbraco.Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs similarity index 84% rename from src/Umbraco.Configuration/Models/HostingSettings.cs rename to src/Umbraco.Core/Configuration/Models/HostingSettings.cs index e096a207da..a774a948ea 100644 --- a/src/Umbraco.Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -1,9 +1,6 @@ using System.Text.Json.Serialization; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class HostingSettings { diff --git a/src/Umbraco.Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs similarity index 89% rename from src/Umbraco.Configuration/Models/ImagingCacheSettings.cs rename to src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs index 05e3cb4677..9c2fd4bf37 100644 --- a/src/Umbraco.Configuration/Models/ImagingCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingCacheSettings { diff --git a/src/Umbraco.Configuration/Models/ImagingResizeSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs similarity index 74% rename from src/Umbraco.Configuration/Models/ImagingResizeSettings.cs rename to src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs index 1d7424c4f2..6b445d8c40 100644 --- a/src/Umbraco.Configuration/Models/ImagingResizeSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs @@ -1,6 +1,7 @@ -using System.Text.Json.Serialization; + +using System.Text.Json.Serialization; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingResizeSettings { diff --git a/src/Umbraco.Configuration/Models/ImagingSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingSettings.cs similarity index 77% rename from src/Umbraco.Configuration/Models/ImagingSettings.cs rename to src/Umbraco.Core/Configuration/Models/ImagingSettings.cs index 36a63d7766..afc55561bb 100644 --- a/src/Umbraco.Configuration/Models/ImagingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingSettings { diff --git a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs b/src/Umbraco.Core/Configuration/Models/IndexCreatorSettings.cs similarity index 70% rename from src/Umbraco.Configuration/Models/IndexCreatorSettings.cs rename to src/Umbraco.Core/Configuration/Models/IndexCreatorSettings.cs index 7738527ed7..fcc22de9a3 100644 --- a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/IndexCreatorSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class IndexCreatorSettings { diff --git a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs b/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs similarity index 86% rename from src/Umbraco.Configuration/Models/KeepAliveSettings.cs rename to src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs index c6f0b9a98c..188c4c5739 100644 --- a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs @@ -1,6 +1,6 @@ using Umbraco.Core.Configuration.UmbracoSettings; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class KeepAliveSettings : IKeepAliveSettings { diff --git a/src/Umbraco.Configuration/Models/LoggingSettings.cs b/src/Umbraco.Core/Configuration/Models/LoggingSettings.cs similarity index 67% rename from src/Umbraco.Configuration/Models/LoggingSettings.cs rename to src/Umbraco.Core/Configuration/Models/LoggingSettings.cs index 9cc0a084d2..414ff06b57 100644 --- a/src/Umbraco.Configuration/Models/LoggingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/LoggingSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class LoggingSettings { diff --git a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs b/src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs similarity index 77% rename from src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs rename to src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs index 32bed610fb..1f2808ef7e 100644 --- a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs @@ -1,8 +1,9 @@ using Umbraco.Core; +using Umbraco.Core.Configuration; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { - public class MemberPasswordConfigurationSettings + public class MemberPasswordConfigurationSettings : IPasswordConfiguration { public int RequiredLength { get; set; } = 10; diff --git a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs b/src/Umbraco.Core/Configuration/Models/ModelsBuilderConfig.cs similarity index 95% rename from src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs rename to src/Umbraco.Core/Configuration/Models/ModelsBuilderConfig.cs index d580ba1b7c..e99557755c 100644 --- a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs +++ b/src/Umbraco.Core/Configuration/Models/ModelsBuilderConfig.cs @@ -1,8 +1,6 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Configuration; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { /// /// Represents the models builder configuration. diff --git a/src/Umbraco.Configuration/Models/NuCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs similarity index 68% rename from src/Umbraco.Configuration/Models/NuCacheSettings.cs rename to src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs index 0077146620..a2bc7d3561 100644 --- a/src/Umbraco.Configuration/Models/NuCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class NuCacheSettings { diff --git a/src/Umbraco.Configuration/Models/RuntimeSettings.cs b/src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs similarity index 76% rename from src/Umbraco.Configuration/Models/RuntimeSettings.cs rename to src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs index 367a6c53a3..f93530b490 100644 --- a/src/Umbraco.Configuration/Models/RuntimeSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class RuntimeSettings { diff --git a/src/Umbraco.Configuration/Models/SecuritySettings.cs b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs similarity index 90% rename from src/Umbraco.Configuration/Models/SecuritySettings.cs rename to src/Umbraco.Core/Configuration/Models/SecuritySettings.cs index 12ea6b7c17..5295abb368 100644 --- a/src/Umbraco.Configuration/Models/SecuritySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class SecuritySettings { diff --git a/src/Umbraco.Configuration/Models/SmtpSettings.cs b/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs similarity index 90% rename from src/Umbraco.Configuration/Models/SmtpSettings.cs rename to src/Umbraco.Core/Configuration/Models/SmtpSettings.cs index c4a874c5ae..a507f8a62f 100644 --- a/src/Umbraco.Configuration/Models/SmtpSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs @@ -1,6 +1,6 @@ using System.Net.Mail; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class SmtpSettings { diff --git a/src/Umbraco.Configuration/Models/TourSettings.cs b/src/Umbraco.Core/Configuration/Models/TourSettings.cs similarity index 68% rename from src/Umbraco.Configuration/Models/TourSettings.cs rename to src/Umbraco.Core/Configuration/Models/TourSettings.cs index a9cfaa8987..895eff6dee 100644 --- a/src/Umbraco.Configuration/Models/TourSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/TourSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class TourSettings { diff --git a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs b/src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs similarity index 72% rename from src/Umbraco.Configuration/Models/TypeFinderSettings.cs rename to src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs index 65690f9668..c5210f6c8e 100644 --- a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class TypeFinderSettings { diff --git a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs b/src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs similarity index 82% rename from src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs rename to src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs index 81724f9259..a0c26b2410 100644 --- a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs @@ -1,9 +1,9 @@ using Umbraco.Core; using Umbraco.Core.Configuration; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { - public class UserPasswordConfigurationSettings + public class UserPasswordConfigurationSettings : IPasswordConfiguration { public int RequiredLength { get; set; } = 10; diff --git a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs b/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs similarity index 93% rename from src/Umbraco.Configuration/Models/WebRoutingSettings.cs rename to src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs index d0e36b4241..7e0c4d5d8c 100644 --- a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs @@ -1,6 +1,6 @@ using Umbraco.Core.Models.PublishedContent; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class WebRoutingSettings { diff --git a/src/Umbraco.Core/Editors/BackOfficeModel.cs b/src/Umbraco.Core/Editors/BackOfficeModel.cs deleted file mode 100644 index be91654d9e..0000000000 --- a/src/Umbraco.Core/Editors/BackOfficeModel.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Web.Features; -using Umbraco.Web.Trees; - -namespace Umbraco.Web.Editors -{ - // TODO: Almost nothing here needs to exist since we can inject these into the view - public class BackOfficeModel - { - public BackOfficeModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, - IContentSettings contentSettings, - IHostingEnvironment hostingEnvironment, - IRuntimeSettings runtimeSettings, ISecuritySettings securitySettings) - { - Features = features; - GlobalSettings = globalSettings; - UmbracoVersion = umbracoVersion; - ContentSettings = contentSettings; - HostingEnvironment = hostingEnvironment; - RuntimeSettings = runtimeSettings; - SecuritySettings = securitySettings; - BackOfficePath = GlobalSettings.GetBackOfficePath(HostingEnvironment); - } - - public UmbracoFeatures Features { get; } - public IGlobalSettings GlobalSettings { get; } - public IUmbracoVersion UmbracoVersion { get; } - public IContentSettings ContentSettings { get; } - public IHostingEnvironment HostingEnvironment { get; } - public IRuntimeSettings RuntimeSettings { get; set; } - public ISecuritySettings SecuritySettings { get; set; } - - public string BackOfficePath { get; } - } -} diff --git a/src/Umbraco.Core/Models/MediaExtensions.cs b/src/Umbraco.Core/Models/MediaExtensions.cs index ffcc2c2a92..aa7a48d8f4 100644 --- a/src/Umbraco.Core/Models/MediaExtensions.cs +++ b/src/Umbraco.Core/Models/MediaExtensions.cs @@ -1,5 +1,5 @@ using System.Linq; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Models @@ -27,9 +27,9 @@ namespace Umbraco.Core.Models /// /// Gets the urls of a media item. /// - public static string[] GetUrls(this IMedia media, IContentSettings contentSettings, MediaUrlGeneratorCollection mediaUrlGenerators) + public static string[] GetUrls(this IMedia media, ContentSettings contentSettings, MediaUrlGeneratorCollection mediaUrlGenerators) { - return contentSettings.ImageAutoFillProperties + return contentSettings.Imaging.ImageAutoFillProperties .Select(field => media.GetUrl(field.Alias, mediaUrlGenerators)) .Where(link => string.IsNullOrWhiteSpace(link) == false) .ToArray(); diff --git a/src/Umbraco.Core/Scheduling/KeepAlive.cs b/src/Umbraco.Core/Scheduling/KeepAlive.cs index a47080912c..d085569e97 100644 --- a/src/Umbraco.Core/Scheduling/KeepAlive.cs +++ b/src/Umbraco.Core/Scheduling/KeepAlive.cs @@ -2,8 +2,9 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Sync; @@ -13,13 +14,19 @@ namespace Umbraco.Web.Scheduling { private readonly IRequestAccessor _requestAccessor; private readonly IMainDom _mainDom; - private readonly IKeepAliveSettings _keepAliveSettings; + private readonly KeepAliveSettings _keepAliveSettings; private readonly IProfilingLogger _logger; private readonly IServerRegistrar _serverRegistrar; private static HttpClient _httpClient; public KeepAlive(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IRequestAccessor requestAccessor, IMainDom mainDom, IKeepAliveSettings keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) + IRequestAccessor requestAccessor, IMainDom mainDom, IOptionsSnapshot keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) + : this(runner, delayMilliseconds, periodMilliseconds, requestAccessor, mainDom, keepAliveSettings.Value, logger, serverRegistrar) + { + } + + public KeepAlive(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, + IRequestAccessor requestAccessor, IMainDom mainDom, KeepAliveSettings keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) : base(runner, delayMilliseconds, periodMilliseconds) { _requestAccessor = requestAccessor; @@ -28,7 +35,9 @@ namespace Umbraco.Web.Scheduling _logger = logger; _serverRegistrar = serverRegistrar; if (_httpClient == null) + { _httpClient = new HttpClient(); + } } public override async Task PerformRunAsync(CancellationToken token) diff --git a/src/Umbraco.Core/Templates/HtmlUrlParser.cs b/src/Umbraco.Core/Templates/HtmlUrlParser.cs index 566fce8b87..8a6baa0aa3 100644 --- a/src/Umbraco.Core/Templates/HtmlUrlParser.cs +++ b/src/Umbraco.Core/Templates/HtmlUrlParser.cs @@ -1,5 +1,6 @@ using System.Text.RegularExpressions; -using Umbraco.Core.Configuration.UmbracoSettings; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -7,16 +8,16 @@ namespace Umbraco.Web.Templates { public sealed class HtmlUrlParser { - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IIOHelper _ioHelper; private readonly IProfilingLogger _logger; private static readonly Regex ResolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); - public HtmlUrlParser(IContentSettings contentSettings, IProfilingLogger logger, IIOHelper ioHelper) + public HtmlUrlParser(IOptionsSnapshot contentSettings, IProfilingLogger logger, IIOHelper ioHelper) { - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _ioHelper = ioHelper; _logger = logger; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index b5e553a78e..3b7ccb1775 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -15,10 +15,12 @@ + + diff --git a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserManager.cs b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserManager.cs index c901c14ee1..6e11e20c8f 100644 --- a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserManager.cs +++ b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserManager.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Security; using Umbraco.Extensions; using Umbraco.Net; @@ -26,7 +27,7 @@ namespace Umbraco.Core.BackOffice BackOfficeIdentityErrorDescriber errors, IServiceProvider services, ILogger> logger, - IUserPasswordConfiguration passwordConfiguration) + IOptions passwordConfiguration) : base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger, passwordConfiguration) { } @@ -48,11 +49,11 @@ namespace Umbraco.Core.BackOffice BackOfficeIdentityErrorDescriber errors, IServiceProvider services, ILogger> logger, - IUserPasswordConfiguration passwordConfiguration) + IOptions passwordConfiguration) : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger) { IpResolver = ipResolver ?? throw new ArgumentNullException(nameof(ipResolver)); - PasswordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); + PasswordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); } #region What we do not currently support diff --git a/src/Umbraco.Infrastructure/Configuration/JsonConfigManipulator.cs b/src/Umbraco.Infrastructure/Configuration/JsonConfigManipulator.cs index 646df5124d..17b0fc3505 100644 --- a/src/Umbraco.Infrastructure/Configuration/JsonConfigManipulator.cs +++ b/src/Umbraco.Infrastructure/Configuration/JsonConfigManipulator.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration.Json; using Microsoft.Extensions.FileProviders; using Newtonsoft.Json; using Newtonsoft.Json.Linq; + namespace Umbraco.Core.Configuration { public class JsonConfigManipulator : IConfigManipulator diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index 0240d60f29..5ddf9aa288 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -2,11 +2,11 @@ using System.Net.Mail; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Logging; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Services; namespace Umbraco.Web.HealthCheck.NotificationMethods @@ -18,9 +18,15 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods private readonly IRequestAccessor _requestAccessor; private readonly IGlobalSettings _globalSettings; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; - public EmailNotificationMethod(ILocalizedTextService textService, IRequestAccessor requestAccessor, IGlobalSettings globalSettings, IHealthChecksSettings healthChecksSettings, IContentSettings contentSettings) : base(healthChecksSettings) + public EmailNotificationMethod( + ILocalizedTextService textService, + IRequestAccessor requestAccessor, + IGlobalSettings globalSettings, + IHealthChecksSettings healthChecksSettings, + IOptionsSnapshot contentSettings) + : base(healthChecksSettings) { var recipientEmail = Settings?["recipientEmail"]?.Value; if (string.IsNullOrWhiteSpace(recipientEmail)) @@ -34,7 +40,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods _textService = textService ?? throw new ArgumentNullException(nameof(textService)); _requestAccessor = requestAccessor; _globalSettings = globalSettings; - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); } public string RecipientEmail { get; } @@ -73,7 +79,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods private MailMessage CreateMailMessage(string subject, string message) { - var to = _contentSettings.NotificationEmailAddress; + var to = _contentSettings.Notifications.NotificationEmailAddress; if (string.IsNullOrWhiteSpace(subject)) subject = "Umbraco Health Check Status"; diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index a240eaf104..f3765493d9 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -3,15 +3,16 @@ using System.Collections.Specialized; using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using Umbraco.Core; +using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Services; -using Umbraco.Web.Install.Models; -using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Extensions; +using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install.InstallSteps { @@ -30,19 +31,27 @@ namespace Umbraco.Web.Install.InstallSteps private readonly DatabaseBuilder _databaseBuilder; private static HttpClient _httpClient; private readonly IGlobalSettings _globalSettings; - private readonly IUserPasswordConfiguration _passwordConfiguration; - private readonly ISecuritySettings _securitySettings; + private readonly UserPasswordConfigurationSettings _passwordConfiguration; + private readonly SecuritySettings _securitySettings; private readonly IConnectionStrings _connectionStrings; private readonly ICookieManager _cookieManager; private readonly BackOfficeUserManager _userManager; - public NewInstallStep(IUserService userService, DatabaseBuilder databaseBuilder, IGlobalSettings globalSettings, IUserPasswordConfiguration passwordConfiguration, ISecuritySettings securitySettings, IConnectionStrings connectionStrings, ICookieManager cookieManager, BackOfficeUserManager userManager) + public NewInstallStep( + IUserService userService, + DatabaseBuilder databaseBuilder, + IGlobalSettings globalSettings, + IOptionsSnapshot passwordConfiguration, + IOptionsSnapshot securitySettings, + IConnectionStrings connectionStrings, + ICookieManager cookieManager, + BackOfficeUserManager userManager) { _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); - _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); - _securitySettings = securitySettings ?? throw new ArgumentNullException(nameof(securitySettings)); + _passwordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); + _securitySettings = securitySettings.Value ?? throw new ArgumentNullException(nameof(securitySettings)); _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); _cookieManager = cookieManager; _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); diff --git a/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs b/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs index 1f495d3a50..c9386ea210 100644 --- a/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs +++ b/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs @@ -1,11 +1,12 @@ using System; using System.Reflection; using System.Threading; +using Microsoft.Extensions.Options; using Serilog.Core; using Serilog.Events; -using Umbraco.Core.Configuration; using Umbraco.Core.Diagnostics; using Umbraco.Core.Hosting; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Infrastructure.Logging.Serilog.Enrichers { @@ -14,13 +15,13 @@ namespace Umbraco.Infrastructure.Logging.Serilog.Enrichers /// public class ThreadAbortExceptionEnricher : ILogEventEnricher { - private readonly ICoreDebugSettings _coreDebugSettings; + private readonly CoreDebugSettings _coreDebugSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IMarchal _marchal; - public ThreadAbortExceptionEnricher(ICoreDebugSettings coreDebugSettings, IHostingEnvironment hostingEnvironment, IMarchal marchal) + public ThreadAbortExceptionEnricher(IOptionsSnapshot coreDebugSettings, IHostingEnvironment hostingEnvironment, IMarchal marchal) { - _coreDebugSettings = coreDebugSettings; + _coreDebugSettings = coreDebugSettings.Value; _hostingEnvironment = hostingEnvironment; _marchal = marchal; } diff --git a/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs b/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs index 05d4744526..38c77aefb5 100644 --- a/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs +++ b/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs @@ -1,8 +1,10 @@ using System; using System.Drawing; using System.IO; -using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -17,9 +19,20 @@ namespace Umbraco.Web.Media { private readonly IMediaFileSystem _mediaFileSystem; private readonly ILogger _logger; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; - public UploadAutoFillProperties(IMediaFileSystem mediaFileSystem, ILogger logger, IContentSettings contentSettings) + public UploadAutoFillProperties( + IMediaFileSystem mediaFileSystem, + ILogger logger, + IOptionsSnapshot contentSettings) + : this(mediaFileSystem, logger, contentSettings.Value) + { + } + + public UploadAutoFillProperties( + IMediaFileSystem mediaFileSystem, + ILogger logger, + ContentSettings contentSettings) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); diff --git a/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs index 0bd6d54c08..069333e55d 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Models; @@ -15,13 +16,13 @@ namespace Umbraco.Web.Models.Mapping { private readonly PropertyEditorCollection _propertyEditors; private readonly ILogger _logger; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; - public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger, IContentSettings contentSettings) + public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger, IOptionsSnapshot contentSettings) { _propertyEditors = propertyEditors; _logger = logger; - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); } private static readonly int[] SystemIds = diff --git a/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs index 9045be20aa..b77214fac5 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs @@ -1,14 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Dictionary; using Umbraco.Core.Mapping; using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Core.Dictionary; -using Umbraco.Core.Configuration; -using Umbraco.Core.PropertyEditors; using Umbraco.Web.Security; namespace Umbraco.Web.Models.Mapping @@ -28,7 +29,7 @@ namespace Umbraco.Web.Models.Mapping private readonly IMemberTypeService _memberTypeService; private readonly IMemberService _memberService; private readonly IMemberGroupService _memberGroupService; - private readonly IMemberPasswordConfiguration _memberPasswordConfiguration; + private readonly MemberPasswordConfigurationSettings _memberPasswordConfiguration; private readonly PropertyEditorCollection _propertyEditorCollection; public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary, @@ -37,7 +38,7 @@ namespace Umbraco.Web.Models.Mapping IMemberTypeService memberTypeService, IMemberService memberService, IMemberGroupService memberGroupService, - IMemberPasswordConfiguration memberPasswordConfiguration, + IOptionsSnapshot memberPasswordConfiguration, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, PropertyEditorCollection propertyEditorCollection) : base(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider) @@ -47,7 +48,7 @@ namespace Umbraco.Web.Models.Mapping _memberTypeService = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService)); _memberService = memberService ?? throw new ArgumentNullException(nameof(memberService)); _memberGroupService = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService)); - _memberPasswordConfiguration = memberPasswordConfiguration; + _memberPasswordConfiguration = memberPasswordConfiguration.Value; _propertyEditorCollection = propertyEditorCollection; } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs index e191ac08bf..bd11127296 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; +using Microsoft.Extensions.Options; using NPoco; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; @@ -25,7 +27,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { private readonly IMapperCollection _mapperCollection; private readonly IGlobalSettings _globalSettings; - private readonly IUserPasswordConfiguration _passwordConfiguration; + private readonly UserPasswordConfigurationSettings _passwordConfiguration; private readonly IJsonSerializer _jsonSerializer; private string _passwordConfigJson; private bool _passwordConfigInitialized; @@ -40,7 +42,36 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// A dictionary specifying the configuration for user passwords. If this is null then no password configuration will be persisted or read. /// /// - public UserRepository(IScopeAccessor scopeAccessor, AppCaches appCaches, ILogger logger, IMapperCollection mapperCollection, IGlobalSettings globalSettings, IUserPasswordConfiguration passwordConfiguration, IJsonSerializer jsonSerializer) + public UserRepository( + IScopeAccessor scopeAccessor, + AppCaches appCaches, + ILogger logger, + IMapperCollection mapperCollection, + IGlobalSettings globalSettings, + IOptionsSnapshot passwordConfiguration, + IJsonSerializer jsonSerializer) + : this(scopeAccessor, appCaches, logger, mapperCollection, globalSettings, passwordConfiguration.Value, jsonSerializer) + { + } + + /// + /// Constructor + /// + /// + /// + /// + /// + /// A dictionary specifying the configuration for user passwords. If this is null then no password configuration will be persisted or read. + /// + /// + public UserRepository( + IScopeAccessor scopeAccessor, + AppCaches appCaches, + ILogger logger, + IMapperCollection mapperCollection, + IGlobalSettings globalSettings, + UserPasswordConfigurationSettings passwordConfiguration, + IJsonSerializer jsonSerializer) : base(scopeAccessor, appCaches, logger) { _mapperCollection = mapperCollection ?? throw new ArgumentNullException(nameof(mapperCollection)); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs index 698fcb10b3..5205cfd15b 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -22,13 +24,32 @@ namespace Umbraco.Web.PropertyEditors public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator { private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly UploadAutoFillProperties _uploadAutoFillProperties; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; private readonly ILocalizedTextService _localizedTextService; - public FileUploadPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSettings contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper) + public FileUploadPropertyEditor( + ILogger logger, + IMediaFileSystem mediaFileSystem, + IOptionsSnapshot contentSettings, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper) + : this(logger, mediaFileSystem, contentSettings.Value, dataTypeService, localizationService, localizedTextService, shortStringHelper) + { + } + + public FileUploadPropertyEditor( + ILogger logger, + IMediaFileSystem mediaFileSystem, + ContentSettings contentSettings, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper) : base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs index e45896551c..e518005526 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -1,7 +1,8 @@ using System; using System.IO; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Models.Editors; using Umbraco.Core.PropertyEditors; @@ -16,9 +17,28 @@ namespace Umbraco.Web.PropertyEditors internal class FileUploadPropertyValueEditor : DataValueEditor { private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; - public FileUploadPropertyValueEditor(DataEditorAttribute attribute, IMediaFileSystem mediaFileSystem, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IContentSettings contentSettings) + public FileUploadPropertyValueEditor( + DataEditorAttribute attribute, + IMediaFileSystem mediaFileSystem, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper, + IOptionsSnapshot contentSettings) + : this(attribute, mediaFileSystem, dataTypeService, localizationService, localizedTextService, shortStringHelper, contentSettings.Value) + { + } + + public FileUploadPropertyValueEditor( + DataEditorAttribute attribute, + IMediaFileSystem mediaFileSystem, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper, + ContentSettings contentSettings) : base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs index 586a120609..398b7110e3 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -29,7 +31,7 @@ namespace Umbraco.Web.PropertyEditors public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator { private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; private readonly IIOHelper _ioHelper; @@ -38,8 +40,32 @@ namespace Umbraco.Web.PropertyEditors /// /// Initializes a new instance of the class. /// - public ImageCropperPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSettings contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper, IShortStringHelper shortStringHelper, ILocalizedTextService localizedTextService) - : base(logger, dataTypeService, localizationService, localizedTextService,shortStringHelper) + public ImageCropperPropertyEditor( + ILogger logger, + IMediaFileSystem mediaFileSystem, + IOptionsSnapshot contentSettings, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + IIOHelper ioHelper, + IShortStringHelper shortStringHelper, + ILocalizedTextService localizedTextService) + : this(logger, mediaFileSystem, contentSettings.Value, dataTypeService, localizationService, ioHelper, shortStringHelper, localizedTextService) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ImageCropperPropertyEditor( + ILogger logger, + IMediaFileSystem mediaFileSystem, + ContentSettings contentSettings, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + IIOHelper ioHelper, + IShortStringHelper shortStringHelper, + ILocalizedTextService localizedTextService) + : base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs index 1c7c8b922a..8f88c301d1 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -22,9 +22,17 @@ namespace Umbraco.Web.PropertyEditors { private readonly ILogger _logger; private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; - public ImageCropperPropertyValueEditor(DataEditorAttribute attribute, ILogger logger, IMediaFileSystem mediaFileSystem, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IContentSettings contentSettings) + public ImageCropperPropertyValueEditor( + DataEditorAttribute attribute, + ILogger logger, + IMediaFileSystem mediaFileSystem, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + ILocalizedTextService localizedTextService, + IShortStringHelper shortStringHelper, + ContentSettings contentSettings) : base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs index b64c52648a..063ac1cc97 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; -using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -16,14 +15,19 @@ namespace Umbraco.Web.PropertyEditors internal class UploadFileTypeValidator : IValueValidator { private readonly ILocalizedTextService _localizedTextService; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; - public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IContentSettings contentSettings) + public UploadFileTypeValidator(ILocalizedTextService localizedTextService, ContentSettings contentSettings) { _localizedTextService = localizedTextService; _contentSettings = contentSettings; } + public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IOptionsSnapshot contentSettings) + : this(localizedTextService, contentSettings.Value) + { + } + public IEnumerable Validate(object value, string valueType, object dataTypeConfiguration) { string selectedFiles = null; @@ -55,7 +59,7 @@ namespace Umbraco.Web.PropertyEditors } } - internal static bool IsValidFileExtension(string fileName, IContentSettings contentSettings) + internal static bool IsValidFileExtension(string fileName, ContentSettings contentSettings) { if (fileName.IndexOf('.') <= 0) return false; var extension = fileName.GetFileExtension().TrimStart("."); diff --git a/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs index ac8d0980c4..ae47b85365 100644 --- a/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs +++ b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs @@ -1,8 +1,9 @@ -using Examine; using System.Globalization; using System.Linq; +using Examine; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -16,14 +17,18 @@ namespace Umbraco.Web.Routing { private readonly ILogger _logger; private readonly IEntityService _entityService; - private readonly IContentSettings _contentConfigSettings; + private readonly ContentSettings _contentSettings; private readonly IExamineManager _examineManager; - public ContentFinderByConfigured404(ILogger logger, IEntityService entityService, IContentSettings contentConfigSettings, IExamineManager examineManager) + public ContentFinderByConfigured404( + ILogger logger, + IEntityService entityService, + IOptionsSnapshot contentConfigSettings, + IExamineManager examineManager) { _logger = logger; _entityService = entityService; - _contentConfigSettings = contentConfigSettings; + _contentSettings = contentConfigSettings.Value; _examineManager = examineManager; } @@ -63,7 +68,7 @@ namespace Umbraco.Web.Routing } var error404 = NotFoundHandlerHelper.GetCurrentNotFoundPageId( - _contentConfigSettings.Error404Collection.ToArray(), + _contentSettings.Error404Collection.ToArray(), _entityService, new PublishedContentQuery(frequest.UmbracoContext.PublishedSnapshot, frequest.UmbracoContext.VariationContextAccessor, _examineManager), errorCulture); diff --git a/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs b/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs index b3e30a7353..2c5d8afbff 100644 --- a/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs +++ b/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs @@ -1,5 +1,7 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; @@ -8,18 +10,23 @@ using Umbraco.Core.Sync; namespace Umbraco.Web.Scheduling { - public class LogScrubber : RecurringTaskBase { private readonly IMainDom _mainDom; private readonly IServerRegistrar _serverRegistrar; private readonly IAuditService _auditService; - private readonly ILoggingSettings _settings; + private readonly LoggingSettings _settings; private readonly IProfilingLogger _logger; private readonly IScopeProvider _scopeProvider; public LogScrubber(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, ILoggingSettings settings, IScopeProvider scopeProvider, IProfilingLogger logger) + IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, IOptionsSnapshot settings, IScopeProvider scopeProvider, IProfilingLogger logger) + : this(runner, delayMilliseconds, periodMilliseconds, mainDom, serverRegistrar, auditService, settings.Value, scopeProvider, logger) + { + } + + public LogScrubber(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, + IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, LoggingSettings settings, IScopeProvider scopeProvider, IProfilingLogger logger) : base(runner, delayMilliseconds, periodMilliseconds) { _mainDom = mainDom; @@ -31,7 +38,7 @@ namespace Umbraco.Web.Scheduling } // maximum age, in minutes - private int GetLogScrubbingMaximumAge(ILoggingSettings settings) + private int GetLogScrubbingMaximumAge(LoggingSettings settings) { var maximumAge = 24 * 60; // 24 hours, in minutes try diff --git a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs index a5850719ab..982f8470a7 100644 --- a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; using Umbraco.Core.Services; @@ -39,8 +39,8 @@ namespace Umbraco.Web.Scheduling private readonly IHealthChecksSettings _healthChecksSettingsConfig; private readonly IServerMessenger _serverMessenger; private readonly IRequestAccessor _requestAccessor; - private readonly ILoggingSettings _loggingSettings; - private readonly IKeepAliveSettings _keepAliveSettings; + private readonly LoggingSettings _loggingSettings; + private readonly KeepAliveSettings _keepAliveSettings; private readonly IHostingEnvironment _hostingEnvironment; private BackgroundTaskRunner _keepAliveRunner; @@ -59,7 +59,7 @@ namespace Umbraco.Web.Scheduling IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger, IApplicationShutdownRegistry applicationShutdownRegistry, IHealthChecksSettings healthChecksSettingsConfig, IServerMessenger serverMessenger, IRequestAccessor requestAccessor, - ILoggingSettings loggingSettings, IKeepAliveSettings keepAliveSettings, + IOptionsSnapshot loggingSettings, IOptionsSnapshot keepAliveSettings, IHostingEnvironment hostingEnvironment) { _runtime = runtime; @@ -77,8 +77,8 @@ namespace Umbraco.Web.Scheduling _healthChecksSettingsConfig = healthChecksSettingsConfig ?? throw new ArgumentNullException(nameof(healthChecksSettingsConfig)); _serverMessenger = serverMessenger; _requestAccessor = requestAccessor; - _loggingSettings = loggingSettings; - _keepAliveSettings = keepAliveSettings; + _loggingSettings = loggingSettings.Value; + _keepAliveSettings = keepAliveSettings.Value; _hostingEnvironment = hostingEnvironment; } @@ -137,7 +137,7 @@ namespace Umbraco.Web.Scheduling }); } - private IBackgroundTask RegisterKeepAlive(IKeepAliveSettings keepAliveSettings) + private IBackgroundTask RegisterKeepAlive(KeepAliveSettings keepAliveSettings) { // ping/keepalive // on all servers @@ -181,7 +181,7 @@ namespace Umbraco.Web.Scheduling return task; } - private IBackgroundTask RegisterLogScrubber(ILoggingSettings settings) + private IBackgroundTask RegisterLogScrubber(LoggingSettings settings) { // log scrubbing // install on all, will only run on non-replica servers diff --git a/src/Umbraco.Infrastructure/Scoping/Scope.cs b/src/Umbraco.Infrastructure/Scoping/Scope.cs index 3b17ae876d..b7ccf539f6 100644 --- a/src/Umbraco.Infrastructure/Scoping/Scope.cs +++ b/src/Umbraco.Infrastructure/Scoping/Scope.cs @@ -2,11 +2,11 @@ using System.Data; using Umbraco.Core.Cache; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Core.Scoping { @@ -17,7 +17,7 @@ namespace Umbraco.Core.Scoping internal class Scope : IScope { private readonly ScopeProvider _scopeProvider; - private readonly ICoreDebugSettings _coreDebugSettings; + private readonly CoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; private readonly ILogger _logger; private readonly ITypeFinder _typeFinder; @@ -39,7 +39,7 @@ namespace Umbraco.Core.Scoping // initializes a new scope private Scope(ScopeProvider scopeProvider, - ICoreDebugSettings coreDebugSettings, + CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, Scope parent, IScopeContext scopeContext, bool detachable, IsolationLevel isolationLevel = IsolationLevel.Unspecified, @@ -118,7 +118,7 @@ namespace Umbraco.Core.Scoping // initializes a new scope public Scope(ScopeProvider scopeProvider, - ICoreDebugSettings coreDebugSettings, + CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, bool detachable, IScopeContext scopeContext, IsolationLevel isolationLevel = IsolationLevel.Unspecified, @@ -132,7 +132,7 @@ namespace Umbraco.Core.Scoping // initializes a new scope in a nested scopes chain, with its parent public Scope(ScopeProvider scopeProvider, - ICoreDebugSettings coreDebugSettings, + CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, FileSystems fileSystems, Scope parent, IsolationLevel isolationLevel = IsolationLevel.Unspecified, diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index 610f308b96..5205a95e8d 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -1,14 +1,13 @@ using System; -using System.Collections.Generic; using System.Data; +using Microsoft.Extensions.Options; using Umbraco.Core.Cache; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; -using Current = Umbraco.Composing.Current; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; #if DEBUG_SCOPES using System.Linq; @@ -26,10 +25,15 @@ namespace Umbraco.Core.Scoping private readonly ITypeFinder _typeFinder; private readonly IRequestCache _requestCache; private readonly FileSystems _fileSystems; - private readonly ICoreDebugSettings _coreDebugSettings; + private readonly CoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; - public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, ICoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) + public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptionsSnapshot coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) + :this(databaseFactory, fileSystems, coreDebugSettings.Value, mediaFileSystem, logger, typeFinder, requestCache) + { + } + + public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) { DatabaseFactory = databaseFactory; _fileSystems = fileSystems; diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index d6c30b24c6..112ab51bf8 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -6,9 +6,9 @@ using System.Linq; using System.Net.Mail; using System.Text; using System.Threading; -using Umbraco.Core.Composing; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -16,7 +16,6 @@ using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Scoping; -using Umbraco.Core.Strings; namespace Umbraco.Core.Services.Implement { @@ -28,12 +27,18 @@ namespace Umbraco.Core.Services.Implement private readonly ILocalizationService _localizationService; private readonly INotificationsRepository _notificationsRepository; private readonly IGlobalSettings _globalSettings; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly ILogger _logger; private readonly IIOHelper _ioHelper; public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, - ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IContentSettings contentSettings) + ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IOptionsSnapshot contentSettings) + : this(provider, userService, contentService, localizationService, logger, ioHelper, notificationsRepository, globalSettings, contentSettings.Value) + { + } + + public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, + ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, ContentSettings contentSettings) { _notificationsRepository = notificationsRepository; _globalSettings = globalSettings; @@ -302,7 +307,7 @@ namespace Umbraco.Core.Services.Implement if (content.ContentType.VariesByNothing()) { - if (!_contentSettings.DisableHtmlEmail) + if (!_contentSettings.Notifications.DisableHtmlEmail) { //create the HTML summary for invariant content @@ -344,7 +349,7 @@ namespace Umbraco.Core.Services.Implement { //it's variant, so detect what cultures have changed - if (!_contentSettings.DisableHtmlEmail) + if (!_contentSettings.Notifications.DisableHtmlEmail) { //Create the HTML based summary (ul of culture names) @@ -406,13 +411,13 @@ namespace Umbraco.Core.Services.Implement summary.ToString()); // create the mail message - var mail = new MailMessage(_contentSettings.NotificationEmailAddress, mailingUser.Email); + var mail = new MailMessage(_contentSettings.Notifications.NotificationEmailAddress, mailingUser.Email); // populate the message mail.Subject = createSubject((mailingUser, subjectVars)); - if (_contentSettings.DisableHtmlEmail) + if (_contentSettings.Notifications.DisableHtmlEmail) { mail.IsBodyHtml = false; mail.Body = createBody((user: mailingUser, body: bodyVars, false)); diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index adb2a95202..fa0ac89c61 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -41,7 +41,7 @@ - + @@ -97,6 +97,7 @@ + diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 85a463ddfa..3a6d099e46 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -18,6 +18,7 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Strings; using Umbraco.Web; using Umbraco.Web.Routing; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Tests.Common { @@ -82,7 +83,7 @@ namespace Umbraco.Tests.Common public abstract IDbProviderFactoryCreator DbProviderFactoryCreator { get; } public abstract IBulkSqlInsertProvider BulkSqlInsertProvider { get; } public abstract IMarchal Marchal { get; } - public ICoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); + public CoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); public IIOHelper IOHelper { diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs index dddcff4331..dec3b55c76 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Persistence.Repositories private UserRepository CreateRepository(IScopeProvider provider) { var accessor = (IScopeAccessor) provider; - var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, GlobalSettings, Mock.Of(), new JsonNetSerializer()); + var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); return repository; } @@ -117,7 +118,7 @@ namespace Umbraco.Tests.Persistence.Repositories var id = user.Id; - var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(),GlobalSettings, Mock.Of(), new JsonNetSerializer()); + var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(),GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); repository2.Delete(user); diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs index 436fb45377..31edde3600 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs @@ -2,7 +2,7 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings { diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs index 21fd59de3a..85dc2f0ea6 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs @@ -1,9 +1,8 @@ using System; -using System.Diagnostics; using System.Linq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; using Umbraco.Core.Macros; namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index a20b220940..3bd7b0a7cc 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Scoping; using Umbraco.Tests.TestHelpers; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Tests.Components { @@ -35,7 +36,7 @@ namespace Umbraco.Tests.Components var typeFinder = TestHelper.GetTypeFinder(); var f = new UmbracoDatabaseFactory(logger, SettingsForTests.DefaultGlobalSettings, Mock.Of(), new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); - var coreDebug = Mock.Of(); + var coreDebug = new CoreDebugSettings(); var mediaFileSystem = Mock.Of(); var p = new ScopeProvider(f, fs, coreDebug, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index 632f433c5b..1dd9f3d7cb 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -3,6 +3,7 @@ using System.Xml.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -31,7 +32,7 @@ namespace Umbraco.Tests.Models // and then, this will reset the width, height... because the file does not exist, of course ;-( var logger = Mock.Of(); var scheme = Mock.Of(); - var config = Mock.Of(); + var config = new ContentSettings(); var mediaFileSystem = new MediaFileSystem(Mock.Of(), scheme, logger, ShortStringHelper); var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, config, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper); diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs index a14eea1d91..03fc77572a 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs @@ -15,6 +15,7 @@ using Umbraco.Core.PropertyEditors; using System; using Umbraco.Core.Configuration; using Umbraco.Core.Serialization; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.Persistence.Repositories { @@ -68,7 +69,7 @@ namespace Umbraco.Tests.Persistence.Repositories private UserRepository CreateRepository(IScopeProvider provider) { var accessor = (IScopeAccessor) provider; - var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, TestObjects.GetGlobalSettings(), Mock.Of(), new JsonNetSerializer()); + var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, TestObjects.GetGlobalSettings(), new UserPasswordConfigurationSettings(), new JsonNetSerializer()); return repository; } diff --git a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs index e55a22065b..c191bc1b43 100644 --- a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs @@ -4,6 +4,7 @@ using Moq; using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -34,12 +35,12 @@ namespace Umbraco.Tests.Routing var logger = Mock.Of(); var mediaFileSystemMock = Mock.Of(); - var contentSection = Mock.Of(); + var contentSettings = new ContentSettings(); var dataTypeService = Mock.Of(); var propertyEditors = new MediaUrlGeneratorCollection(new IMediaUrlGenerator[] { - new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), - new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), + new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), + new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), }); _mediaUrlProvider = new DefaultMediaUrlProvider(propertyEditors, UriUtility); } diff --git a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs index 8958eabd42..d2a17d1004 100644 --- a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Net; using Umbraco.Web.Security; @@ -23,18 +24,19 @@ namespace Umbraco.Tests.Security const string v7Hash = "7Uob6fMTTxDIhWGebYiSxg==P+hgvWlXLbDd4cFLADn811KOaVI/9pg1PNvTuG5NklY="; const string plaintext = "4XxzH3s3&J"; - var mockPasswordConfiguration = new Mock(); + var passwordConfiguration = new UserPasswordConfigurationSettings + { + HashAlgorithmType = Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName + }; var mockIpResolver = new Mock(); var mockUserStore = new Mock>(); var mockDataProtectionProvider = new Mock(); mockDataProtectionProvider.Setup(x => x.Create(It.IsAny())) .Returns(new Mock().Object); - mockPasswordConfiguration.Setup(x => x.HashAlgorithmType) - .Returns(Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName); var userManager = BackOfficeOwinUserManager.Create( - mockPasswordConfiguration.Object, + passwordConfiguration, mockIpResolver.Object, mockUserStore.Object, null, diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 5512f50254..e9f05f43fc 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -33,6 +33,7 @@ using Umbraco.Web; using Umbraco.Web.Hosting; using Umbraco.Web.Routing; using File = System.IO.File; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Tests.TestHelpers { @@ -94,7 +95,7 @@ namespace Umbraco.Tests.TestHelpers public static IDbProviderFactoryCreator DbProviderFactoryCreator => _testHelperInternal.DbProviderFactoryCreator; public static IBulkSqlInsertProvider BulkSqlInsertProvider => _testHelperInternal.BulkSqlInsertProvider; public static IMarchal Marchal => _testHelperInternal.Marchal; - public static ICoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings; + public static CoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings; public static IIOHelper IOHelper => _testHelperInternal.IOHelper; diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 7e8914f78e..5077563e78 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.Hosting; @@ -95,7 +96,7 @@ namespace Umbraco.Tests.TestHelpers ILogger logger, IIOHelper ioHelper, IGlobalSettings globalSettings, - IContentSettings contentSettings, + ContentSettings contentSettings, IEventMessagesFactory eventMessagesFactory, UrlSegmentProviderCollection urlSegmentProviders, IUmbracoVersion umbracoVersion, diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs index 4faac5ce52..a82dda52c7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs @@ -1,17 +1,17 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Routing; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Mail; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Models; @@ -46,10 +46,10 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly ILocalizedTextService _textService; private readonly UmbracoMapper _umbracoMapper; private readonly IGlobalSettings _globalSettings; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; private readonly ILogger _logger; private readonly IIpResolver _ipResolver; - private readonly IUserPasswordConfiguration _passwordConfiguration; + private readonly UserPasswordConfigurationSettings _passwordConfiguration; private readonly IEmailSender _emailSender; private readonly Core.Hosting.IHostingEnvironment _hostingEnvironment; private readonly IRequestAccessor _requestAccessor; @@ -65,10 +65,10 @@ namespace Umbraco.Web.BackOffice.Controllers ILocalizedTextService textService, UmbracoMapper umbracoMapper, IGlobalSettings globalSettings, - ISecuritySettings securitySettings, + IOptionsSnapshot securitySettings, ILogger logger, IIpResolver ipResolver, - IUserPasswordConfiguration passwordConfiguration, + IOptionsSnapshot passwordConfiguration, IEmailSender emailSender, Core.Hosting.IHostingEnvironment hostingEnvironment, IRequestAccessor requestAccessor) @@ -80,10 +80,10 @@ namespace Umbraco.Web.BackOffice.Controllers _textService = textService; _umbracoMapper = umbracoMapper; _globalSettings = globalSettings; - _securitySettings = securitySettings; + _securitySettings = securitySettings.Value; _logger = logger; _ipResolver = ipResolver; - _passwordConfiguration = passwordConfiguration; + _passwordConfiguration = passwordConfiguration.Value; _emailSender = emailSender; _hostingEnvironment = hostingEnvironment; _requestAccessor = requestAccessor; diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs index f3d11dea78..2768770e65 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs @@ -1,16 +1,15 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Routing; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; -using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.WebAssets; using Umbraco.Extensions; @@ -19,10 +18,8 @@ using Umbraco.Web.BackOffice.PropertyEditors; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Editors; using Umbraco.Web.Features; -using Umbraco.Web.HealthCheck; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Trees; -using Umbraco.Web.WebApi; namespace Umbraco.Web.BackOffice.Controllers { @@ -36,12 +33,12 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly UmbracoFeatures _features; private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _settings; - private readonly ISecuritySettings _securitySettings; + private readonly RuntimeSettings _runtimeSettings; + private readonly SecuritySettings _securitySettings; private readonly IRuntimeMinifier _runtimeMinifier; private readonly IAuthenticationSchemeProvider _authenticationSchemeProvider; @@ -51,12 +48,12 @@ namespace Umbraco.Web.BackOffice.Controllers UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, IHttpContextAccessor httpContextAccessor, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings, - ISecuritySettings securitySettings, + IOptionsSnapshot runtimeSettings, + IOptionsSnapshot securitySettings, IRuntimeMinifier runtimeMinifier, IAuthenticationSchemeProvider authenticationSchemeProvider) { @@ -65,12 +62,12 @@ namespace Umbraco.Web.BackOffice.Controllers _features = features; _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _httpContextAccessor = httpContextAccessor; _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; - _settings = settings; - _securitySettings = securitySettings; + _runtimeSettings = runtimeSettings.Value; + _securitySettings = securitySettings.Value; _runtimeMinifier = runtimeMinifier; _authenticationSchemeProvider = authenticationSchemeProvider; } @@ -362,7 +359,7 @@ namespace Umbraco.Web.BackOffice.Controllers {"appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd('/')}, { "imageFileTypes", - string.Join(",", _contentSettings.ImageFileTypes) + string.Join(",", _contentSettings.Imaging.ImageFileTypes) }, { "disallowedUploadFiles", @@ -509,7 +506,7 @@ namespace Umbraco.Web.BackOffice.Controllers private string GetMaxRequestLength() { - return _settings.MaxRequestLength.HasValue ? _settings.MaxRequestLength.Value.ToString() : string.Empty; + return _runtimeSettings.MaxRequestLength.HasValue ? _runtimeSettings.MaxRequestLength.Value.ToString() : string.Empty; } } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs index 69b566d0cd..ff0eacb9bb 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs @@ -1,31 +1,30 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Net.Http; -using System.Threading.Tasks; -using Umbraco.Core.Services; -using Umbraco.Web.Models; -using Umbraco.Web.Models.ContentEditing; using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Cache; -using Umbraco.Core.IO; -using Umbraco.Web.WebApi.Filters; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Media; +using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Extensions; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.Security; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; +using Umbraco.Web.Models; +using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Security; namespace Umbraco.Web.BackOffice.Controllers @@ -37,7 +36,7 @@ namespace Umbraco.Web.BackOffice.Controllers public class CurrentUserController : UmbracoAuthorizedJsonController { private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IImageUrlGenerator _imageUrlGenerator; private readonly IWebSecurity _webSecurity; @@ -51,7 +50,7 @@ namespace Umbraco.Web.BackOffice.Controllers public CurrentUserController( IMediaFileSystem mediaFileSystem, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, IWebSecurity webSecurity, @@ -64,7 +63,7 @@ namespace Umbraco.Web.BackOffice.Controllers IShortStringHelper shortStringHelper) { _mediaFileSystem = mediaFileSystem; - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _hostingEnvironment = hostingEnvironment; _imageUrlGenerator = imageUrlGenerator; _webSecurity = webSecurity; diff --git a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs index 194029db4b..d049dbebbb 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs @@ -4,20 +4,21 @@ using System.Data; using System.Linq; using System.Net; using System.Net.Mime; +using System.Text; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; -using Umbraco.Web.Models.ContentEditing; -using System.Text; -using Constants = Umbraco.Core.Constants; -using Umbraco.Core.Mapping; -using Microsoft.AspNetCore.Mvc; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Editors; +using Umbraco.Web.Models.ContentEditing; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.BackOffice.Controllers { @@ -34,7 +35,7 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly PropertyEditorCollection _propertyEditors; private readonly IDataTypeService _dataTypeService; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly UmbracoMapper _umbracoMapper; private readonly PropertyEditorCollection _propertyEditorCollection; private readonly IContentTypeService _contentTypeService; @@ -46,7 +47,7 @@ namespace Umbraco.Web.BackOffice.Controllers public DataTypeController( PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, UmbracoMapper umbracoMapper, PropertyEditorCollection propertyEditorCollection, IContentTypeService contentTypeService, @@ -57,7 +58,7 @@ namespace Umbraco.Web.BackOffice.Controllers { _propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors)); _dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); _propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection)); _contentTypeService = contentTypeService ?? throw new ArgumentNullException(nameof(contentTypeService)); diff --git a/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs index 6ce6d3a1c6..f909313dff 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs @@ -1,8 +1,10 @@ using System; using System.IO; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Media; using Umbraco.Core.Models; @@ -18,13 +20,13 @@ namespace Umbraco.Web.BackOffice.Controllers public class ImagesController : UmbracoAuthorizedApiController { private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IImageUrlGenerator _imageUrlGenerator; - public ImagesController(IMediaFileSystem mediaFileSystem, IContentSettings contentSettings, IImageUrlGenerator imageUrlGenerator) + public ImagesController(IMediaFileSystem mediaFileSystem, IOptionsSnapshot contentSettings, IImageUrlGenerator imageUrlGenerator) { _mediaFileSystem = mediaFileSystem; - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _imageUrlGenerator = imageUrlGenerator; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs index 6bb68248b1..9a339a18b8 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs @@ -3,35 +3,30 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Net.Http; using System.Net.Mime; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Services; -using Umbraco.Web.Models.ContentEditing; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Dictionary; using Umbraco.Core.Events; using Umbraco.Core.Hosting; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Models; using Umbraco.Core.Models.ContentEditing; -using Umbraco.Core.Models.Editors; using Umbraco.Core.Models.Entities; +using Umbraco.Core.Models.Membership; using Umbraco.Core.Models.Validation; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.PropertyEditors; -using Umbraco.Web.ContentApps; -using Umbraco.Web.WebApi.Filters; -using Constants = Umbraco.Core.Constants; -using Umbraco.Core.Mapping; +using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Extensions; using Umbraco.Web.BackOffice.Filters; @@ -39,7 +34,11 @@ using Umbraco.Web.BackOffice.ModelBinders; using Umbraco.Web.Common.ActionResults; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; +using Umbraco.Web.ContentApps; +using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Security; +using Umbraco.Web.WebApi.Filters; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.BackOffice.Controllers { @@ -52,7 +51,7 @@ namespace Umbraco.Web.BackOffice.Controllers public class MediaController : ContentControllerBase { private readonly IShortStringHelper _shortStringHelper; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IMediaTypeService _mediaTypeService; private readonly IMediaService _mediaService; private readonly IEntityService _entityService; @@ -69,7 +68,7 @@ namespace Umbraco.Web.BackOffice.Controllers IShortStringHelper shortStringHelper, IEventMessagesFactory eventMessages, ILocalizedTextService localizedTextService, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, IMediaTypeService mediaTypeService, IMediaService mediaService, IEntityService entityService, @@ -85,7 +84,7 @@ namespace Umbraco.Web.BackOffice.Controllers : base(cultureDictionary, logger, shortStringHelper, eventMessages, localizedTextService) { _shortStringHelper = shortStringHelper; - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _mediaTypeService = mediaTypeService; _mediaService = mediaService; _entityService = entityService; @@ -742,7 +741,7 @@ namespace Umbraco.Web.BackOffice.Controllers if (contentTypeAlias == Constants.Conventions.MediaTypes.AutoSelect) { - if (_contentSettings.ImageFileTypes.Contains(ext)) + if (_contentSettings.Imaging.ImageFileTypes.Contains(ext)) { mediaType = Constants.Conventions.MediaTypes.Image; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs index 9627c96e24..41aa693c0f 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs @@ -8,23 +8,20 @@ using System.Net.Mime; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Dictionary; using Umbraco.Core.Events; using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Models.ContentEditing; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Security; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; -using Umbraco.Web.ContentApps; -using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.WebApi.Filters; -using Constants = Umbraco.Core.Constants; -using Umbraco.Core.Mapping; -using Umbraco.Core.Serialization; using Umbraco.Core.Strings; using Umbraco.Extensions; using Umbraco.Web.BackOffice.Filters; @@ -32,7 +29,11 @@ using Umbraco.Web.BackOffice.ModelBinders; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Common.Filters; +using Umbraco.Web.ContentApps; +using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Security; +using Umbraco.Web.WebApi.Filters; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.BackOffice.Controllers { @@ -45,8 +46,7 @@ namespace Umbraco.Web.BackOffice.Controllers [OutgoingNoHyphenGuidFormat] public class MemberController : ContentControllerBase { - - private readonly IMemberPasswordConfiguration _passwordConfig; + private readonly MemberPasswordConfigurationSettings _passwordConfig; private readonly PropertyEditorCollection _propertyEditors; private readonly LegacyPasswordSecurity _passwordSecurity; private readonly UmbracoMapper _umbracoMapper; @@ -63,7 +63,7 @@ namespace Umbraco.Web.BackOffice.Controllers IShortStringHelper shortStringHelper, IEventMessagesFactory eventMessages, ILocalizedTextService localizedTextService, - IMemberPasswordConfiguration passwordConfig, + IOptionsSnapshot passwordConfig, PropertyEditorCollection propertyEditors, LegacyPasswordSecurity passwordSecurity, UmbracoMapper umbracoMapper, @@ -74,7 +74,7 @@ namespace Umbraco.Web.BackOffice.Controllers IJsonSerializer jsonSerializer) : base(cultureDictionary, logger, shortStringHelper, eventMessages, localizedTextService) { - _passwordConfig = passwordConfig; + _passwordConfig = passwordConfig.Value; _propertyEditors = propertyEditors; _passwordSecurity = passwordSecurity; _umbracoMapper = umbracoMapper; diff --git a/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs b/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs index dd7c539922..5a28a228f3 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs @@ -6,8 +6,10 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Strings; @@ -28,19 +30,19 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IIOHelper _ioHelper; public TinyMceController( IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, IIOHelper ioHelper ) { _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _ioHelper = ioHelper; } @@ -76,7 +78,7 @@ namespace Umbraco.Web.BackOffice.Controllers var safeFileName = fileName.ToSafeFileName(_shortStringHelper); var ext = safeFileName.Substring(safeFileName.LastIndexOf('.') + 1).ToLower(); - if (_contentSettings.IsFileAllowedForUpload(ext) == false || _contentSettings.ImageFileTypes.Contains(ext) == false) + if (_contentSettings.IsFileAllowedForUpload(ext) == false || _contentSettings.Imaging.ImageFileTypes.Contains(ext) == false) { // Throw some error - to say can't upload this IMG type return new UmbracoProblemResult("This is not an image filetype extension that is approved", HttpStatusCode.BadRequest); diff --git a/src/Umbraco.Web.BackOffice/Controllers/TourController.cs b/src/Umbraco.Web.BackOffice/Controllers/TourController.cs index c74cf41daf..106d520743 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/TourController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/TourController.cs @@ -4,9 +4,8 @@ using System.IO; using System.Linq; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using Umbraco.Configuration.Models; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Services; using Umbraco.Web.Common.Attributes; diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs index fff609322c..07c2cab1c7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Net.Http; using System.Net.Mail; using System.Runtime.Serialization; using System.Security.Cryptography; @@ -11,27 +10,22 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Media; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Core.Strings; -using Umbraco.Web.Models; -using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.WebApi.Filters; -using Constants = Umbraco.Core.Constants; -using IUser = Umbraco.Core.Models.Membership.IUser; -using Task = System.Threading.Tasks.Task; -using Umbraco.Core.Mapping; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Hosting; -using Umbraco.Core.Media; using Umbraco.Extensions; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.Security; @@ -39,7 +33,13 @@ using Umbraco.Web.Common.ActionResults; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Editors; +using Umbraco.Web.Models; +using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Security; +using Umbraco.Web.WebApi.Filters; +using Constants = Umbraco.Core.Constants; +using IUser = Umbraco.Core.Models.Membership.IUser; +using Task = System.Threading.Tasks.Task; namespace Umbraco.Web.BackOffice.Controllers { @@ -50,11 +50,11 @@ namespace Umbraco.Web.BackOffice.Controllers public class UsersController : UmbracoAuthorizedJsonController { private readonly IMediaFileSystem _mediaFileSystem; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly ISqlContext _sqlContext; private readonly IImageUrlGenerator _imageUrlGenerator; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; private readonly IRequestAccessor _requestAccessor; private readonly IEmailSender _emailSender; private readonly IWebSecurity _webSecurity; @@ -73,11 +73,11 @@ namespace Umbraco.Web.BackOffice.Controllers public UsersController( IMediaFileSystem mediaFileSystem, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, IHostingEnvironment hostingEnvironment, ISqlContext sqlContext, IImageUrlGenerator imageUrlGenerator, - ISecuritySettings securitySettings, + IOptionsSnapshot securitySettings, IRequestAccessor requestAccessor, IEmailSender emailSender, IWebSecurity webSecurity, @@ -95,11 +95,11 @@ namespace Umbraco.Web.BackOffice.Controllers LinkGenerator linkGenerator) { _mediaFileSystem = mediaFileSystem; - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _hostingEnvironment = hostingEnvironment; _sqlContext = sqlContext; _imageUrlGenerator = imageUrlGenerator; - _securitySettings = securitySettings; + _securitySettings = securitySettings.Value; _requestAccessor = requestAccessor; _emailSender = emailSender; _webSecurity = webSecurity; @@ -137,7 +137,7 @@ namespace Umbraco.Web.BackOffice.Controllers return await PostSetAvatarInternal(files, _userService, _appCaches.RuntimeCache, _mediaFileSystem, _shortStringHelper, _contentSettings, _hostingEnvironment, _imageUrlGenerator, id); } - internal static async Task PostSetAvatarInternal(IList files, IUserService userService, IAppCache cache, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IContentSettings contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, int id) + internal static async Task PostSetAvatarInternal(IList files, IUserService userService, IAppCache cache, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, ContentSettings contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, int id) { if (files is null) { diff --git a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs index 2c7db69b84..c9e53b1b82 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -2,9 +2,10 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Security; using Umbraco.Core.Serialization; using Umbraco.Net; @@ -73,7 +74,7 @@ namespace Umbraco.Extensions services.TryAddScoped, PasswordValidator>(); services.TryAddScoped>( services => new BackOfficePasswordHasher( - new LegacyPasswordSecurity(services.GetRequiredService()), + new LegacyPasswordSecurity(services.GetRequiredService>().Value), services.GetRequiredService())); services.TryAddScoped, DefaultUserConfirmation>(); services.TryAddScoped, UserClaimsPrincipalFactory>(); diff --git a/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs b/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs index 0a7bdb0026..b05a05c167 100644 --- a/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs +++ b/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs @@ -1,14 +1,14 @@ -using Umbraco.Core; +using System; +using Microsoft.Extensions.Options; +using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Dictionary; -using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Trees; -using Umbraco.Core.Configuration.UmbracoSettings; -using System; namespace Umbraco.Web.Models.Mapping { @@ -23,17 +23,17 @@ namespace Umbraco.Web.Models.Mapping private readonly IMediaTypeService _mediaTypeService; private readonly MediaUrlGeneratorCollection _mediaUrlGenerators; private readonly TabsAndPropertiesMapper _tabsAndPropertiesMapper; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; public MediaMapDefinition(ICultureDictionary cultureDictionary, CommonMapper commonMapper, CommonTreeNodeMapper commonTreeNodeMapper, IMediaService mediaService, IMediaTypeService mediaTypeService, - ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators, IContentSettings contentSettings, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators, IOptionsSnapshot contentSettings, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { _commonMapper = commonMapper; _commonTreeNodeMapper = commonTreeNodeMapper; _mediaService = mediaService; _mediaTypeService = mediaTypeService; _mediaUrlGenerators = mediaUrlGenerators; - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _tabsAndPropertiesMapper = new TabsAndPropertiesMapper(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider); } diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs index d51db33a55..70cdf05dc5 100644 --- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs @@ -5,20 +5,20 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.Services; -using Umbraco.Net; using Umbraco.Core.Security; +using Umbraco.Core.Services; using Umbraco.Extensions; -using Microsoft.Extensions.DependencyInjection; +using Umbraco.Net; using Umbraco.Web.Common.Security; -using Microsoft.AspNetCore.Routing; namespace Umbraco.Web.BackOffice.Security { @@ -28,7 +28,7 @@ namespace Umbraco.Web.BackOffice.Security public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions { private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; @@ -42,7 +42,7 @@ namespace Umbraco.Web.BackOffice.Security public ConfigureBackOfficeCookieOptions( IUmbracoContextAccessor umbracoContextAccessor, - ISecuritySettings securitySettings, + IOptionsSnapshot securitySettings, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, @@ -55,7 +55,7 @@ namespace Umbraco.Web.BackOffice.Security LinkGenerator linkGenerator) { _umbracoContextAccessor = umbracoContextAccessor; - _securitySettings = securitySettings; + _securitySettings = securitySettings.Value; _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; _runtimeState = runtimeState; @@ -230,7 +230,7 @@ namespace Umbraco.Web.BackOffice.Security } /// - /// Ensures the ticket is renewed if the is set to true + /// Ensures the ticket is renewed if the is set to true /// and the current request is for the get user seconds endpoint /// /// diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs index 13d608bd9b..5dd80411eb 100644 --- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.BackOffice.Security { @@ -13,11 +14,11 @@ namespace Umbraco.Web.BackOffice.Security /// public class ConfigureBackOfficeIdentityOptions : IConfigureOptions { - private readonly IUserPasswordConfiguration _userPasswordConfiguration; + private readonly UserPasswordConfigurationSettings _userPasswordConfiguration; - public ConfigureBackOfficeIdentityOptions(IUserPasswordConfiguration userPasswordConfiguration) + public ConfigureBackOfficeIdentityOptions(IOptionsSnapshot userPasswordConfiguration) { - _userPasswordConfiguration = userPasswordConfiguration; + _userPasswordConfiguration = userPasswordConfiguration.Value; } public void Configure(BackOfficeIdentityOptions options) diff --git a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs index e72b62b006..88e361029f 100644 --- a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs +++ b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs @@ -3,9 +3,10 @@ using System.Text; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; @@ -25,7 +26,7 @@ namespace Umbraco.Web.Common.AspNetCore private IUmbracoContext _umbracoContext; private IUmbracoContextAccessor UmbracoContextAccessor => Context.RequestServices.GetRequiredService(); private IGlobalSettings GlobalSettings => Context.RequestServices.GetRequiredService(); - private IContentSettings ContentSettings => Context.RequestServices.GetRequiredService(); + private ContentSettings ContentSettings => Context.RequestServices.GetRequiredService>().Value; private IProfilerHtml ProfilerHtml => Context.RequestServices.GetRequiredService(); private IIOHelper IOHelper => Context.RequestServices.GetRequiredService(); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index cbc374f93b..7a02b53724 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -112,7 +112,7 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine:")); diff --git a/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs b/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs index 559a02e149..76e462843e 100644 --- a/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs +++ b/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs @@ -4,8 +4,9 @@ using System.Text.RegularExpressions; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Common.ModelBinders; @@ -22,12 +23,12 @@ namespace Umbraco.Web.Common.Filters { private static readonly Regex _getPublishedModelsTypesRegex = new Regex("Umbraco.Web.PublishedModels.(\\w+)", RegexOptions.Compiled); - private readonly IExceptionFilterSettings _exceptionFilterSettings; + private readonly ExceptionFilterSettings _exceptionFilterSettings; private readonly IPublishedModelFactory _publishedModelFactory; - public ModelBindingExceptionFilter(IExceptionFilterSettings exceptionFilterSettings, IPublishedModelFactory publishedModelFactory) + public ModelBindingExceptionFilter(IOptionsSnapshot exceptionFilterSettings, IPublishedModelFactory publishedModelFactory) { - _exceptionFilterSettings = exceptionFilterSettings; + _exceptionFilterSettings = exceptionFilterSettings.Value; _publishedModelFactory = publishedModelFactory ?? throw new ArgumentNullException(nameof(publishedModelFactory)); } diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index 8685c0b8b1..eae771b930 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -4,9 +4,10 @@ using System.IO; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -22,7 +23,7 @@ namespace Umbraco.Web.Macros { private readonly IProfilingLogger _plogger; private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly ILocalizedTextService _textService; private readonly AppCaches _appCaches; private readonly IMacroService _macroService; @@ -33,11 +34,10 @@ namespace Umbraco.Web.Macros private readonly IRequestAccessor _requestAccessor; private readonly IHttpContextAccessor _httpContextAccessor; - public MacroRenderer( IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, - IContentSettings contentSettings, + IOptionsSnapshot contentSettings, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, @@ -50,7 +50,7 @@ namespace Umbraco.Web.Macros { _plogger = plogger ?? throw new ArgumentNullException(nameof(plogger)); _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _textService = textService; _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs index 959c4c27a2..a0a84e893f 100644 --- a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs @@ -26,6 +26,8 @@ using Umbraco.Web.Common.Templates; using Umbraco.Web.Common.Security; using Umbraco.Web.Security; using Umbraco.Web.Templates; +using Umbraco.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Common.Runtime { @@ -96,7 +98,7 @@ namespace Umbraco.Web.Common.Runtime composition.RegisterUnique(); composition.RegisterUnique(); - composition.RegisterUnique(factory => new LegacyPasswordSecurity(factory.GetInstance())); + composition.RegisterUnique(factory => new LegacyPasswordSecurity(factory.GetInstance>().Value)); } diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index e4773a85d5..73fa53f7bc 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -1,35 +1,30 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; -using System.Collections.Generic; -using System.Net.Mail; using System.Security.Principal; using System.Threading.Tasks; -using System.Web; using System.Web.Http; -using System.Web.Mvc; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Models; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Hosting; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Web.Models; -using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Mvc; +using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using Umbraco.Core.Persistence; -using IUser = Umbraco.Core.Models.Membership.IUser; -using Umbraco.Core.Mapping; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Hosting; -using Umbraco.Extensions; -using Umbraco.Web.Routing; using Constants = Umbraco.Core.Constants; +using IUser = Umbraco.Core.Models.Membership.IUser; namespace Umbraco.Web.Editors { @@ -47,7 +42,7 @@ namespace Umbraco.Web.Editors private readonly IUserPasswordConfiguration _passwordConfiguration; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; private readonly IRequestAccessor _requestAccessor; private readonly IEmailSender _emailSender; @@ -62,7 +57,7 @@ namespace Umbraco.Web.Editors IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, - ISecuritySettings securitySettings, + IOptionsSnapshot securitySettings, IPublishedUrlProvider publishedUrlProvider, IRequestAccessor requestAccessor, IEmailSender emailSender) @@ -71,7 +66,7 @@ namespace Umbraco.Web.Editors _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); - _securitySettings = securitySettings ?? throw new ArgumentNullException(nameof(securitySettings)); + _securitySettings = securitySettings.Value ?? throw new ArgumentNullException(nameof(securitySettings)); _requestAccessor = requestAccessor ?? throw new ArgumentNullException(nameof(securitySettings)); _emailSender = emailSender; } diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index b963871a58..4258267421 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -4,19 +4,21 @@ using System.Threading.Tasks; using System.Web; using System.Web.Mvc; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using Umbraco.Web.Mvc; -using Umbraco.Core.Services; -using Umbraco.Web.Features; -using Umbraco.Web.Security; -using Constants = Umbraco.Core.Constants; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; +using Umbraco.Core.Logging; +using Umbraco.Core.Services; +using Umbraco.Web.Features; +using Umbraco.Web.Mvc; +using Umbraco.Web.Security; using BackOfficeIdentityUser = Umbraco.Core.BackOffice.BackOfficeIdentityUser; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors { @@ -34,8 +36,8 @@ namespace Umbraco.Web.Editors private readonly IUmbracoVersion _umbracoVersion; private readonly IContentSettings _contentSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _runtimeSettings; - private readonly ISecuritySettings _securitySettings; + private readonly RuntimeSettings _runtimeSettings; + private readonly SecuritySettings _securitySettings; public BackOfficeController( UmbracoFeatures features, @@ -47,17 +49,16 @@ namespace Umbraco.Web.Editors IUmbracoVersion umbracoVersion, IContentSettings contentSettings, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings, - ISecuritySettings securitySettings) + IOptionsSnapshot runtimeSettings, + IOptionsSnapshot securitySettings) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) - { _features = features; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _hostingEnvironment = hostingEnvironment; - _runtimeSettings = settings; - _securitySettings = securitySettings; + _runtimeSettings = runtimeSettings.Value; + _securitySettings = securitySettings.Value; } protected BackOfficeSignInManager SignInManager => _signInManager ?? (_signInManager = OwinContext.GetBackOfficeSignInManager()); diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 454338112c..0dd232cbfb 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -5,18 +5,18 @@ using System.Linq; using System.Runtime.Serialization; using System.Web; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Web.Features; -using Umbraco.Web.HealthCheck; -using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Mvc; -using Umbraco.Web.Trees; -using Constants = Umbraco.Core.Constants; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.WebAssets; +using Umbraco.Web.Features; +using Umbraco.Web.Mvc; using Umbraco.Web.Security; +using Umbraco.Web.Trees; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors { @@ -34,8 +34,8 @@ namespace Umbraco.Web.Editors private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _settings; - private readonly ISecuritySettings _securitySettings; + private readonly RuntimeSettings _runtimeSettings; + private readonly SecuritySettings _securitySettings; private readonly IRuntimeMinifier _runtimeMinifier; internal BackOfficeServerVariables( @@ -47,8 +47,8 @@ namespace Umbraco.Web.Editors IContentSettings contentSettings, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings, - ISecuritySettings securitySettings, + IOptionsSnapshot runtimeSettings, + IOptionsSnapshot securitySettings, IRuntimeMinifier runtimeMinifier) { _urlHelper = urlHelper; @@ -59,8 +59,8 @@ namespace Umbraco.Web.Editors _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; - _settings = settings; - _securitySettings = securitySettings; + _runtimeSettings = runtimeSettings.Value; + _securitySettings = securitySettings.Value; _runtimeMinifier = runtimeMinifier; } @@ -288,7 +288,7 @@ namespace Umbraco.Web.Editors private string GetMaxRequestLength() { - return _settings.MaxRequestLength.HasValue ? _settings.MaxRequestLength.Value.ToString() : string.Empty; + return _runtimeSettings.MaxRequestLength.HasValue ? _runtimeSettings.MaxRequestLength.Value.ToString() : string.Empty; } } } diff --git a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs index 26b85d6c39..8a093f1943 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs @@ -1,15 +1,10 @@ -using System; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.Owin; +using Microsoft.Extensions.Options; using Microsoft.Owin.Security.Cookies; using Umbraco.Core; -using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; -using Umbraco.Core.Services; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.Security; +using Umbraco.Core.Services; namespace Umbraco.Web.Security { @@ -21,24 +16,25 @@ namespace Umbraco.Web.Security private readonly IRuntimeState _runtimeState; private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; - public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, ISecuritySettings securitySettings) + public BackOfficeCookieAuthenticationProvider( + IUserService userService, + IRuntimeState runtimeState, + IGlobalSettings globalSettings, + IHostingEnvironment hostingEnvironment, + IOptionsSnapshot securitySettings) { _userService = userService; _runtimeState = runtimeState; _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; - _securitySettings = securitySettings; + _securitySettings = securitySettings.Value; } public override void ResponseSignOut(CookieResponseSignOutContext context) - { - + { } - - - } } diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index 771c3239b6..da3500fb25 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -8,6 +8,7 @@ using Microsoft.Owin.Security.DataProtection; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Security; using Umbraco.Core.Services; @@ -20,7 +21,7 @@ namespace Umbraco.Web.Security public const string OwinMarkerKey = "Umbraco.Web.Security.Identity.BackOfficeUserManagerMarker"; public BackOfficeOwinUserManager( - IUserPasswordConfiguration passwordConfiguration, + IOptions passwordConfiguration, IIpResolver ipResolver, IUserStore store, IOptions optionsAccessor, @@ -32,7 +33,7 @@ namespace Umbraco.Web.Security ILogger> logger) : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, passwordConfiguration) { - PasswordConfiguration = passwordConfiguration; + PasswordConfiguration = passwordConfiguration.Value; InitUserManager(this, dataProtectionProvider); } @@ -47,7 +48,7 @@ namespace Umbraco.Web.Security IExternalLoginService externalLoginService, IGlobalSettings globalSettings, UmbracoMapper mapper, - IUserPasswordConfiguration passwordConfiguration, + UserPasswordConfigurationSettings passwordConfiguration, IIpResolver ipResolver, BackOfficeIdentityErrorDescriber errors, IDataProtectionProvider dataProtectionProvider, @@ -68,7 +69,7 @@ namespace Umbraco.Web.Security /// Creates a BackOfficeUserManager instance with all default options and a custom BackOfficeUserManager instance ///
public static BackOfficeOwinUserManager Create( - IUserPasswordConfiguration passwordConfiguration, + UserPasswordConfigurationSettings passwordConfiguration, IIpResolver ipResolver, IUserStore customUserStore, BackOfficeIdentityErrorDescriber errors, @@ -103,7 +104,7 @@ namespace Umbraco.Web.Security options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(30); return new BackOfficeOwinUserManager( - passwordConfiguration, + new OptionsWrapper(passwordConfiguration), ipResolver, customUserStore, new OptionsWrapper(options), diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index 3ab37f0f70..0bf83efd34 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -3,14 +3,13 @@ using System.Diagnostics; using System.Globalization; using System.Threading.Tasks; using System.Web; +using Microsoft.Extensions.Options; using Microsoft.Owin; using Microsoft.Owin.Logging; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Core.Security; namespace Umbraco.Web.Security { @@ -26,7 +25,7 @@ namespace Umbraco.Web.Security { private readonly UmbracoBackOfficeCookieAuthOptions _authOptions; private readonly IGlobalSettings _globalSettings; - private readonly ISecuritySettings _security; + private readonly SecuritySettings _securitySettings; private readonly ILogger _logger; private readonly IHostingEnvironment _hostingEnvironment; @@ -34,14 +33,14 @@ namespace Umbraco.Web.Security OwinMiddleware next, UmbracoBackOfficeCookieAuthOptions authOptions, IGlobalSettings globalSettings, - ISecuritySettings security, + IOptionsSnapshot securitySettings, ILogger logger, IHostingEnvironment hostingEnvironment) : base(next) { _authOptions = authOptions ?? throw new ArgumentNullException(nameof(authOptions)); _globalSettings = globalSettings; - _security = security; + _securitySettings = securitySettings.Value; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _hostingEnvironment = hostingEnvironment; } @@ -55,7 +54,7 @@ namespace Umbraco.Web.Security && request.Uri.AbsolutePath.InvariantEquals( $"{_globalSettings.GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) { - var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName); + var cookie = _authOptions.CookieManager.GetRequestCookie(context, _securitySettings.AuthCookieName); if (cookie.IsNullOrWhiteSpace() == false) { var ticket = _authOptions.TicketDataFormat.Unprotect(cookie); @@ -75,7 +74,7 @@ namespace Umbraco.Web.Security //Ok, so here we need to check if we want to process/renew the auth ticket for each // of these requests. If that is the case, the user will really never be logged out until they // close their browser (there will be edge cases of that, especially when debugging) - if (_security.KeepUserLoggedIn) + if (_securitySettings.KeepUserLoggedIn) { var currentUtc = _authOptions.SystemClock.UtcNow; var issuedUtc = ticket.Properties.IssuedUtc; diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index 600b58cf06..af10009a0e 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -1,20 +1,20 @@ using System; +using Microsoft.Extensions.Options; using Microsoft.Owin; using Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Mapping; -using Umbraco.Net; using Umbraco.Core.Services; +using Umbraco.Net; using Umbraco.Web; using Umbraco.Web.Composing; using Umbraco.Web.Security; - [assembly: OwinStartup("UmbracoDefaultOwinStartup", typeof(UmbracoDefaultOwinStartup))] namespace Umbraco.Web @@ -30,7 +30,7 @@ namespace Umbraco.Web protected IUmbracoContextAccessor UmbracoContextAccessor => Current.UmbracoContextAccessor; protected IGlobalSettings GlobalSettings => Current.Factory.GetInstance(); protected IContentSettings ContentSettings => Current.Factory.GetInstance(); - protected ISecuritySettings SecuritySettings => Current.Factory.GetInstance(); + protected SecuritySettings SecuritySettings => Current.Factory.GetInstance>().Value; protected IUserPasswordConfiguration UserPasswordConfig => Current.Factory.GetInstance(); protected IRuntimeState RuntimeState => Current.RuntimeState; protected ServiceContext Services => Current.Services; diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs index 0d8d4b8bf2..9a8da5a7eb 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs @@ -3,9 +3,11 @@ using System.Collections.Specialized; using System.IO; using ClientDependency.Core.CompositeFiles.Providers; using ClientDependency.Core.Config; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.Runtime; @@ -16,16 +18,16 @@ namespace Umbraco.Web.WebAssets.CDF { private readonly IHostingSettings _hostingSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _settings; + private readonly RuntimeSettings _runtimeSettings; public ClientDependencyComponent( IHostingSettings hostingSettings, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings) + IOptionsSnapshot runtimeSettings) { _hostingSettings = hostingSettings; _hostingEnvironment = hostingEnvironment; - _settings = settings; + _runtimeSettings = runtimeSettings.Value; } public void Initialize() @@ -54,10 +56,10 @@ namespace Umbraco.Web.WebAssets.CDF = Path.Combine(cachePath, "ClientDependency"); } - if (_settings.MaxQueryStringLength.HasValue || _settings.MaxRequestLength.HasValue) + if (_runtimeSettings.MaxQueryStringLength.HasValue || _runtimeSettings.MaxRequestLength.HasValue) { //set the max url length for CDF to be the smallest of the max query length, max request length - ClientDependency.Core.CompositeFiles.CompositeDependencyHandler.MaxHandlerUrlLength = Math.Min(_settings.MaxQueryStringLength.GetValueOrDefault(), _settings.MaxRequestLength.GetValueOrDefault()); + ClientDependency.Core.CompositeFiles.CompositeDependencyHandler.MaxHandlerUrlLength = Math.Min(_runtimeSettings.MaxQueryStringLength.GetValueOrDefault(), _runtimeSettings.MaxRequestLength.GetValueOrDefault()); } //Register a custom renderer - used to process property editor dependencies From 510bd92e78a6e0021c2c9891eaf39a038004226d Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Fri, 21 Aug 2020 14:52:47 +0100 Subject: [PATCH 04/58] Amended injection of further settings to use IOptionsSnapshot. --- .../AspNetCoreConfigsFactory.cs | 1 - .../Legacy/ContentSettingsExtensions.cs | 21 ++++++++ .../BackOffice/BackOfficeIdentityUser.cs | 7 +-- .../BackOffice/IdentityMapDefinition.cs | 8 +-- src/Umbraco.Core/Composing/Composition.cs | 13 ++--- .../Composing/TypeFinderConfig.cs | 6 +-- .../ConfigConnectionStringExtensions.cs | 1 - .../Configuration/GlobalSettingsExtensions.cs | 7 +-- .../Models/ConnectionStrings.cs | 18 ++++--- .../ModelsBuilderConfigExtensions.cs | 4 +- .../Configuration/UmbracoVersion.cs | 8 +-- src/Umbraco.Core/IO/IOHelper.cs | 2 +- src/Umbraco.Core/Models/Language.cs | 5 +- src/Umbraco.Core/Models/Membership/User.cs | 7 +-- .../Models/UmbracoUserExtensions.cs | 5 +- .../Packaging/PackagesRepository.cs | 6 ++- .../PublishedContentExtensions.cs | 3 +- .../Routing/ContentFinderByIdPath.cs | 8 +-- .../Routing/ContentFinderByUrlAndTemplate.cs | 8 +-- src/Umbraco.Core/Routing/PublishedRequest.cs | 8 +-- src/Umbraco.Core/Routing/PublishedRouter.cs | 8 +-- src/Umbraco.Core/Routing/UrlProvider.cs | 6 ++- src/Umbraco.Core/Umbraco.Core.csproj | 3 ++ src/Umbraco.Core/UriExtensions.cs | 6 +-- .../LuceneIndexCreator.cs | 10 ++-- .../UmbracoIndexesCreator.cs | 4 +- .../BackOffice/BackOfficeUserStore.cs | 11 ++++- .../Compose/NotificationsComponent.cs | 15 ++++-- .../CompositionExtensions/FileSystems.cs | 6 ++- .../CompositionExtensions/Services.cs | 6 ++- .../Composing/RegisterFactory.cs | 3 +- .../EmailNotificationMethod.cs | 6 +-- .../Install/FilePermissionHelper.cs | 8 +-- .../Install/InstallHelper.cs | 7 +-- .../InstallSteps/DatabaseConfigureStep.cs | 7 +-- .../InstallSteps/DatabaseInstallStep.cs | 10 +--- .../InstallSteps/DatabaseUpgradeStep.cs | 14 +++--- .../Install/InstallSteps/NewInstallStep.cs | 9 ++-- .../Migrations/Install/DatabaseBuilder.cs | 8 +-- .../Migrations/Install/DatabaseDataCreator.cs | 5 +- .../Install/DatabaseSchemaCreator.cs | 5 +- .../Migrations/Upgrade/UmbracoPlan.cs | 5 +- .../Mapping/ContentTypeMapDefinition.cs | 9 ++-- .../Models/Mapping/UserMapDefinition.cs | 8 +-- .../Packaging/PackageDataInstallation.cs | 5 +- .../Persistence/Factories/LanguageFactory.cs | 3 +- .../Persistence/Factories/UserFactory.cs | 3 +- .../Implement/LanguageRepository.cs | 8 +-- .../Implement/ScriptRepository.cs | 8 +-- .../Implement/StylesheetRepository.cs | 8 +-- .../Repositories/Implement/UserRepository.cs | 8 +-- .../Persistence/UmbracoDatabaseFactory.cs | 7 +-- .../Routing/RedirectTrackingComponent.cs | 9 ++-- .../Runtime/CoreInitialComponent.cs | 10 ++-- .../Runtime/CoreRuntime.cs | 24 ++++----- .../Runtime/SqlMainDomLock.cs | 3 +- src/Umbraco.Infrastructure/RuntimeState.cs | 5 +- .../Services/Implement/FileService.cs | 8 +-- .../Services/Implement/NotificationService.cs | 8 +-- .../Services/Implement/UserService.cs | 8 +-- .../Users/EmailSender.cs | 19 +++++-- .../BackOfficeJavaScriptInitializer.cs | 3 +- .../WebAssets/BackOfficeWebAssets.cs | 8 +-- .../WebAssets/RuntimeMinifierExtensions.cs | 3 +- .../BackOffice/ContentTypeModelValidator.cs | 5 +- .../ContentTypeModelValidatorBase.cs | 9 ++-- .../BackOffice/DashboardReport.cs | 5 +- .../BackOffice/MediaTypeModelValidator.cs | 5 +- .../ModelsBuilderDashboardController.cs | 10 ++-- .../Building/Builder.cs | 3 +- .../Building/ModelsGenerator.cs | 5 +- .../Building/TextBuilder.cs | 4 +- .../Compose/ModelsBuilderComponent.cs | 8 +-- .../LiveModelsProvider.cs | 5 +- .../ModelsGenerationError.cs | 5 +- .../OutOfDateModelsStatus.cs | 5 +- .../PureLiveModelFactory.cs | 6 ++- .../ContentCache.cs | 11 ++++- .../DataSource/BTree.cs | 6 +-- .../PublishedSnapshotService.cs | 15 +++--- src/Umbraco.Tests.Common/SettingsForTests.cs | 38 +++++++------- src/Umbraco.Tests.Common/TestHelperBase.cs | 2 +- .../Implementations/TestHostingEnvironment.cs | 6 +-- .../BackOfficeCookieManagerTests.cs | 10 ++-- .../Extensions/UriExtensionsTests.cs | 2 +- .../TestHelpers/SettingsForTests.cs | 5 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 2 +- .../TestHelpers/TestObjects-Mocks.cs | 4 +- .../Controllers/AuthenticationController.cs | 6 +-- .../Controllers/BackOfficeAssetsController.cs | 6 ++- .../Controllers/BackOfficeController.cs | 10 ++-- .../Controllers/BackOfficeServerVariables.cs | 6 +-- .../Controllers/CodeFileController.cs | 20 +++----- .../Controllers/ContentTypeController.cs | 9 ++-- .../Controllers/DashboardController.cs | 1 - .../Controllers/DictionaryController.cs | 8 +-- .../Controllers/LanguageController.cs | 8 +-- .../Controllers/PreviewController.cs | 8 +-- .../RedirectUrlManagementController.cs | 8 +-- .../Controllers/UpdateCheckController.cs | 14 +++--- .../Controllers/UsersController.cs | 6 +-- .../SetAngularAntiForgeryTokensAttribute.cs | 9 ++-- .../UmbracoWebApiRequireHttpsAttribute.cs | 9 ++-- .../Routing/BackOfficeAreaRoutes.cs | 8 +-- .../Security/BackOfficeCookieManager.cs | 19 ++++--- .../ConfigureBackOfficeCookieOptions.cs | 6 +-- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 10 +++- .../AspNetCoreHostingEnvironment.cs | 14 ++++-- .../AspNetCore/AspNetCoreRequestAccessor.cs | 8 +-- .../AspNetCore/UmbracoViewPage.cs | 2 +- .../Extensions/HttpRequestExtensions.cs | 3 +- .../UmbracoCoreServiceCollectionExtensions.cs | 49 ++++++++++--------- .../UmbracoWebServiceCollectionExtensions.cs | 18 +++---- .../Filters/StatusCodeResultAttribute.cs | 4 +- .../Install/InstallController.cs | 8 +-- .../Runtime/AspNetCoreComposer.cs | 27 +++++----- .../Security/WebSecurity.cs | 14 +++--- .../Templates/TemplateRenderer.cs | 8 +-- .../UmbracoContext/UmbracoContext.cs | 6 ++- .../UmbracoContext/UmbracoContextFactory.cs | 8 +-- .../UmbracoBackOffice/AuthorizeUpgrade.cshtml | 9 ++-- .../Umbraco/UmbracoBackOffice/Default.cshtml | 8 +-- .../umbraco/UmbracoBackOffice/Default.cshtml | 10 ++-- .../umbraco/UmbracoBackOffice/Preview.cshtml | 5 +- src/Umbraco.Web/AppBuilderExtensions.cs | 3 +- .../AspNet/AspNetBackOfficeInfo.cs | 13 +++-- .../AspNet/AspNetHostingEnvironment.cs | 12 ++--- .../AspNet/AspNetRequestAccessor.cs | 10 ++-- .../Compose/AuditEventsComponent.cs | 10 ++-- .../BackOfficeUserAuditEventsComponent.cs | 8 +-- .../Editors/AuthenticationController.cs | 8 +-- .../Editors/BackOfficeController.cs | 2 +- .../Editors/BackOfficeServerVariables.cs | 6 +-- .../UmbracoAuthorizedJsonController.cs | 4 +- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 7 +-- .../Mvc/AreaRegistrationExtensions.cs | 6 +-- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 13 +++-- src/Umbraco.Web/Mvc/PluginControllerArea.cs | 13 +++-- src/Umbraco.Web/Mvc/RenderMvcController.cs | 6 +-- .../Mvc/RenderNoContentController.cs | 8 +-- .../Mvc/UmbracoAuthorizedController.cs | 6 ++- src/Umbraco.Web/Mvc/UmbracoController.cs | 19 +++---- .../Mvc/UmbracoViewPageOfTModel.cs | 16 +++--- src/Umbraco.Web/RoutableDocumentFilter.cs | 27 +++++----- .../Runtime/WebInitialComponent.cs | 12 +++-- .../Security/AppBuilderExtensions.cs | 5 +- .../BackOfficeCookieAuthenticationProvider.cs | 6 +-- .../Security/BackOfficeOwinUserManager.cs | 2 +- .../Security/BackOfficeSignInManager.cs | 18 +++++-- .../Security/GetUserSecondsMiddleWare.cs | 6 +-- src/Umbraco.Web/UmbracoApplicationBase.cs | 5 +- src/Umbraco.Web/UmbracoContext.cs | 5 +- src/Umbraco.Web/UmbracoContextFactory.cs | 8 +-- .../WebApi/UmbracoApiController.cs | 4 +- .../WebApi/UmbracoApiControllerBase.cs | 15 +++--- .../WebApi/UmbracoAuthorizedApiController.cs | 4 +- .../CDF/ClientDependencyComponent.cs | 6 +-- 157 files changed, 774 insertions(+), 550 deletions(-) create mode 100644 src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/Models/ConnectionStrings.cs (80%) diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index 45d6498ff4..ec87be7b3d 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -41,7 +41,6 @@ namespace Umbraco.Configuration //configs.Add(() => new ModelsBuilderConfig(_configuration)); //configs.Add(() => new HostingSettings(_configuration)); //configs.Add(() => new GlobalSettings(_configuration)); - configs.Add(() => new ConnectionStrings(_configuration)); //configs.Add(() => new ImagingSettings(_configuration)); return configs; diff --git a/src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs b/src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs new file mode 100644 index 0000000000..87b83416ac --- /dev/null +++ b/src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs @@ -0,0 +1,21 @@ +using System.Linq; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Core.Configuration +{ + public static class ContentSettingsExtensions + { + /// + /// Determines if file extension is allowed for upload based on (optional) white list and black list + /// held in settings. + /// Allow upload if extension is whitelisted OR if there is no whitelist and extension is NOT blacklisted. + /// + public static bool IsFileAllowedForUpload(this IContentSettings contentSettings, string extension) + { + return contentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)) || + (contentSettings.AllowedUploadFiles.Any() == false && + contentSettings.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false); + } + } +} diff --git a/src/Umbraco.Core/BackOffice/BackOfficeIdentityUser.cs b/src/Umbraco.Core/BackOffice/BackOfficeIdentityUser.cs index 8df253b296..bd04b44b18 100644 --- a/src/Umbraco.Core/BackOffice/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Core/BackOffice/BackOfficeIdentityUser.cs @@ -5,6 +5,7 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Identity; using Umbraco.Core.Models.Membership; @@ -39,7 +40,7 @@ namespace Umbraco.Core.BackOffice /// This is allowed to be null (but would need to be filled in if trying to persist this instance) /// /// - public static BackOfficeIdentityUser CreateNew(IGlobalSettings globalSettings, string username, string email, string culture) + public static BackOfficeIdentityUser CreateNew(GlobalSettings globalSettings, string username, string email, string culture) { if (string.IsNullOrWhiteSpace(username)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(username)); if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(culture)); @@ -57,7 +58,7 @@ namespace Umbraco.Core.BackOffice return user; } - private BackOfficeIdentityUser(IGlobalSettings globalSettings, IReadOnlyUserGroup[] groups) + private BackOfficeIdentityUser(GlobalSettings globalSettings, IReadOnlyUserGroup[] groups) { _startMediaIds = Array.Empty(); _startContentIds = Array.Empty(); @@ -78,7 +79,7 @@ namespace Umbraco.Core.BackOffice /// /// /// - public BackOfficeIdentityUser(IGlobalSettings globalSettings, int userId, IEnumerable groups) + public BackOfficeIdentityUser(GlobalSettings globalSettings, int userId, IEnumerable groups) : this(globalSettings, groups.ToArray()) { // use the property setters - they do more than just setting a field diff --git a/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs b/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs index e8d16a7903..e002ea1c8d 100644 --- a/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs +++ b/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs @@ -1,5 +1,7 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; @@ -11,13 +13,13 @@ namespace Umbraco.Core.BackOffice { private readonly ILocalizedTextService _textService; private readonly IEntityService _entityService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public IdentityMapDefinition(ILocalizedTextService textService, IEntityService entityService, IGlobalSettings globalSettings) + public IdentityMapDefinition(ILocalizedTextService textService, IEntityService entityService, IOptionsSnapshot globalSettings) { _textService = textService; _entityService = entityService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void DefineMaps(UmbracoMapper mapper) diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index f6e8655575..72d45605a6 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -21,7 +21,6 @@ namespace Umbraco.Core.Composing private readonly Dictionary> _uniques = new Dictionary>(); private readonly IRegister _register; - /// /// Initializes a new instance of the class. /// @@ -29,16 +28,14 @@ namespace Umbraco.Core.Composing /// A type loader. /// A logger. /// The runtime state. - /// Optional configs. /// An IOHelper /// - public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs, IIOHelper ioHelper, AppCaches appCaches) + public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, IIOHelper ioHelper, AppCaches appCaches) { _register = register ?? throw new ArgumentNullException(nameof(register)); TypeLoader = typeLoader ?? throw new ArgumentNullException(nameof(typeLoader)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); RuntimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); - Configs = configs ?? throw new ArgumentNullException(nameof(configs)); IOHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); AppCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); } @@ -63,11 +60,6 @@ namespace Umbraco.Core.Composing ///
public IRuntimeState RuntimeState { get; } - /// - /// Gets the configurations. - /// - public Configs Configs { get; } - #endregion #region IRegister @@ -136,7 +128,8 @@ namespace Umbraco.Core.Composing IFactory factory = null; - Configs.RegisterWith(_register); + // TODO: what to do about this? + //Configs.RegisterWith(_register); // ReSharper disable once AccessToModifiedClosure -- on purpose _register.Register(_ => factory, Lifetime.Singleton); diff --git a/src/Umbraco.Core/Composing/TypeFinderConfig.cs b/src/Umbraco.Core/Composing/TypeFinderConfig.cs index 9a3cd7072c..cf043ab381 100644 --- a/src/Umbraco.Core/Composing/TypeFinderConfig.cs +++ b/src/Umbraco.Core/Composing/TypeFinderConfig.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Core.Composing @@ -11,10 +11,10 @@ namespace Umbraco.Core.Composing ///
public class TypeFinderConfig : ITypeFinderConfig { - private readonly ITypeFinderSettings _settings; + private readonly TypeFinderSettings _settings; private IEnumerable _assembliesAcceptingLoadExceptions; - public TypeFinderConfig(ITypeFinderSettings settings) + public TypeFinderConfig(TypeFinderSettings settings) { _settings = settings; } diff --git a/src/Umbraco.Core/ConfigConnectionStringExtensions.cs b/src/Umbraco.Core/ConfigConnectionStringExtensions.cs index 693b8a433e..8047af88c5 100644 --- a/src/Umbraco.Core/ConfigConnectionStringExtensions.cs +++ b/src/Umbraco.Core/ConfigConnectionStringExtensions.cs @@ -5,7 +5,6 @@ using Umbraco.Core.Configuration; namespace Umbraco.Core { - public static class ConfigConnectionStringExtensions { public static bool IsConnectionStringConfigured(this ConfigConnectionString databaseSettings) diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs index a9a7f578d0..f9b2362e14 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; namespace Umbraco.Core.Configuration @@ -14,7 +15,7 @@ namespace Umbraco.Core.Configuration /// /// /// - public static string GetBackOfficePath(this IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static string GetBackOfficePath(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { if (_backOfficePath != null) return _backOfficePath; _backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); @@ -32,7 +33,7 @@ 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, IHostingEnvironment hostingEnvironment) + public static string GetUmbracoMvcArea(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { if (_mvcArea != null) return _mvcArea; @@ -41,7 +42,7 @@ namespace Umbraco.Core.Configuration return _mvcArea; } - internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + internal static string GetUmbracoMvcAreaNoCache(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var path = string.IsNullOrEmpty(globalSettings.UmbracoPath) ? string.Empty diff --git a/src/Umbraco.Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs similarity index 80% rename from src/Umbraco.Configuration/Models/ConnectionStrings.cs rename to src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index 586765714c..9d038ed17c 100644 --- a/src/Umbraco.Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -1,25 +1,27 @@ using System; +using System.Collections.Generic; using System.Data.Common; -using Microsoft.Extensions.Configuration; +using System.Text.Json.Serialization; using Umbraco.Core; using Umbraco.Core.Configuration; namespace Umbraco.Configuration.Models { - public class ConnectionStrings : IConnectionStrings + public class ConnectionStrings { - private readonly IConfiguration _configuration; + [JsonPropertyName(Constants.System.UmbracoConnectionName)] + public string UmbracoConnectionString { get; set; } - public ConnectionStrings(IConfiguration configuration) - { - _configuration = configuration; - } + private Dictionary AsDictionary() => new Dictionary + { + { Constants.System.UmbracoConnectionName, UmbracoConnectionString } + }; public ConfigConnectionString this[string key] { get { - var connectionString = _configuration.GetConnectionString(key); + var connectionString = this.AsDictionary()[key]; var provider = ParseProvider(connectionString); return new ConfigConnectionString(connectionString, provider, key); } diff --git a/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs b/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs index 3e3b116395..4117d904b9 100644 --- a/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs +++ b/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs @@ -1,5 +1,6 @@ using System.Configuration; using System.IO; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.Core.Configuration @@ -8,9 +9,8 @@ namespace Umbraco.Core.Configuration { private static string _modelsDirectoryAbsolute = null; - public static string ModelsDirectoryAbsolute(this IModelsBuilderConfig modelsBuilderConfig, IIOHelper ioHelper) + public static string ModelsDirectoryAbsolute(this ModelsBuilderConfig modelsBuilderConfig, IIOHelper ioHelper) { - if (_modelsDirectoryAbsolute is null) { var modelsDirectory = modelsBuilderConfig.ModelsDirectory; diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index 0ddac4a8bd..3ae59189fa 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -1,7 +1,7 @@ using System; -using System.Configuration; using System.Reflection; using Semver; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Core.Configuration { @@ -10,10 +10,10 @@ namespace Umbraco.Core.Configuration ///
public class UmbracoVersion : IUmbracoVersion { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public UmbracoVersion(IGlobalSettings globalSettings) - : this() + public UmbracoVersion(GlobalSettings globalSettings) + : this() { _globalSettings = globalSettings; } diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index a8a34e2e93..3885930031 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.IO { private readonly IHostingEnvironment _hostingEnvironment; - public IOHelper(IHostingEnvironment hostingEnvironment, IGlobalSettings globalSettings) + public IOHelper(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); } diff --git a/src/Umbraco.Core/Models/Language.cs b/src/Umbraco.Core/Models/Language.cs index e83c59443d..0ac8526181 100644 --- a/src/Umbraco.Core/Models/Language.cs +++ b/src/Umbraco.Core/Models/Language.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Runtime.Serialization; using System.Threading; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models @@ -14,7 +15,7 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class Language : EntityBase, ILanguage { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private string _isoCode; private string _cultureName; @@ -22,7 +23,7 @@ namespace Umbraco.Core.Models private bool _mandatory; private int? _fallbackLanguageId; - public Language(IGlobalSettings globalSettings, string isoCode) + public Language(GlobalSettings globalSettings, string isoCode) { IsoCode = isoCode; _globalSettings = globalSettings; diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index 43cedec951..7599997750 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Runtime.Serialization; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models.Membership @@ -18,7 +19,7 @@ namespace Umbraco.Core.Models.Membership /// /// Constructor for creating a new/empty user /// - public User(IGlobalSettings globalSettings) + public User(GlobalSettings globalSettings) { SessionTimeout = 60; _userGroups = new HashSet(); @@ -38,7 +39,7 @@ namespace Umbraco.Core.Models.Membership /// /// /// - public User(IGlobalSettings globalSettings, string name, string email, string username, string rawPasswordValue) + public User(GlobalSettings globalSettings, string name, string email, string username, string rawPasswordValue) : this(globalSettings) { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(name)); @@ -69,7 +70,7 @@ namespace Umbraco.Core.Models.Membership /// /// /// - public User(IGlobalSettings globalSettings, int id, string name, string email, string username, + public User(GlobalSettings globalSettings, int id, string name, string email, string username, string rawPasswordValue, string passwordConfig, IEnumerable userGroups, int[] startContentIds, int[] startMediaIds) : this(globalSettings) diff --git a/src/Umbraco.Core/Models/UmbracoUserExtensions.cs b/src/Umbraco.Core/Models/UmbracoUserExtensions.cs index 6ed3e6279b..18684f7946 100644 --- a/src/Umbraco.Core/Models/UmbracoUserExtensions.cs +++ b/src/Umbraco.Core/Models/UmbracoUserExtensions.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; @@ -48,14 +49,14 @@ namespace Umbraco.Core.Models /// /// /// - public static CultureInfo GetUserCulture(this IUser user, ILocalizedTextService textService, IGlobalSettings globalSettings) + public static CultureInfo GetUserCulture(this IUser user, ILocalizedTextService textService, GlobalSettings globalSettings) { if (user == null) throw new ArgumentNullException(nameof(user)); if (textService == null) throw new ArgumentNullException(nameof(textService)); return GetUserCulture(user.Language, textService, globalSettings); } - public static CultureInfo GetUserCulture(string userLanguage, ILocalizedTextService textService, IGlobalSettings globalSettings) + public static CultureInfo GetUserCulture(string userLanguage, ILocalizedTextService textService, GlobalSettings globalSettings) { try { diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index 0764378b06..b73747fab8 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -5,7 +5,9 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Xml.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -61,7 +63,7 @@ namespace Umbraco.Core.Packaging IHostingEnvironment hostingEnvironment, IEntityXmlSerializer serializer, ILogger logger, IUmbracoVersion umbracoVersion, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, string packageRepositoryFileName, string tempFolderPath = null, string packagesFolderPath = null, string mediaFolderPath = null) { @@ -79,7 +81,7 @@ namespace Umbraco.Core.Packaging _tempFolderPath = tempFolderPath ?? Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles"; _packagesFolderPath = packagesFolderPath ?? Constants.SystemDirectories.Packages; - _mediaFolderPath = mediaFolderPath ?? globalSettings.UmbracoMediaPath + "/created-packages"; + _mediaFolderPath = mediaFolderPath ?? globalSettings.Value.UmbracoMediaPath + "/created-packages"; _parser = new PackageDefinitionXmlParser(logger, umbracoVersion); _umbracoVersion = umbracoVersion; diff --git a/src/Umbraco.Core/PublishedContentExtensions.cs b/src/Umbraco.Core/PublishedContentExtensions.cs index 03ce0c066a..62f48917c3 100644 --- a/src/Umbraco.Core/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/PublishedContentExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -149,7 +150,7 @@ namespace Umbraco.Core } public static bool IsAllowedTemplate(this IPublishedContent content, IContentTypeService contentTypeService, - IWebRoutingSettings webRoutingSettings, int templateId) + WebRoutingSettings webRoutingSettings, int templateId) { return content.IsAllowedTemplate(contentTypeService, webRoutingSettings.DisableAlternativeTemplates, diff --git a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs index 4b58832e8e..3d69f8ab46 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs @@ -4,6 +4,8 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; using System.Globalization; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Routing { @@ -17,11 +19,11 @@ namespace Umbraco.Web.Routing { private readonly ILogger _logger; private readonly IRequestAccessor _requestAccessor; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; - public ContentFinderByIdPath(IWebRoutingSettings webRoutingSettings, ILogger logger, IRequestAccessor requestAccessor) + public ContentFinderByIdPath(IOptionsSnapshot webRoutingSettings, ILogger logger, IRequestAccessor requestAccessor) { - _webRoutingSettings = webRoutingSettings ?? throw new System.ArgumentNullException(nameof(webRoutingSettings)); + _webRoutingSettings = webRoutingSettings.Value ?? throw new System.ArgumentNullException(nameof(webRoutingSettings)); _logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); _requestAccessor = requestAccessor; } diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs b/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs index 7bcea4681e..47dc729654 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs @@ -3,6 +3,8 @@ using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Routing { @@ -19,14 +21,14 @@ namespace Umbraco.Web.Routing private readonly IFileService _fileService; private readonly IContentTypeService _contentTypeService; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; - public ContentFinderByUrlAndTemplate(ILogger logger, IFileService fileService, IContentTypeService contentTypeService, IWebRoutingSettings webRoutingSettings) + public ContentFinderByUrlAndTemplate(ILogger logger, IFileService fileService, IContentTypeService contentTypeService, IOptionsSnapshot webRoutingSettings) : base(logger) { _fileService = fileService; _contentTypeService = contentTypeService; - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; } /// diff --git a/src/Umbraco.Core/Routing/PublishedRequest.cs b/src/Umbraco.Core/Routing/PublishedRequest.cs index a46eb26e7e..24bad199a5 100644 --- a/src/Umbraco.Core/Routing/PublishedRequest.cs +++ b/src/Umbraco.Core/Routing/PublishedRequest.cs @@ -5,6 +5,8 @@ using System.Threading; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Routing { @@ -16,7 +18,7 @@ namespace Umbraco.Web.Routing public class PublishedRequest : IPublishedRequest { private readonly IPublishedRouter _publishedRouter; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private bool _readonly; // after prepared private bool _readonlyUri; // after preparing @@ -33,11 +35,11 @@ namespace Umbraco.Web.Routing /// The published router. /// The Umbraco context. /// The request Uri. - public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IWebRoutingSettings webRoutingSettings, Uri uri = null) + public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IOptionsSnapshot webRoutingSettings, Uri uri = null) { UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; Uri = uri ?? umbracoContext.CleanedUmbracoUrl; } diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs index 1a422dea92..d77f64ca5e 100644 --- a/src/Umbraco.Core/Routing/PublishedRouter.cs +++ b/src/Umbraco.Core/Routing/PublishedRouter.cs @@ -10,6 +10,8 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Web.Security; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Routing { @@ -18,7 +20,7 @@ namespace Umbraco.Web.Routing /// public class PublishedRouter : IPublishedRouter { - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly ContentFinderCollection _contentFinders; private readonly IContentLastChanceFinder _contentLastChanceFinder; private readonly IProfilingLogger _profilingLogger; @@ -36,7 +38,7 @@ namespace Umbraco.Web.Routing /// Initializes a new instance of the class. ///
public PublishedRouter( - IWebRoutingSettings webRoutingSettings, + IOptionsSnapshot webRoutingSettings, ContentFinderCollection contentFinders, IContentLastChanceFinder contentLastChanceFinder, IVariationContextAccessor variationContextAccessor, @@ -49,7 +51,7 @@ namespace Umbraco.Web.Routing IContentTypeService contentTypeService, IPublicAccessService publicAccessService) { - _webRoutingSettings = webRoutingSettings ?? throw new ArgumentNullException(nameof(webRoutingSettings)); + _webRoutingSettings = webRoutingSettings.Value ?? throw new ArgumentNullException(nameof(webRoutingSettings)); _contentFinders = contentFinders ?? throw new ArgumentNullException(nameof(contentFinders)); _contentLastChanceFinder = contentLastChanceFinder ?? throw new ArgumentNullException(nameof(contentLastChanceFinder)); _profilingLogger = proflog ?? throw new ArgumentNullException(nameof(proflog)); diff --git a/src/Umbraco.Core/Routing/UrlProvider.cs b/src/Umbraco.Core/Routing/UrlProvider.cs index fa764cf7ff..9e1dd9a01d 100644 --- a/src/Umbraco.Core/Routing/UrlProvider.cs +++ b/src/Umbraco.Core/Routing/UrlProvider.cs @@ -4,6 +4,8 @@ using System.Linq; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Routing { @@ -24,7 +26,7 @@ namespace Umbraco.Web.Routing /// The list of media url providers. /// The current variation accessor. /// - public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IWebRoutingSettings routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor) + public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IOptionsSnapshot routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor) { if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings)); @@ -35,7 +37,7 @@ namespace Umbraco.Web.Routing var provider = UrlMode.Auto; Mode = provider; - if (Enum.TryParse(routingSettings.UrlProviderMode, out provider)) + if (Enum.TryParse(routingSettings.Value.UrlProviderMode, out provider)) { Mode = provider; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 3b7ccb1775..067b26e0f0 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -27,6 +27,9 @@ <_Parameter1>Umbraco.Tests + + <_Parameter1>Umbraco.Tests.Common + <_Parameter1>Umbraco.Tests.UnitTests diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 13aa6bde46..9a49df7d95 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -3,8 +3,8 @@ using System.IO; using System.Linq; using Umbraco.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; namespace Umbraco.Core { @@ -38,7 +38,7 @@ namespace Umbraco.Core /// But if we've got this far we'll just have to assume it's front-end anyways. /// /// - public static bool IsBackOfficeRequest(this Uri url, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static bool IsBackOfficeRequest(this Uri url, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var applicationPath = hostingEnvironment.ApplicationVirtualPath; @@ -128,7 +128,7 @@ namespace Umbraco.Core /// /// /// - internal static bool IsDefaultBackOfficeRequest(this Uri url, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + internal static bool IsDefaultBackOfficeRequest(this Uri url, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment); if (url.AbsolutePath.InvariantEquals(backOfficePath.TrimEnd("/")) diff --git a/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs b/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs index 9efcdc4891..6edbb05b85 100644 --- a/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs +++ b/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs @@ -4,11 +4,11 @@ using System.IO; using Examine; using Examine.LuceneEngine.Directories; using Lucene.Net.Store; -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; namespace Umbraco.Examine { @@ -20,13 +20,13 @@ namespace Umbraco.Examine { private readonly ITypeFinder _typeFinder; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IIndexCreatorSettings _settings; + private readonly IndexCreatorSettings _settings; - protected LuceneIndexCreator(ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IIndexCreatorSettings settings) + protected LuceneIndexCreator(ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IOptionsSnapshot settings) { _typeFinder = typeFinder; _hostingEnvironment = hostingEnvironment; - _settings = settings; + _settings = settings.Value; } public abstract IEnumerable Create(); diff --git a/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs b/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs index 3cf7d6d386..09dc40b32b 100644 --- a/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs +++ b/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs @@ -9,6 +9,8 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Hosting; using Umbraco.Core.IO; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Examine { @@ -28,7 +30,7 @@ namespace Umbraco.Examine IUmbracoIndexConfig umbracoIndexConfig, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, - IIndexCreatorSettings settings) : base(typeFinder, hostingEnvironment, settings) + IOptionsSnapshot settings) : base(typeFinder, hostingEnvironment, settings) { ProfilingLogger = profilingLogger ?? throw new System.ArgumentNullException(nameof(profilingLogger)); LanguageService = languageService ?? throw new System.ArgumentNullException(nameof(languageService)); diff --git a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs index 96b3d8559a..7c2eb1adfd 100644 --- a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs @@ -5,7 +5,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Models.Identity; @@ -32,11 +34,16 @@ namespace Umbraco.Core.BackOffice private readonly IUserService _userService; private readonly IEntityService _entityService; private readonly IExternalLoginService _externalLoginService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly UmbracoMapper _mapper; private bool _disposed = false; - public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, IGlobalSettings globalSettings, UmbracoMapper mapper) + public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, IOptionsSnapshot globalSettings, UmbracoMapper mapper) + : this(userService, entityService, externalLoginService, globalSettings.Value, mapper) + { + } + + public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, GlobalSettings globalSettings, UmbracoMapper mapper) { _userService = userService; _entityService = entityService; diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs index 3a4b8a5fac..c725826fd7 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -153,7 +155,7 @@ namespace Umbraco.Web.Compose private readonly INotificationService _notificationService; private readonly IUserService _userService; private readonly ILocalizedTextService _textService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly ILogger _logger; /// @@ -166,14 +168,21 @@ namespace Umbraco.Web.Compose /// /// /// - public Notifier(IUmbracoContextAccessor umbracoContextAccessor, IRequestAccessor requestAccessor, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, ILogger logger) + public Notifier( + IUmbracoContextAccessor umbracoContextAccessor, + IRequestAccessor requestAccessor, + INotificationService notificationService, + IUserService userService, + ILocalizedTextService textService, + IOptionsSnapshot globalSettings, + ILogger logger) { _umbracoContextAccessor = umbracoContextAccessor; _requestAccessor = requestAccessor; _notificationService = notificationService; _userService = userService; _textService = textService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _logger = logger; } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs index 9dc130fcba..fec14bfbd2 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs @@ -1,4 +1,6 @@ -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.IO.MediaPathSchemes; @@ -97,7 +99,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions var ioHelper = factory.GetInstance(); var hostingEnvironment = factory.GetInstance(); var logger = factory.GetInstance(); - var globalSettings = factory.GetInstance(); + var globalSettings = factory.GetInstance>().Value; var rootPath = hostingEnvironment.MapPathWebRoot(globalSettings.UmbracoMediaPath); var rootUrl = hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath); diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs index 980dd1c11e..dd4db120ce 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs @@ -1,8 +1,10 @@ using System; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -94,13 +96,13 @@ namespace Umbraco.Core.Composing.CompositionExtensions factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), - factory.GetInstance(), + factory.GetInstance>(), packageRepoFileName); private static LocalizedTextServiceFileSources SourcesFactory(IFactory container) { var hostingEnvironment = container.GetInstance(); - var globalSettings = container.GetInstance(); + var globalSettings = container.GetInstance>().Value; var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.UmbracoPath , "config","lang"))); var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins)); var configLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Config ,"lang"))); diff --git a/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs b/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs index 835bd0b9a8..d6c0e74d75 100644 --- a/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs +++ b/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs @@ -6,6 +6,7 @@ using System; using System.Reflection; using Umbraco.Core.Composing.LightInject; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Core.Composing { @@ -29,7 +30,7 @@ namespace Umbraco.Core.Composing /// To override the default LightInjectContainer, add an appSetting named 'Umbraco.Core.RegisterType' with /// a fully qualified type name to a class with a static method "Create" returning an IRegister. /// - public static IRegister Create(IGlobalSettings globalSettings) + public static IRegister Create(GlobalSettings globalSettings) { Type type; diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index 5ddf9aa288..96eee5f458 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -17,13 +17,13 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods private readonly ILocalizedTextService _textService; private readonly IRequestAccessor _requestAccessor; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly ContentSettings _contentSettings; public EmailNotificationMethod( ILocalizedTextService textService, IRequestAccessor requestAccessor, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHealthChecksSettings healthChecksSettings, IOptionsSnapshot contentSettings) : base(healthChecksSettings) @@ -39,7 +39,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods _textService = textService ?? throw new ArgumentNullException(nameof(textService)); _requestAccessor = requestAccessor; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); } diff --git a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs index 4c3edf0a1b..d5dc5307ab 100644 --- a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs @@ -8,6 +8,8 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Install; using Umbraco.Core.IO; using Umbraco.Web.PublishedCache; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Install { @@ -19,13 +21,13 @@ namespace Umbraco.Web.Install // ensure Umbraco can write to these files (the directories must exist) private readonly string[] _permissionFiles = { }; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly IPublishedSnapshotService _publishedSnapshotService; - public FilePermissionHelper(IGlobalSettings globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService) + public FilePermissionHelper(IOptionsSnapshot globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService) { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _ioHelper = ioHelper; _publishedSnapshotService = publishedSnapshotService; _permissionDirs = new[] { _globalSettings.UmbracoCssPath, Constants.SystemDirectories.Config, Constants.SystemDirectories.Data, _globalSettings.UmbracoMediaPath, Constants.SystemDirectories.Preview }; diff --git a/src/Umbraco.Infrastructure/Install/InstallHelper.cs b/src/Umbraco.Infrastructure/Install/InstallHelper.cs index 1333363355..b9729f4e1b 100644 --- a/src/Umbraco.Infrastructure/Install/InstallHelper.cs +++ b/src/Umbraco.Infrastructure/Install/InstallHelper.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Web.Install.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Install { @@ -22,7 +23,7 @@ namespace Umbraco.Web.Install private readonly DatabaseBuilder _databaseBuilder; private readonly ILogger _logger; private readonly IUmbracoVersion _umbracoVersion; - private readonly IConnectionStrings _connectionStrings; + private readonly ConnectionStrings _connectionStrings; private readonly IInstallationService _installationService; private readonly ICookieManager _cookieManager; private readonly IUserAgentProvider _userAgentProvider; @@ -33,7 +34,7 @@ namespace Umbraco.Web.Install public InstallHelper(DatabaseBuilder databaseBuilder, ILogger logger, IUmbracoVersion umbracoVersion, - IConnectionStrings connectionStrings, + IOptionsSnapshot connectionStrings, IInstallationService installationService, ICookieManager cookieManager, IUserAgentProvider userAgentProvider, @@ -43,7 +44,7 @@ namespace Umbraco.Web.Install _logger = logger; _umbracoVersion = umbracoVersion; _databaseBuilder = databaseBuilder; - _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); + _connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings)); _installationService = installationService; _cookieManager = cookieManager; _userAgentProvider = userAgentProvider; diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs index 0c88c7a096..0691f39e80 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Web.Install.Models; using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Install.InstallSteps { @@ -16,12 +17,12 @@ namespace Umbraco.Web.Install.InstallSteps { private readonly DatabaseBuilder _databaseBuilder; private readonly ILogger _logger; - private readonly IConnectionStrings _connectionStrings; + private readonly ConnectionStrings _connectionStrings; - public DatabaseConfigureStep(DatabaseBuilder databaseBuilder, IConnectionStrings connectionStrings) + public DatabaseConfigureStep(DatabaseBuilder databaseBuilder, IOptionsSnapshot connectionStrings) { _databaseBuilder = databaseBuilder; - _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); + _connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings)); } public override Task ExecuteAsync(DatabaseModel database) diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseInstallStep.cs index b3086672d8..e5f783caba 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseInstallStep.cs @@ -16,19 +16,11 @@ namespace Umbraco.Web.Install.InstallSteps { private readonly DatabaseBuilder _databaseBuilder; private readonly IRuntimeState _runtime; - private readonly ILogger _logger; - private readonly IIOHelper _ioHelper; - private readonly IConnectionStrings _connectionStrings; - private readonly IConfigManipulator _configManipulator; - public DatabaseInstallStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger, IIOHelper ioHelper, IConnectionStrings connectionStrings, IConfigManipulator configManipulator) + public DatabaseInstallStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime) { _databaseBuilder = databaseBuilder; _runtime = runtime; - _logger = logger; - _ioHelper = ioHelper; - _connectionStrings = connectionStrings; - _configManipulator = configManipulator; } public override Task ExecuteAsync(object model) diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs index dccf320787..44214d1b73 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs @@ -1,8 +1,10 @@ using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; @@ -20,8 +22,8 @@ namespace Umbraco.Web.Install.InstallSteps private readonly IRuntimeState _runtime; private readonly ILogger _logger; private readonly IUmbracoVersion _umbracoVersion; - private readonly IGlobalSettings _globalSettings; - private readonly IConnectionStrings _connectionStrings; + private readonly GlobalSettings _globalSettings; + private readonly ConnectionStrings _connectionStrings; private readonly IIOHelper _ioHelper; private readonly IConfigManipulator _configManipulator; @@ -30,8 +32,8 @@ namespace Umbraco.Web.Install.InstallSteps IRuntimeState runtime, ILogger logger, IUmbracoVersion umbracoVersion, - IGlobalSettings globalSettings, - IConnectionStrings connectionStrings, + IOptionsSnapshot globalSettings, + IOptionsSnapshot connectionStrings, IIOHelper ioHelper, IConfigManipulator configManipulator) { @@ -39,8 +41,8 @@ namespace Umbraco.Web.Install.InstallSteps _runtime = runtime; _logger = logger; _umbracoVersion = umbracoVersion; - _globalSettings = globalSettings; - _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); + _globalSettings = globalSettings.Value; + _connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings)); _ioHelper = ioHelper; _configManipulator = configManipulator; } diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index f3765493d9..a8a516199f 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -30,29 +30,26 @@ namespace Umbraco.Web.Install.InstallSteps private readonly IUserService _userService; private readonly DatabaseBuilder _databaseBuilder; private static HttpClient _httpClient; - private readonly IGlobalSettings _globalSettings; private readonly UserPasswordConfigurationSettings _passwordConfiguration; private readonly SecuritySettings _securitySettings; - private readonly IConnectionStrings _connectionStrings; + private readonly ConnectionStrings _connectionStrings; private readonly ICookieManager _cookieManager; private readonly BackOfficeUserManager _userManager; public NewInstallStep( IUserService userService, DatabaseBuilder databaseBuilder, - IGlobalSettings globalSettings, IOptionsSnapshot passwordConfiguration, IOptionsSnapshot securitySettings, - IConnectionStrings connectionStrings, + IOptionsSnapshot connectionStrings, ICookieManager cookieManager, BackOfficeUserManager userManager) { _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); _passwordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _securitySettings = securitySettings.Value ?? throw new ArgumentNullException(nameof(securitySettings)); - _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); + _connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings)); _cookieManager = cookieManager; _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); } diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index 98d50d61b1..8bf8ceb33e 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -2,7 +2,9 @@ using System.IO; using System.Linq; using System.Xml.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -21,7 +23,7 @@ namespace Umbraco.Core.Migrations.Install { private readonly IUmbracoDatabaseFactory _databaseFactory; private readonly IScopeProvider _scopeProvider; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IRuntimeState _runtime; private readonly IMigrationBuilder _migrationBuilder; private readonly IKeyValueService _keyValueService; @@ -38,7 +40,7 @@ namespace Umbraco.Core.Migrations.Install /// public DatabaseBuilder( IScopeProvider scopeProvider, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtime, ILogger logger, @@ -50,7 +52,7 @@ namespace Umbraco.Core.Migrations.Install IConfigManipulator configManipulator) { _scopeProvider = scopeProvider; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _databaseFactory = databaseFactory; _runtime = runtime; _logger = logger; diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs index 36f1a30b20..6f0f32c37d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs @@ -1,6 +1,7 @@ using System; using NPoco; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Models; @@ -16,9 +17,9 @@ namespace Umbraco.Core.Migrations.Install private readonly IDatabase _database; private readonly ILogger _logger; private readonly IUmbracoVersion _umbracoVersion; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public DatabaseDataCreator(IDatabase database, ILogger logger, IUmbracoVersion umbracoVersion, IGlobalSettings globalSettings) + public DatabaseDataCreator(IDatabase database, ILogger logger, IUmbracoVersion umbracoVersion, GlobalSettings globalSettings) { _database = database; _logger = logger; diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs index 921ba0b3d5..97bd8bc2d6 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using NPoco; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -20,9 +21,9 @@ namespace Umbraco.Core.Migrations.Install private readonly IUmbracoDatabase _database; private readonly ILogger _logger; private readonly IUmbracoVersion _umbracoVersion; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public DatabaseSchemaCreator(IUmbracoDatabase database, ILogger logger, IUmbracoVersion umbracoVersion, IGlobalSettings globalSettings) + public DatabaseSchemaCreator(IUmbracoDatabase database, ILogger logger, IUmbracoVersion umbracoVersion, GlobalSettings globalSettings) { _database = database; _logger = logger; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index c671b0d236..3b555c89b1 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -2,6 +2,7 @@ using Semver; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Migrations.Upgrade.Common; using Umbraco.Core.Migrations.Upgrade.V_8_0_0; using Umbraco.Core.Migrations.Upgrade.V_8_0_1; @@ -16,13 +17,13 @@ namespace Umbraco.Core.Migrations.Upgrade public class UmbracoPlan : MigrationPlan { private readonly IUmbracoVersion _umbracoVersion; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private const string InitPrefix = "{init-"; private const string InitSuffix = "}"; /// /// Initializes a new instance of the class. /// - public UmbracoPlan(IUmbracoVersion umbracoVersion, IGlobalSettings globalSettings) + public UmbracoPlan(IUmbracoVersion umbracoVersion, GlobalSettings globalSettings) : base(Constants.System.UmbracoUpgradePlanName) { _umbracoVersion = umbracoVersion; diff --git a/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs index 9341b2f756..83da0c306c 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs @@ -13,6 +13,8 @@ using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Strings; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Models.Mapping { @@ -30,13 +32,12 @@ namespace Umbraco.Web.Models.Mapping private readonly IMemberTypeService _memberTypeService; private readonly ILogger _logger; private readonly IShortStringHelper _shortStringHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - public ContentTypeMapDefinition(CommonMapper commonMapper, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, - ILogger logger, IShortStringHelper shortStringHelper, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + ILogger logger, IShortStringHelper shortStringHelper, IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) { _commonMapper = commonMapper; _propertyEditors = propertyEditors; @@ -47,7 +48,7 @@ namespace Umbraco.Web.Models.Mapping _memberTypeService = memberTypeService; _logger = logger; _shortStringHelper = shortStringHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; } diff --git a/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs index 043b37a654..ca17bffd5d 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs @@ -18,6 +18,8 @@ using Umbraco.Web.Actions; using Umbraco.Web.Services; using Umbraco.Core.Media; using Umbraco.Core.Persistence.Dtos; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Models.Mapping { @@ -29,13 +31,13 @@ namespace Umbraco.Web.Models.Mapping private readonly ILocalizedTextService _textService; private readonly ActionCollection _actions; private readonly AppCaches _appCaches; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IMediaFileSystem _mediaFileSystem; private readonly IShortStringHelper _shortStringHelper; private readonly IImageUrlGenerator _imageUrlGenerator; public UserMapDefinition(ILocalizedTextService textService, IUserService userService, IEntityService entityService, ISectionService sectionService, - AppCaches appCaches, ActionCollection actions, IGlobalSettings globalSettings, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, + AppCaches appCaches, ActionCollection actions, IOptionsSnapshot globalSettings, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IImageUrlGenerator imageUrlGenerator) { _sectionService = sectionService; @@ -44,7 +46,7 @@ namespace Umbraco.Web.Models.Mapping _textService = textService; _actions = actions; _appCaches = appCaches; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _mediaFileSystem = mediaFileSystem; _shortStringHelper = shortStringHelper; _imageUrlGenerator = imageUrlGenerator; diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index 6b1aa96e69..a868170c5f 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using System.Xml.XPath; using Umbraco.Core.Collections; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -29,7 +30,7 @@ namespace Umbraco.Core.Packaging private readonly PropertyEditorCollection _propertyEditors; private readonly IScopeProvider _scopeProvider; private readonly IShortStringHelper _shortStringHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly ILocalizedTextService _localizedTextService; private readonly IEntityService _entityService; private readonly IContentTypeService _contentTypeService; @@ -37,7 +38,7 @@ namespace Umbraco.Core.Packaging public PackageDataInstallation(ILogger logger, IFileService fileService, IMacroService macroService, ILocalizationService localizationService, IDataTypeService dataTypeService, IEntityService entityService, IContentTypeService contentTypeService, - IContentService contentService, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, IShortStringHelper shortStringHelper, IGlobalSettings globalSettings, + IContentService contentService, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, IShortStringHelper shortStringHelper, GlobalSettings globalSettings, ILocalizedTextService localizedTextService) { _logger = logger; diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/LanguageFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/LanguageFactory.cs index 1da4a8dfac..0b5937a328 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/LanguageFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/LanguageFactory.cs @@ -1,5 +1,6 @@ using System.Globalization; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Dtos; @@ -7,7 +8,7 @@ namespace Umbraco.Core.Persistence.Factories { internal static class LanguageFactory { - public static ILanguage BuildEntity(IGlobalSettings globalSettings, LanguageDto dto) + public static ILanguage BuildEntity(GlobalSettings globalSettings, LanguageDto dto) { var lang = new Language(globalSettings, dto.IsoCode) { diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs index b56e822e92..839f7b5ad7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence.Dtos; @@ -8,7 +9,7 @@ namespace Umbraco.Core.Persistence.Factories { internal static class UserFactory { - public static IUser BuildEntity(IGlobalSettings globalSettings, UserDto dto) + public static IUser BuildEntity(GlobalSettings globalSettings, UserDto dto) { var guidId = dto.Id.ToGuid(); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs index 245ff10f7f..80afef181e 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using NPoco; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -19,14 +21,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// internal class LanguageRepository : NPocoRepositoryBase, ILanguageRepository { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly Dictionary _codeIdMap = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly Dictionary _idCodeMap = new Dictionary(); - public LanguageRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger, IGlobalSettings globalSettings) + public LanguageRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger, IOptionsSnapshot globalSettings) : base(scopeAccessor, cache, logger) { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } protected override IRepositoryCachePolicy CreateCachePolicy() diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs index 498cf51432..b137f36bc4 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -14,13 +16,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement internal class ScriptRepository : FileRepository, IScriptRepository { private readonly IIOHelper _ioHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public ScriptRepository(IFileSystems fileSystems, IIOHelper ioHelper, IGlobalSettings globalSettings) + public ScriptRepository(IFileSystems fileSystems, IIOHelper ioHelper, IOptionsSnapshot globalSettings) : base(fileSystems.ScriptsFileSystem) { _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } #region Implementation of IRepository diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs index f432d6959e..4ee18c635c 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -13,13 +15,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement internal class StylesheetRepository : FileRepository, IStylesheetRepository { private readonly IIOHelper _ioHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public StylesheetRepository(IFileSystems fileSystems, IIOHelper ioHelper, IGlobalSettings globalSettings) + public StylesheetRepository(IFileSystems fileSystems, IIOHelper ioHelper, IOptionsSnapshot globalSettings) : base(fileSystems.StylesheetsFileSystem) { _ioHelper = ioHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } #region Overrides of FileRepository diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs index bd11127296..e054c4423a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs @@ -26,7 +26,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement internal class UserRepository : NPocoRepositoryBase, IUserRepository { private readonly IMapperCollection _mapperCollection; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly UserPasswordConfigurationSettings _passwordConfiguration; private readonly IJsonSerializer _jsonSerializer; private string _passwordConfigJson; @@ -47,10 +47,10 @@ namespace Umbraco.Core.Persistence.Repositories.Implement AppCaches appCaches, ILogger logger, IMapperCollection mapperCollection, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IOptionsSnapshot passwordConfiguration, IJsonSerializer jsonSerializer) - : this(scopeAccessor, appCaches, logger, mapperCollection, globalSettings, passwordConfiguration.Value, jsonSerializer) + : this(scopeAccessor, appCaches, logger, mapperCollection, globalSettings.Value, passwordConfiguration.Value, jsonSerializer) { } @@ -69,7 +69,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement AppCaches appCaches, ILogger logger, IMapperCollection mapperCollection, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, UserPasswordConfigurationSettings passwordConfiguration, IJsonSerializer jsonSerializer) : base(scopeAccessor, appCaches, logger) diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index 837fe6cba3..1b46a6a3cd 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -6,6 +6,7 @@ using NPoco; using NPoco.FluentMappings; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.FaultHandling; using Umbraco.Core.Persistence.Mappers; @@ -28,7 +29,7 @@ namespace Umbraco.Core.Persistence internal class UmbracoDatabaseFactory : DisposableObjectSlim, IUmbracoDatabaseFactory { private readonly IDbProviderFactoryCreator _dbProviderFactoryCreator; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly Lazy _mappers; private readonly ILogger _logger; @@ -70,7 +71,7 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used by core runtime. - public UmbracoDatabaseFactory(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, GlobalSettings globalSettings, ConnectionStrings connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) : this(logger, globalSettings, connectionStrings, Constants.System.UmbracoConnectionName, mappers, dbProviderFactoryCreator) { @@ -80,7 +81,7 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used by the other ctor and in tests. - public UmbracoDatabaseFactory(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, string connectionStringName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, GlobalSettings globalSettings, ConnectionStrings connectionStrings, string connectionStringName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) { if (connectionStringName == null) throw new ArgumentNullException(nameof(connectionStringName)); if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(connectionStringName)); diff --git a/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs b/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs index f9256b3692..63a6725fb8 100644 --- a/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs +++ b/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.Models; @@ -24,15 +26,14 @@ namespace Umbraco.Web.Routing { private const string _eventStateKey = "Umbraco.Web.Redirects.RedirectTrackingEventHandler"; - - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; private readonly IRedirectUrlService _redirectUrlService; private readonly IVariationContextAccessor _variationContextAccessor; - public RedirectTrackingComponent(IWebRoutingSettings webRoutingSettings, IPublishedSnapshotAccessor publishedSnapshotAccessor, IRedirectUrlService redirectUrlService, IVariationContextAccessor variationContextAccessor) + public RedirectTrackingComponent(IOptionsSnapshot webRoutingSettings, IPublishedSnapshotAccessor publishedSnapshotAccessor, IRedirectUrlService redirectUrlService, IVariationContextAccessor variationContextAccessor) { - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; _publishedSnapshotAccessor = publishedSnapshotAccessor; _redirectUrlService = redirectUrlService; _variationContextAccessor = variationContextAccessor; diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs index 1432e6b7f2..3a4cd60901 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs @@ -1,5 +1,7 @@ -using Umbraco.Core.Composing; +using Microsoft.Extensions.Options; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.Core.Runtime @@ -7,12 +9,12 @@ namespace Umbraco.Core.Runtime public class CoreInitialComponent : IComponent { private readonly IIOHelper _ioHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public CoreInitialComponent(IIOHelper ioHelper, IGlobalSettings globalSettings) + public CoreInitialComponent(IIOHelper ioHelper, IOptionsSnapshot globalSettings) { _ioHelper = ioHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void Initialize() diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index 2f9766e5c2..ad036e12eb 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -5,6 +5,7 @@ using System.IO; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -26,11 +27,12 @@ namespace Umbraco.Core.Runtime private readonly RuntimeState _state; private readonly IUmbracoBootPermissionChecker _umbracoBootPermissionChecker; private readonly IRequestCache _requestCache; - private readonly IGlobalSettings _globalSettings; - private readonly IConnectionStrings _connectionStrings; + private readonly GlobalSettings _globalSettings; + private readonly ConnectionStrings _connectionStrings; public CoreRuntime( - Configs configs, + GlobalSettings globalSettings, + ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, @@ -43,9 +45,11 @@ namespace Umbraco.Core.Runtime ITypeFinder typeFinder, IRequestCache requestCache) { + _globalSettings = globalSettings; + _connectionStrings = connectionStrings; + IOHelper = ioHelper; - Configs = configs; - UmbracoVersion = umbracoVersion ; + UmbracoVersion = umbracoVersion; Profiler = profiler; HostingEnvironment = hostingEnvironment; BackOfficeInfo = backOfficeInfo; @@ -58,14 +62,10 @@ namespace Umbraco.Core.Runtime MainDom = mainDom; TypeFinder = typeFinder; - _globalSettings = Configs.Global(); - _connectionStrings = configs.ConnectionStrings(); - - // runtime state // beware! must use '() => _factory.GetInstance()' and NOT '_factory.GetInstance' // as the second one captures the current value (null) and therefore fails - _state = new RuntimeState(Configs.Global(), UmbracoVersion) + _state = new RuntimeState(_globalSettings, UmbracoVersion) { Level = RuntimeLevel.Boot }; @@ -99,8 +99,8 @@ namespace Umbraco.Core.Runtime /// Gets the /// protected IIOHelper IOHelper { get; } + protected IHostingEnvironment HostingEnvironment { get; } - protected Configs Configs { get; } protected IUmbracoVersion UmbracoVersion { get; } /// @@ -179,7 +179,7 @@ namespace Umbraco.Core.Runtime var typeLoader = new TypeLoader(TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(HostingEnvironment.LocalTempPath), ProfilingLogger); // create the composition - composition = new Composition(register, typeLoader, ProfilingLogger, _state, Configs, IOHelper, appCaches); + composition = new Composition(register, typeLoader, ProfilingLogger, _state, IOHelper, appCaches); composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, MainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, UmbracoVersion, DbProviderFactoryCreator, HostingEnvironment, BackOfficeInfo); // register ourselves (TODO: Should we put this in RegisterEssentials?) diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index d3bb7eefac..723be61283 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -7,6 +7,7 @@ using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -31,7 +32,7 @@ namespace Umbraco.Core.Runtime private bool _errorDuringAcquiring; private object _locker = new object(); - public SqlMainDomLock(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, IDbProviderFactoryCreator dbProviderFactoryCreator, IHostingEnvironment hostingEnvironment) + public SqlMainDomLock(ILogger logger, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IDbProviderFactoryCreator dbProviderFactoryCreator, IHostingEnvironment hostingEnvironment) { // unique id for our appdomain, this is more unique than the appdomain id which is just an INT counter to its safer _lockId = Guid.NewGuid().ToString(); diff --git a/src/Umbraco.Infrastructure/RuntimeState.cs b/src/Umbraco.Infrastructure/RuntimeState.cs index 4a33291314..832cdc7605 100644 --- a/src/Umbraco.Infrastructure/RuntimeState.cs +++ b/src/Umbraco.Infrastructure/RuntimeState.cs @@ -3,6 +3,7 @@ using System.Threading; using Semver; using Umbraco.Core.Collections; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; @@ -16,13 +17,13 @@ namespace Umbraco.Core /// public class RuntimeState : IRuntimeState { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; /// /// Initializes a new instance of the class. /// - public RuntimeState(IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion) + public RuntimeState(GlobalSettings globalSettings, IUmbracoVersion umbracoVersion) { _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index 188fad4c7b..7d6c0303ce 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; +using Microsoft.Extensions.Options; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -29,7 +31,7 @@ namespace Umbraco.Core.Services.Implement private readonly IPartialViewMacroRepository _partialViewMacroRepository; private readonly IAuditRepository _auditRepository; private readonly IShortStringHelper _shortStringHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private const string PartialViewHeader = "@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage"; @@ -38,7 +40,7 @@ namespace Umbraco.Core.Services.Implement public FileService(IScopeProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, ITemplateRepository templateRepository, IPartialViewRepository partialViewRepository, IPartialViewMacroRepository partialViewMacroRepository, - IAuditRepository auditRepository, IShortStringHelper shortStringHelper, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + IAuditRepository auditRepository, IShortStringHelper shortStringHelper, IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) : base(uowProvider, logger, eventMessagesFactory) { _stylesheetRepository = stylesheetRepository; @@ -48,7 +50,7 @@ namespace Umbraco.Core.Services.Implement _partialViewMacroRepository = partialViewMacroRepository; _auditRepository = auditRepository; _shortStringHelper = shortStringHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; } diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 112ab51bf8..3ad1ea8446 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -26,19 +26,19 @@ namespace Umbraco.Core.Services.Implement private readonly IContentService _contentService; private readonly ILocalizationService _localizationService; private readonly INotificationsRepository _notificationsRepository; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly ContentSettings _contentSettings; private readonly ILogger _logger; private readonly IIOHelper _ioHelper; public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, - ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IOptionsSnapshot contentSettings) - : this(provider, userService, contentService, localizationService, logger, ioHelper, notificationsRepository, globalSettings, contentSettings.Value) + ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IOptionsSnapshot globalSettings, IOptionsSnapshot contentSettings) + : this(provider, userService, contentService, localizationService, logger, ioHelper, notificationsRepository, globalSettings.Value, contentSettings.Value) { } public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, - ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, ContentSettings contentSettings) + ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, GlobalSettings globalSettings, ContentSettings contentSettings) { _notificationsRepository = notificationsRepository; _globalSettings = globalSettings; diff --git a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs index faf7889fbf..921da6f345 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs @@ -4,7 +4,9 @@ using System.Data.Common; using System.Globalization; using System.Linq; using System.Linq.Expressions; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.Logging; using Umbraco.Core.Models.Membership; @@ -22,16 +24,16 @@ namespace Umbraco.Core.Services.Implement { private readonly IUserRepository _userRepository; private readonly IUserGroupRepository _userGroupRepository; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly bool _isUpgrading; public UserService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IRuntimeState runtimeState, - IUserRepository userRepository, IUserGroupRepository userGroupRepository, IGlobalSettings globalSettings) + IUserRepository userRepository, IUserGroupRepository userGroupRepository, IOptionsSnapshot globalSettings) : base(provider, logger, eventMessagesFactory) { _userRepository = userRepository; _userGroupRepository = userGroupRepository; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _isUpgrading = runtimeState.Level == RuntimeLevel.Install || runtimeState.Level == RuntimeLevel.Upgrade; } diff --git a/src/Umbraco.Infrastructure/Users/EmailSender.cs b/src/Umbraco.Infrastructure/Users/EmailSender.cs index 9a2f425021..1ca30bb966 100644 --- a/src/Umbraco.Infrastructure/Users/EmailSender.cs +++ b/src/Umbraco.Infrastructure/Users/EmailSender.cs @@ -2,9 +2,11 @@ using System.Linq; using System.Net.Mail; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using MimeKit; using MimeKit.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using SmtpClient = MailKit.Net.Smtp.SmtpClient; @@ -17,14 +19,23 @@ namespace Umbraco.Core { // TODO: This should encapsulate a BackgroundTaskRunner with a queue to send these emails! - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly bool _enableEvents; - public EmailSender(IGlobalSettings globalSettings) : this(globalSettings, false) + public EmailSender(IOptionsSnapshot globalSettings) : this(globalSettings, false) { } - public EmailSender(IGlobalSettings globalSettings, bool enableEvents) + public EmailSender(IOptionsSnapshot globalSettings, bool enableEvents) + : this(globalSettings.Value, enableEvents) + { + } + + public EmailSender(GlobalSettings globalSettings) : this(globalSettings, false) + { + } + + public EmailSender(GlobalSettings globalSettings, bool enableEvents) { _globalSettings = globalSettings; _enableEvents = enableEvents; @@ -107,7 +118,7 @@ namespace Umbraco.Core /// /// We assume this is possible if either an event handler is registered or an smtp server is configured /// - public static bool CanSendRequiredEmail(IGlobalSettings globalSettings) => EventHandlerRegistered || globalSettings.IsSmtpServerConfigured; + public static bool CanSendRequiredEmail(GlobalSettings globalSettings) => EventHandlerRegistered || globalSettings.IsSmtpServerConfigured; /// /// returns true if an event handler has been registered diff --git a/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs b/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs index 18279e35ba..77db7bcbfd 100644 --- a/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs +++ b/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs @@ -2,6 +2,7 @@ using System.Text; using System.Text.RegularExpressions; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -31,7 +32,7 @@ namespace Umbraco.Web.WebAssets /// /// /// - public static string GetJavascriptInitialization(IEnumerable scripts, string angularModule, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static string GetJavascriptInitialization(IEnumerable scripts, string angularModule, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var jarray = new StringBuilder(); jarray.AppendLine("["); diff --git a/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs b/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs index fcb27f7189..b3d7d485f5 100644 --- a/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs +++ b/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Manifest; @@ -25,7 +27,7 @@ namespace Umbraco.Web.WebAssets private readonly IRuntimeMinifier _runtimeMinifier; private readonly IManifestParser _parser; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly PropertyEditorCollection _propertyEditorCollection; @@ -34,13 +36,13 @@ namespace Umbraco.Web.WebAssets IManifestParser parser, PropertyEditorCollection propertyEditorCollection, IHostingEnvironment hostingEnvironment, - IGlobalSettings globalSettings) + IOptionsSnapshot globalSettings) { _runtimeMinifier = runtimeMinifier; _parser = parser; _propertyEditorCollection = propertyEditorCollection; _hostingEnvironment = hostingEnvironment; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void CreateBundles() diff --git a/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs b/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs index 072afa5816..929c7c9dd2 100644 --- a/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs +++ b/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.WebAssets; @@ -15,7 +16,7 @@ namespace Umbraco.Web.WebAssets /// Returns the JavaScript to load the back office's assets /// /// - public static async Task GetScriptForLoadingBackOfficeAsync(this IRuntimeMinifier minifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static async Task GetScriptForLoadingBackOfficeAsync(this IRuntimeMinifier minifier, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var files = await minifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoJsBundleName); var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco", globalSettings, hostingEnvironment); diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs index 75affe09e7..1da5e44a77 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +11,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class ContentTypeModelValidator : ContentTypeModelValidatorBase { - public ContentTypeModelValidator(IModelsBuilderConfig config) : base(config) + public ContentTypeModelValidator(IOptionsSnapshot config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs index 1e96e64df8..dc78b31abd 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Editors; using Umbraco.Web.Models.ContentEditing; @@ -13,11 +14,11 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice where TModel : ContentTypeSave where TProperty : PropertyTypeBasic { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; - public ContentTypeModelValidatorBase(IModelsBuilderConfig config) + public ContentTypeModelValidatorBase(IOptionsSnapshot config) { - _config = config; + _config = config.Value; } protected override IEnumerable Validate(TModel model) diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs index 6e22313474..9dc4d8bfb4 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs @@ -1,16 +1,17 @@ using System.Text; using Umbraco.Configuration; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.BackOffice { internal class DashboardReport { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly ModelsGenerationError _mbErrors; - public DashboardReport(IModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) + public DashboardReport(ModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { _config = config; _outOfDateModels = outOfDateModels; diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs index fcd42908e7..fc03c24704 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +11,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class MediaTypeModelValidator : ContentTypeModelValidatorBase { - public MediaTypeModelValidator(IModelsBuilderConfig config) : base(config) + public MediaTypeModelValidator(IOptionsSnapshot config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs index 17b694de56..92f42121e2 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs @@ -3,8 +3,10 @@ using System.Net; using System.Net.Http; using System.Runtime.Serialization; using System.Web.Hosting; +using Microsoft.Extensions.Options; using Umbraco.Configuration; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Exceptions; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Web.Editors; @@ -23,20 +25,20 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice [UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)] public class ModelsBuilderDashboardController : UmbracoAuthorizedJsonController { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly ModelsGenerator _modelGenerator; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly ModelsGenerationError _mbErrors; private readonly DashboardReport _dashboardReport; - public ModelsBuilderDashboardController(IModelsBuilderConfig config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) + public ModelsBuilderDashboardController(IOptionsSnapshot config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { //_umbracoServices = umbracoServices; - _config = config; + _config = config.Value; _modelGenerator = modelsGenerator; _outOfDateModels = outOfDateModels; _mbErrors = mbErrors; - _dashboardReport = new DashboardReport(config, outOfDateModels, mbErrors); + _dashboardReport = new DashboardReport(_config, outOfDateModels, mbErrors); } // invoked by the dashboard diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs index f64e5ed1ce..c053f94649 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -70,7 +71,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building /// /// The list of models to generate. /// The models namespace. - protected Builder(IModelsBuilderConfig config, IList typeModels) + protected Builder(ModelsBuilderConfig config, IList typeModels) { _typeModels = typeModels ?? throw new ArgumentNullException(nameof(typeModels)); diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs index 648a2e76fa..29da569102 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs @@ -1,6 +1,7 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded.Building @@ -8,11 +9,11 @@ namespace Umbraco.ModelsBuilder.Embedded.Building public class ModelsGenerator { private readonly UmbracoServices _umbracoService; - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly IIOHelper _ioHelper; - public ModelsGenerator(UmbracoServices umbracoService, IModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) + public ModelsGenerator(UmbracoServices umbracoService, ModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) { _umbracoService = umbracoService; _config = config; diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs index 723ee10f35..6caca6c8ab 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -17,7 +17,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building /// and the result of code parsing. /// /// The list of models to generate. - public TextBuilder(IModelsBuilderConfig config, IList typeModels) + public TextBuilder(ModelsBuilderConfig config, IList typeModels) : base(config, typeModels) { } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs index 32cfd3057e..a794f45616 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs @@ -15,19 +15,21 @@ using Umbraco.ModelsBuilder.Embedded.BackOffice; using Umbraco.Web; using Umbraco.Web.Mvc; using Umbraco.Web.WebAssets; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded.Compose { internal class ModelsBuilderComponent : IComponent { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IShortStringHelper _shortStringHelper; private readonly LiveModelsProvider _liveModelsProvider; private readonly OutOfDateModelsStatus _outOfDateModels; - public ModelsBuilderComponent(IModelsBuilderConfig config, IShortStringHelper shortStringHelper, LiveModelsProvider liveModelsProvider, OutOfDateModelsStatus outOfDateModels) + public ModelsBuilderComponent(IOptionsSnapshot config, IShortStringHelper shortStringHelper, LiveModelsProvider liveModelsProvider, OutOfDateModelsStatus outOfDateModels) { - _config = config; + _config = config.Value; _shortStringHelper = shortStringHelper; _liveModelsProvider = liveModelsProvider; _outOfDateModels = outOfDateModels; diff --git a/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs b/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs index 61d39cd373..e1ba236839 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Web.Cache; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded { @@ -15,7 +16,7 @@ namespace Umbraco.ModelsBuilder.Embedded private static Mutex _mutex; private static int _req; private readonly ILogger _logger; - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly ModelsGenerator _modelGenerator; private readonly ModelsGenerationError _mbErrors; private readonly IHostingEnvironment _hostingEnvironment; @@ -23,7 +24,7 @@ namespace Umbraco.ModelsBuilder.Embedded // we do not manage pure live here internal bool IsEnabled => _config.ModelsMode.IsLiveNotPure(); - public LiveModelsProvider(ILogger logger, IModelsBuilderConfig config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IHostingEnvironment hostingEnvironment) + public LiveModelsProvider(ILogger logger, ModelsBuilderConfig config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IHostingEnvironment hostingEnvironment) { _logger = logger; _config = config ?? throw new ArgumentNullException(nameof(config)); diff --git a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs index f8f6e8c7bc..0181701f1f 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs @@ -2,16 +2,17 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded { public sealed class ModelsGenerationError { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public ModelsGenerationError(IModelsBuilderConfig config, IIOHelper ioHelper) + public ModelsGenerationError(ModelsBuilderConfig config, IIOHelper ioHelper) { _config = config; _ioHelper = ioHelper; diff --git a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs index b8105eeef2..4fb23ad5b3 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs @@ -1,5 +1,6 @@ using System.IO; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Cache; @@ -7,10 +8,10 @@ namespace Umbraco.ModelsBuilder.Embedded { public sealed class OutOfDateModelsStatus { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public OutOfDateModelsStatus(IModelsBuilderConfig config, IIOHelper ioHelper) + public OutOfDateModelsStatus(ModelsBuilderConfig config, IIOHelper ioHelper) { _config = config; _ioHelper = ioHelper; diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index 7809d2bf48..6e5ba18888 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -19,6 +19,8 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; using File = System.IO.File; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded { @@ -41,7 +43,7 @@ namespace Umbraco.ModelsBuilder.Embedded private const string ProjVirt = "~/App_Data/Models/all.generated.cs"; private static readonly string[] OurFiles = { "models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err" }; - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IApplicationShutdownRegistry _hostingLifetime; private readonly IIOHelper _ioHelper; private readonly ModelsGenerationError _errors; @@ -49,7 +51,7 @@ namespace Umbraco.ModelsBuilder.Embedded public PureLiveModelFactory( Lazy umbracoServices, IProfilingLogger logger, - IModelsBuilderConfig config, + IOptionsSnapshot config, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IIOHelper ioHelper) diff --git a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs index 337c61b30f..470a224dc8 100644 --- a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs +++ b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Xml.XPath; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Xml; using Umbraco.Core.Xml.XPath; @@ -19,7 +21,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private readonly IAppCache _snapshotCache; private readonly IAppCache _elementsCache; private readonly IDomainCache _domainCache; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IVariationContextAccessor _variationContextAccessor; #region Constructor @@ -29,7 +31,12 @@ namespace Umbraco.Web.PublishedCache.NuCache // it's too late for UmbracoContext which has captured previewDefault and stuff into these ctor vars // but, no, UmbracoContext returns snapshot.Content which comes from elements SO a resync should create a new cache - public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor) + public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IOptionsSnapshot globalSettings, IVariationContextAccessor variationContextAccessor) + : this(previewDefault, snapshot, snapshotCache, elementsCache, domainCache, globalSettings.Value, variationContextAccessor) + { + } + + public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, GlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor) : base(previewDefault) { _snapshot = snapshot; diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/BTree.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/BTree.cs index 00e7fd34d1..ae7393a91a 100644 --- a/src/Umbraco.PublishedCache.NuCache/DataSource/BTree.cs +++ b/src/Umbraco.PublishedCache.NuCache/DataSource/BTree.cs @@ -2,12 +2,13 @@ using CSharpTest.Net.Collections; using CSharpTest.Net.Serialization; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.PublishedCache.NuCache.DataSource { internal class BTree { - public static BPlusTree GetTree(string filepath, bool exists, INuCacheSettings settings) + public static BPlusTree GetTree(string filepath, bool exists, NuCacheSettings settings) { var keySerializer = new PrimitiveSerializer(); var valueSerializer = new ContentNodeKitSerializer(); @@ -22,7 +23,6 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource // default is 4096, min 2^9 = 512, max 2^16 = 64K FileBlockSize = GetBlockSize(settings), - //HACK: Forces FileOptions to be WriteThrough here: https://github.com/mamift/CSharpTest.Net.Collections/blob/9f93733b3af7ee0e2de353e822ff54d908209b0b/src/CSharpTest.Net.Collections/IO/TransactedCompoundFile.cs#L316-L327, // as the reflection uses otherwise will failed in .NET Core as the "_handle" field in FileStream is renamed to "_fileHandle". StoragePerformance = StoragePerformance.CommitToDisk, @@ -40,7 +40,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource return tree; } - private static int GetBlockSize(INuCacheSettings settings) + private static int GetBlockSize(NuCacheSettings settings) { var blockSize = 4096; diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index 815fe0a168..f603ee25ad 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -6,11 +6,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CSharpTest.Net.Collections; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Install; using Umbraco.Core.IO; @@ -45,7 +47,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private readonly IDocumentRepository _documentRepository; private readonly IMediaRepository _mediaRepository; private readonly IMemberRepository _memberRepository; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IEntityXmlSerializer _entitySerializer; private readonly IPublishedModelFactory _publishedModelFactory; private readonly IDefaultCultureAccessor _defaultCultureAccessor; @@ -53,7 +55,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; private readonly IIOHelper _ioHelper; - private readonly INuCacheSettings _config; + private readonly NuCacheSettings _config; // volatile because we read it with no lock private volatile bool _isReady; @@ -84,14 +86,15 @@ namespace Umbraco.Web.PublishedCache.NuCache IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IProfilingLogger logger, IScopeProvider scopeProvider, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, - IDataSource dataSource, IGlobalSettings globalSettings, + IDataSource dataSource, + IOptionsSnapshot globalSettings, IEntityXmlSerializer entitySerializer, IPublishedModelFactory publishedModelFactory, UrlSegmentProviderCollection urlSegmentProviders, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, IIOHelper ioHelper, - INuCacheSettings config) + IOptionsSnapshot config) : base(publishedSnapshotAccessor, variationContextAccessor) { //if (Interlocked.Increment(ref _singletonCheck) > 1) @@ -106,12 +109,12 @@ namespace Umbraco.Web.PublishedCache.NuCache _mediaRepository = mediaRepository; _memberRepository = memberRepository; _defaultCultureAccessor = defaultCultureAccessor; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _urlSegmentProviders = urlSegmentProviders; _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; _ioHelper = ioHelper; - _config = config; + _config = config.Value; // we need an Xml serializer here so that the member cache can support XPath, // for members this is done by navigating the serialized-to-xml member diff --git a/src/Umbraco.Tests.Common/SettingsForTests.cs b/src/Umbraco.Tests.Common/SettingsForTests.cs index 1a14dc6bc1..e60f6ad0a4 100644 --- a/src/Umbraco.Tests.Common/SettingsForTests.cs +++ b/src/Umbraco.Tests.Common/SettingsForTests.cs @@ -3,7 +3,7 @@ using Moq; using Semver; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; @@ -16,25 +16,23 @@ namespace Umbraco.Tests.Common { } - public IGlobalSettings GenerateMockGlobalSettings(IUmbracoVersion umbVersion = null) + public GlobalSettings GenerateStubGlobalSettings(IUmbracoVersion umbVersion = null) { var semanticVersion = umbVersion?.SemanticVersion ?? new SemVersion(9); - var config = Mock.Of( - settings => - settings.UseHttps == false && - settings.HideTopLevelNodeFromPath == false && - settings.TimeOutInMinutes == 20 && - settings.DefaultUILanguage == "en" && - settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") && - settings.ReservedUrls == GlobalSettings.StaticReservedUrls && - settings.UmbracoPath == "~/umbraco" && - settings.UmbracoMediaPath == "~/media" && - settings.UmbracoCssPath == "~/css" && - settings.UmbracoScriptsPath == "~/scripts" - ); - - + var config = new GlobalSettings + { + UseHttps = false, + HideTopLevelNodeFromPath = false, + TimeOutInMinutes = 20, + DefaultUILanguage = "en", + ReservedPaths = (GlobalSettings.StaticReservedPaths + "~/umbraco"), + ReservedUrls = GlobalSettings.StaticReservedUrls, + UmbracoPath = "~/umbraco", + UmbracoMediaPath = "~/media", + UmbracoCssPath = "~/css", + UmbracoScriptsPath = "~/scripts", + }; return config; } @@ -104,15 +102,15 @@ namespace Umbraco.Tests.Common _defaultHostingSettings = null; } - private readonly Dictionary _defaultGlobalSettings = new Dictionary(); + private readonly Dictionary _defaultGlobalSettings = new Dictionary(); private IHostingSettings _defaultHostingSettings; - public IGlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion) + public GlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion) { if (_defaultGlobalSettings.TryGetValue(umbVersion.SemanticVersion, out var settings)) return settings; - settings = GenerateMockGlobalSettings(umbVersion); + settings = GenerateStubGlobalSettings(umbVersion); _defaultGlobalSettings[umbVersion.SemanticVersion] = settings; return settings; } diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 3a6d099e46..461cbf4097 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -90,7 +90,7 @@ namespace Umbraco.Tests.Common get { if (_ioHelper == null) - _ioHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateMockGlobalSettings()); + _ioHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateStubGlobalSettings()); return _ioHelper; } } diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs index 076cecef4a..73076522c8 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Hosting; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; @@ -9,7 +9,7 @@ namespace Umbraco.Tests.Integration.Implementations public class TestHostingEnvironment : AspNetCoreHostingEnvironment, IHostingEnvironment { - public TestHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) + public TestHostingEnvironment(IOptionsSnapshot hostingSettings, IWebHostEnvironment webHostEnvironment) : base(hostingSettings, webHostEnvironment) { } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs index 3464259052..a25a21f27c 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs @@ -25,7 +25,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( @@ -50,7 +50,7 @@ namespace Umbraco.Tests.Security //hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); var mgr = new BackOfficeCookieManager( @@ -72,7 +72,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -97,7 +97,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -119,7 +119,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs index 4c8903735a..71ef0e1bdb 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs @@ -18,7 +18,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions { _settingsForTests = new SettingsForTests(); _hostEnvironment = Mock.Of(); - _globalSettings = _settingsForTests.GenerateMockGlobalSettings(); + _globalSettings = _settingsForTests.GenerateStubGlobalSettings(); } private SettingsForTests _settingsForTests; diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index b58301287b..6abe44d0fd 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Tests.TestHelpers @@ -7,7 +8,7 @@ namespace Umbraco.Tests.TestHelpers { private static Common.SettingsForTests _settingsForTests = new Common.SettingsForTests(); - public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateMockGlobalSettings(TestHelper.GetUmbracoVersion()); + public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateStubGlobalSettings(TestHelper.GetUmbracoVersion()); /// /// Returns generated settings which can be stubbed to return whatever values necessary @@ -45,7 +46,7 @@ namespace Umbraco.Tests.TestHelpers public static void Reset() => _settingsForTests.Reset(); - internal static IGlobalSettings DefaultGlobalSettings => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion()); + internal static GlobalSettings DefaultGlobalSettings => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion()); internal static IHostingSettings DefaultHostingSettings => _settingsForTests.DefaultHostingSettings; diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index e9f05f43fc..08b21dda8d 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -58,7 +58,7 @@ namespace Umbraco.Tests.TestHelpers public override IBackOfficeInfo GetBackOfficeInfo() => new AspNetBackOfficeInfo( - SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion()), + SettingsForTests.GenerateStubGlobalSettings(GetUmbracoVersion()), TestHelper.IOHelper, Mock.Of(), SettingsForTests.GenerateMockWebRoutingSettings()); public override IHostingEnvironment GetHostingEnvironment() diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 1b63bcc98d..24aa171c87 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -8,6 +8,7 @@ using Moq; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -136,10 +137,11 @@ namespace Umbraco.Tests.TestHelpers return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext; } - public IGlobalSettings GetGlobalSettings() + public GlobalSettings GetGlobalSettings() { return SettingsForTests.DefaultGlobalSettings; } + public IFileSystems GetFileSystemsMock() { var fileSystems = Mock.Of(); diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs index a82dda52c7..dc22d24f05 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs @@ -45,7 +45,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IUserService _userService; private readonly ILocalizedTextService _textService; private readonly UmbracoMapper _umbracoMapper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly SecuritySettings _securitySettings; private readonly ILogger _logger; private readonly IIpResolver _ipResolver; @@ -64,7 +64,7 @@ namespace Umbraco.Web.BackOffice.Controllers IUserService userService, ILocalizedTextService textService, UmbracoMapper umbracoMapper, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IOptionsSnapshot securitySettings, ILogger logger, IIpResolver ipResolver, @@ -79,7 +79,7 @@ namespace Umbraco.Web.BackOffice.Controllers _userService = userService; _textService = textService; _umbracoMapper = umbracoMapper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _securitySettings = securitySettings.Value; _logger = logger; _ipResolver = ipResolver; diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs index 7cbeb8e86e..916b422b33 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -17,9 +19,9 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly IFileSystem _jsLibFileSystem; - public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IGlobalSettings globalSettings) + public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IOptionsSnapshot globalSettings) { - _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.UmbracoPath + Path.DirectorySeparatorChar + "lib"); + _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib"); } [HttpGet] diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 1970205ebc..4672d48d88 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -5,13 +5,14 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Services; @@ -35,7 +36,7 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly BackOfficeUserManager _userManager; private readonly IRuntimeMinifier _runtimeMinifier; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly ILocalizedTextService _textService; @@ -49,7 +50,7 @@ namespace Umbraco.Web.BackOffice.Controllers public BackOfficeController( BackOfficeUserManager userManager, IRuntimeMinifier runtimeMinifier, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService textService, @@ -59,11 +60,10 @@ namespace Umbraco.Web.BackOffice.Controllers BackOfficeSignInManager signInManager, IWebSecurity webSecurity, ILogger logger) - { _userManager = userManager; _runtimeMinifier = runtimeMinifier; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _umbracoContextAccessor = umbracoContextAccessor; _textService = textService; diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs index 2768770e65..3305a7bbb1 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly LinkGenerator _linkGenerator; private readonly IRuntimeState _runtimeState; private readonly UmbracoFeatures _features; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; private readonly ContentSettings _contentSettings; private readonly TreeCollection _treeCollection; @@ -46,7 +46,7 @@ namespace Umbraco.Web.BackOffice.Controllers LinkGenerator linkGenerator, IRuntimeState runtimeState, UmbracoFeatures features, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUmbracoVersion umbracoVersion, IOptionsSnapshot contentSettings, IHttpContextAccessor httpContextAccessor, @@ -60,7 +60,7 @@ namespace Umbraco.Web.BackOffice.Controllers _linkGenerator = linkGenerator; _runtimeState = runtimeState; _features = features; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _httpContextAccessor = httpContextAccessor; diff --git a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs index 621f3a0e78..7fdfc81cd1 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs @@ -3,11 +3,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Net.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Mapping; using Umbraco.Core.Models; @@ -15,15 +14,13 @@ using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Core.Strings.Css; using Umbraco.Extensions; -using Umbraco.Web.Models.ContentEditing; -using Stylesheet = Umbraco.Core.Models.Stylesheet; -using StylesheetRule = Umbraco.Web.Models.ContentEditing.StylesheetRule; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Common.ActionsResults; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; -using Umbraco.Web.Editors; -using Umbraco.Web.BackOffice.Trees; +using Umbraco.Web.Models.ContentEditing; +using Stylesheet = Umbraco.Core.Models.Stylesheet; +using StylesheetRule = Umbraco.Web.Models.ContentEditing.StylesheetRule; namespace Umbraco.Web.BackOffice.Controllers { @@ -41,7 +38,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly ILocalizedTextService _localizedTextService; private readonly UmbracoMapper _umbracoMapper; private readonly IShortStringHelper _shortStringHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; public CodeFileController( IIOHelper ioHelper, @@ -51,9 +48,8 @@ namespace Umbraco.Web.BackOffice.Controllers ILocalizedTextService localizedTextService, UmbracoMapper umbracoMapper, IShortStringHelper shortStringHelper, - IGlobalSettings globalSettings) + IOptionsSnapshot globalSettings) { - _ioHelper = ioHelper; _fileSystems = fileSystems; _fileService = fileService; @@ -61,7 +57,7 @@ namespace Umbraco.Web.BackOffice.Controllers _localizedTextService = localizedTextService; _umbracoMapper = umbracoMapper; _shortStringHelper = shortStringHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } /// diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index 444667b591..28a09942dd 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -39,6 +39,8 @@ using Umbraco.Web.Editors; using Umbraco.Web.Routing; using Umbraco.Web.Security; using ContentType = Umbraco.Core.Models.ContentType; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.BackOffice.Controllers { @@ -55,7 +57,7 @@ namespace Umbraco.Web.BackOffice.Controllers public class ContentTypeController : ContentTypeControllerBase { private readonly IEntityXmlSerializer _serializer; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly PropertyEditorCollection _propertyEditors; private readonly IScopeProvider _scopeProvider; private readonly IIOHelper _ioHelper; @@ -74,7 +76,6 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IEntityService _entityService; private readonly IHostingEnvironment _hostingEnvironment; - public ContentTypeController( ICultureDictionary cultureDictionary, EditorValidatorCollection editorValidatorCollection, @@ -84,7 +85,7 @@ namespace Umbraco.Web.BackOffice.Controllers UmbracoMapper umbracoMapper, ILocalizedTextService localizedTextService, IEntityXmlSerializer serializer, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, IIOHelper ioHelper, @@ -108,7 +109,7 @@ namespace Umbraco.Web.BackOffice.Controllers localizedTextService) { _serializer = serializer; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _propertyEditors = propertyEditors; _scopeProvider = scopeProvider; _ioHelper = ioHelper; diff --git a/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs b/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs index 03bbe132f3..8970a70b34 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs @@ -43,7 +43,6 @@ namespace Umbraco.Web.BackOffice.Controllers /// Initializes a new instance of the with all its dependencies. /// public DashboardController( - IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, diff --git a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs index 7d362e52b6..b0b18c8da3 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs @@ -15,6 +15,8 @@ using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Security; using Constants = Umbraco.Core.Constants; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.BackOffice.Controllers { @@ -33,7 +35,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly ILogger _logger; private readonly ILocalizationService _localizationService; private readonly IWebSecurity _webSecurity; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly ILocalizedTextService _localizedTextService; private readonly UmbracoMapper _umbracoMapper; @@ -41,7 +43,7 @@ namespace Umbraco.Web.BackOffice.Controllers ILogger logger, ILocalizationService localizationService, IWebSecurity webSecurity, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, ILocalizedTextService localizedTextService, UmbracoMapper umbracoMapper ) @@ -49,7 +51,7 @@ namespace Umbraco.Web.BackOffice.Controllers _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); _webSecurity = webSecurity ?? throw new ArgumentNullException(nameof(webSecurity)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); _localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs b/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs index 14667c1fe5..0a58c04443 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Services; @@ -25,15 +27,15 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly ILocalizationService _localizationService; private readonly UmbracoMapper _umbracoMapper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; public LanguageController(ILocalizationService localizationService, UmbracoMapper umbracoMapper, - IGlobalSettings globalSettings) + IOptionsSnapshot globalSettings) { _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); } /// diff --git a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs index fec9d23f19..eeb73d6d47 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs @@ -1,11 +1,13 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewEngines; +using Microsoft.Extensions.Options; using System; using System.IO; using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.Services; @@ -28,7 +30,7 @@ namespace Umbraco.Web.BackOffice.Controllers public class PreviewController : Controller { private readonly UmbracoFeatures _features; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IPublishedSnapshotService _publishedSnapshotService; private readonly IWebSecurity _webSecurity; private readonly ILocalizationService _localizationService; @@ -39,7 +41,7 @@ namespace Umbraco.Web.BackOffice.Controllers public PreviewController( UmbracoFeatures features, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IPublishedSnapshotService publishedSnapshotService, IWebSecurity webSecurity, ILocalizationService localizationService, @@ -49,7 +51,7 @@ namespace Umbraco.Web.BackOffice.Controllers ICompositeViewEngine viewEngines) { _features = features; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _publishedSnapshotService = publishedSnapshotService; _webSecurity = webSecurity; _localizationService = localizationService; diff --git a/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs b/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs index 5086919b83..c5c5ca91ab 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs @@ -12,6 +12,8 @@ using Umbraco.Core.Mapping; using Umbraco.Core.Services; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Security; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.BackOffice.Controllers { @@ -19,21 +21,21 @@ namespace Umbraco.Web.BackOffice.Controllers public class RedirectUrlManagementController : UmbracoAuthorizedApiController { private readonly ILogger _logger; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly IWebSecurity _webSecurity; private readonly IRedirectUrlService _redirectUrlService; private readonly UmbracoMapper _umbracoMapper; private readonly IHostingEnvironment _hostingEnvironment; public RedirectUrlManagementController(ILogger logger, - IWebRoutingSettings webRoutingSettings, + IOptionsSnapshot webRoutingSettings, IWebSecurity webSecurity, IRedirectUrlService redirectUrlService, UmbracoMapper umbracoMapper, IHostingEnvironment hostingEnvironment) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _webRoutingSettings = webRoutingSettings ?? throw new ArgumentNullException(nameof(webRoutingSettings)); + _webRoutingSettings = webRoutingSettings.Value ?? throw new ArgumentNullException(nameof(webRoutingSettings)); _webSecurity = webSecurity ?? throw new ArgumentNullException(nameof(webSecurity)); _redirectUrlService = redirectUrlService ?? throw new ArgumentNullException(nameof(redirectUrlService)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); diff --git a/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs b/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs index 4212bace72..78ac2713c0 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs @@ -3,10 +3,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Options; using Semver; using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web.Common.Attributes; @@ -22,20 +24,20 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IUmbracoVersion _umbracoVersion; private readonly ICookieManager _cookieManager; private readonly IWebSecurity _webSecurity; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; public UpdateCheckController( IUpgradeService upgradeService, IUmbracoVersion umbracoVersion, ICookieManager cookieManager, IWebSecurity webSecurity, - IGlobalSettings globalSettings) + IOptionsSnapshot globalSettings) { _upgradeService = upgradeService ?? throw new ArgumentNullException(nameof(upgradeService)); _umbracoVersion = umbracoVersion ?? throw new ArgumentNullException(nameof(umbracoVersion)); _cookieManager = cookieManager ?? throw new ArgumentNullException(nameof(cookieManager)); _webSecurity = webSecurity ?? throw new ArgumentNullException(nameof(webSecurity)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); } [UpdateCheckResponseFilter] @@ -77,11 +79,11 @@ namespace Umbraco.Web.BackOffice.Controllers private class UpdateCheckResponseFilter : IActionFilter { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public UpdateCheckResponseFilter(IGlobalSettings globalSettings) + public UpdateCheckResponseFilter(IOptionsSnapshot globalSettings) { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void OnActionExecuted(ActionExecutedContext context) diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs index 07c2cab1c7..ab3f48cdad 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs @@ -66,7 +66,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IEntityService _entityService; private readonly IMediaService _mediaService; private readonly IContentService _contentService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly BackOfficeUserManager _backOfficeUserManager; private readonly ILogger _logger; private readonly LinkGenerator _linkGenerator; @@ -89,7 +89,7 @@ namespace Umbraco.Web.BackOffice.Controllers IEntityService entityService, IMediaService mediaService, IContentService contentService, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, BackOfficeUserManager backOfficeUserManager, ILogger logger, LinkGenerator linkGenerator) @@ -111,7 +111,7 @@ namespace Umbraco.Web.BackOffice.Controllers _entityService = entityService; _mediaService = mediaService; _contentService = contentService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _backOfficeUserManager = backOfficeUserManager; _logger = logger; _linkGenerator = linkGenerator; diff --git a/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs index e52287b57e..761c1110cb 100644 --- a/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs @@ -2,8 +2,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.BackOffice.Security; namespace Umbraco.Extensions @@ -20,12 +21,12 @@ namespace Umbraco.Extensions private class SetAngularAntiForgeryTokensFilter : IAsyncActionFilter { private readonly IBackOfficeAntiforgery _antiforgery; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public SetAngularAntiForgeryTokensFilter(IBackOfficeAntiforgery antiforgery, IGlobalSettings globalSettings) + public SetAngularAntiForgeryTokensFilter(IBackOfficeAntiforgery antiforgery, IOptionsSnapshot globalSettings) { _antiforgery = antiforgery; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) diff --git a/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs index 7c7652c532..f3fd82bdf6 100644 --- a/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs @@ -3,7 +3,8 @@ using System.Net; using System.Net.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.BackOffice.Filters { @@ -27,11 +28,11 @@ namespace Umbraco.Web.BackOffice.Filters public class UmbracoWebApiRequireHttpsFilter: IAuthorizationFilter { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public UmbracoWebApiRequireHttpsFilter(IGlobalSettings globalSettings) + public UmbracoWebApiRequireHttpsFilter(IOptionsSnapshot globalSettings) { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void OnAuthorization(AuthorizationFilterContext context) diff --git a/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs b/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs index ec0a75fe11..6d2fe9a9c8 100644 --- a/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs +++ b/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Common.Controllers; @@ -14,19 +16,19 @@ namespace Umbraco.Web.BackOffice.Routing /// public class BackOfficeAreaRoutes : IAreaRoutes { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; private readonly UmbracoApiControllerTypeCollection _apiControllers; private readonly string _umbracoPathSegment; public BackOfficeAreaRoutes( - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, UmbracoApiControllerTypeCollection apiControllers) { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _runtimeState = runtimeState; _apiControllers = apiControllers; diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeCookieManager.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeCookieManager.cs index 75112e9a22..60bdc9c8ff 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeCookieManager.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeCookieManager.cs @@ -1,16 +1,15 @@ -using Microsoft.AspNetCore.Authentication.Cookies; +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Routing; -using System; -using System.Collections.Generic; -using System.Linq; using Umbraco.Core; -using Umbraco.Extensions; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Web.BackOffice.Controllers; +using Umbraco.Extensions; namespace Umbraco.Web.BackOffice.Security { @@ -28,7 +27,7 @@ namespace Umbraco.Web.BackOffice.Security private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IRuntimeState _runtime; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IRequestCache _requestCache; private readonly string[] _explicitPaths; @@ -36,7 +35,7 @@ namespace Umbraco.Web.BackOffice.Security IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IHostingEnvironment hostingEnvironment, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IRequestCache requestCache, LinkGenerator linkGenerator) : this(umbracoContextAccessor, runtime, hostingEnvironment, globalSettings, requestCache, linkGenerator, null) @@ -46,7 +45,7 @@ namespace Umbraco.Web.BackOffice.Security IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IHostingEnvironment hostingEnvironment, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IRequestCache requestCache, LinkGenerator linkGenerator, IEnumerable explicitPaths) diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs index 70cdf05dc5..69a5359d4e 100644 --- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.BackOffice.Security { private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly SecuritySettings _securitySettings; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; private readonly IDataProtectionProvider _dataProtection; @@ -43,7 +43,7 @@ namespace Umbraco.Web.BackOffice.Security public ConfigureBackOfficeCookieOptions( IUmbracoContextAccessor umbracoContextAccessor, IOptionsSnapshot securitySettings, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, IDataProtectionProvider dataProtection, @@ -56,7 +56,7 @@ namespace Umbraco.Web.BackOffice.Security { _umbracoContextAccessor = umbracoContextAccessor; _securitySettings = securitySettings.Value; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _runtimeState = runtimeState; _dataProtection = dataProtection; diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index 39b1d7ff4e..4dc72bfd95 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -1,11 +1,17 @@ +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreBackOfficeInfo : IBackOfficeInfo { - public AspNetCoreBackOfficeInfo(IGlobalSettings globalSettings) + public AspNetCoreBackOfficeInfo(IOptionsSnapshot globalSettings) + : this(globalSettings.Value) + { + } + + public AspNetCoreBackOfficeInfo(GlobalSettings globalSettings) { GetAbsoluteUrl = globalSettings.UmbracoPath; } diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index efa1a52ad4..f35ced66f0 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -1,19 +1,26 @@ using System; using System.IO; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Common.AspNetCore { - public class AspNetCoreHostingEnvironment : Umbraco.Core.Hosting.IHostingEnvironment + public class AspNetCoreHostingEnvironment : Core.Hosting.IHostingEnvironment { - private readonly IHostingSettings _hostingSettings; + private readonly HostingSettings _hostingSettings; private readonly IWebHostEnvironment _webHostEnvironment; private string _localTempPath; - public AspNetCoreHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) + public AspNetCoreHostingEnvironment(IOptionsSnapshot hostingSettings, IWebHostEnvironment webHostEnvironment) + : this(hostingSettings.Value, webHostEnvironment) + { + } + + public AspNetCoreHostingEnvironment(HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) { _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); _webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment)); @@ -27,7 +34,6 @@ namespace Umbraco.Web.Common.AspNetCore ?? "/"; IISVersion = new Version(0, 0); // TODO not necessary IIS - } public bool IsHosted { get; } = true; diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs index d29e58a2bf..2b27e37887 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Extensions; using Umbraco.Web.Common.Lifetime; @@ -13,18 +15,18 @@ namespace Umbraco.Web.Common.AspNetCore { private readonly IHttpContextAccessor _httpContextAccessor; private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly ISet _applicationUrls = new HashSet(); private Uri _currentApplicationUrl; public AspNetCoreRequestAccessor(IHttpContextAccessor httpContextAccessor, IUmbracoRequestLifetime umbracoRequestLifetime, IUmbracoContextAccessor umbracoContextAccessor, - IWebRoutingSettings webRoutingSettings) + IOptionsSnapshot webRoutingSettings) { _httpContextAccessor = httpContextAccessor; _umbracoContextAccessor = umbracoContextAccessor; - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; umbracoRequestLifetime.RequestStart += RequestStart; umbracoRequestLifetime.RequestEnd += RequestEnd; diff --git a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs index 88e361029f..28bb1dc41c 100644 --- a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs +++ b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.Common.AspNetCore private IUmbracoContext _umbracoContext; private IUmbracoContextAccessor UmbracoContextAccessor => Context.RequestServices.GetRequiredService(); - private IGlobalSettings GlobalSettings => Context.RequestServices.GetRequiredService(); + private GlobalSettings GlobalSettings => Context.RequestServices.GetRequiredService>().Value; private ContentSettings ContentSettings => Context.RequestServices.GetRequiredService>().Value; private IProfilerHtml ProfilerHtml => Context.RequestServices.GetRequiredService(); private IIOHelper IOHelper => Context.RequestServices.GetRequiredService(); diff --git a/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs b/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs index 5baedf3ded..0369717b9b 100644 --- a/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; namespace Umbraco.Extensions @@ -24,7 +25,7 @@ namespace Umbraco.Extensions return request.Cookies.TryGetValue(Constants.Web.PreviewCookieName, out var cookieVal) && !cookieVal.IsNullOrWhiteSpace(); } - public static bool IsBackOfficeRequest(this HttpRequest request, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static bool IsBackOfficeRequest(this HttpRequest request, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { return new Uri(request.GetEncodedUrl(), UriKind.RelativeOrAbsolute).IsBackOfficeRequest(globalSettings, hostingEnvironment); } diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 7a02b53724..cbdbeac873 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -9,15 +9,16 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Serilog; using Serilog.Extensions.Hosting; using Serilog.Extensions.Logging; using Umbraco.Configuration; -using Umbraco.Configuration.Models; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; @@ -26,7 +27,7 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Runtime; using Umbraco.Web.Common.AspNetCore; using Umbraco.Web.Common.Profiler; -using CoreDebugSettings = Umbraco.Configuration.Models.CoreDebugSettings; +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Extensions { @@ -101,6 +102,7 @@ namespace Umbraco.Extensions { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ConnectionStrings")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Core:Debug")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); @@ -113,12 +115,12 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigModelsBuilderPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix)); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging:")); var configsFactory = new AspNetCoreConfigsFactory(configuration); @@ -217,21 +219,27 @@ namespace Umbraco.Extensions // into the container. This is not true for `Configs` but we should do that too, see comments in // `RegisterEssentials`. var serviceProvider = services.BuildServiceProvider(); - var configs = serviceProvider.GetService(); + + var globalSettings = serviceProvider.GetService>().Value; + var connectionStrings = serviceProvider.GetService>().Value; + var hostingSettings = serviceProvider.GetService>().Value; + var typeFinderSettings = serviceProvider.GetService>().Value; + var dbProviderFactoryCreator = serviceProvider.GetRequiredService(); CreateCompositionRoot(services, - configs, + globalSettings, + hostingSettings, webHostEnvironment, loggingConfiguration, out var logger, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler); - var globalSettings = configs.Global(); var umbracoVersion = new UmbracoVersion(globalSettings); - var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, configs.TypeFinder()); + var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); var coreRuntime = GetCoreRuntime( - configs, + globalSettings, + connectionStrings, umbracoVersion, ioHelper, logger, @@ -247,7 +255,7 @@ namespace Umbraco.Extensions return services; } - private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, ITypeFinderSettings typeFinderSettings) + private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, TypeFinderSettings typeFinderSettings) { var runtimeHashPaths = new RuntimeHashPaths(); runtimeHashPaths.AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin"))); @@ -256,25 +264,23 @@ namespace Umbraco.Extensions } private static IRuntime GetCoreRuntime( - Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, Core.Logging.ILogger logger, + GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, Core.Logging.ILogger logger, IProfiler profiler, Core.Hosting.IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, ITypeFinder typeFinder, IRequestCache requestCache, IDbProviderFactoryCreator dbProviderFactoryCreator) { - // Determine if we should use the sql main dom or the default - var globalSettings = configs.Global(); - var connStrings = configs.ConnectionStrings(); var appSettingMainDomLock = globalSettings.MainDomLock; var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); var mainDomLock = appSettingMainDomLock == "SqlMainDomLock" || isWindows == false - ? (IMainDomLock)new SqlMainDomLock(logger, globalSettings, connStrings, dbProviderFactoryCreator, hostingEnvironment) + ? (IMainDomLock)new SqlMainDomLock(logger, globalSettings, connectionStrings, dbProviderFactoryCreator, hostingEnvironment) : new MainDomSemaphoreLock(logger, hostingEnvironment); var mainDom = new MainDom(logger, mainDomLock); var coreRuntime = new CoreRuntime( - configs, + globalSettings, + connectionStrings, umbracoVersion, ioHelper, logger, @@ -292,7 +298,8 @@ namespace Umbraco.Extensions private static IServiceCollection CreateCompositionRoot( IServiceCollection services, - Configs configs, + GlobalSettings globalSettings, + HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment, ILoggingConfiguration loggingConfiguration, out Core.Logging.ILogger logger, @@ -301,14 +308,12 @@ namespace Umbraco.Extensions out IBackOfficeInfo backOfficeInfo, out IProfiler profiler) { - if (configs == null) - throw new InvalidOperationException($"Could not resolve type {typeof(Configs)} from the container, ensure {nameof(AddUmbracoConfiguration)} is called before calling {nameof(AddUmbracoCore)}"); + if (globalSettings == null) + throw new InvalidOperationException($"Could not resolve type {typeof(GlobalSettings)} from the container, ensure {nameof(AddUmbracoConfiguration)} is called before calling {nameof(AddUmbracoCore)}"); - var hostingSettings = configs.Hosting(); - var globalSettings = configs.Global(); hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment); - ioHelper = new IOHelper(hostingEnvironment, globalSettings); + ioHelper = new IOHelper(hostingEnvironment); logger = AddLogger(services, hostingEnvironment, loggingConfiguration); backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs index a795edf6cf..61120c8ee9 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs @@ -19,6 +19,7 @@ using Smidge; using Smidge.Nuglify; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Common.ApplicationModels; using Umbraco.Web.Common.Middleware; using Umbraco.Web.Common.ModelBinding; @@ -40,8 +41,7 @@ namespace Umbraco.Extensions // TODO: We need to avoid this, surely there's a way? See ContainerTests.BuildServiceProvider_Before_Host_Is_Configured var serviceProvider = services.BuildServiceProvider(); - var configs = serviceProvider.GetService(); - var imagingSettings = configs.Imaging(); + var imagingSettings = serviceProvider.GetService>().Value; services.AddUmbracoImageSharp(imagingSettings); return services; @@ -53,19 +53,19 @@ namespace Umbraco.Extensions /// /// /// - public static IServiceCollection AddUmbracoImageSharp(this IServiceCollection services, IImagingSettings imagingSettings) + public static IServiceCollection AddUmbracoImageSharp(this IServiceCollection services, ImagingSettings imagingSettings) { services.AddImageSharpCore( options => { options.Configuration = SixLabors.ImageSharp.Configuration.Default; - options.MaxBrowserCacheDays = imagingSettings.MaxBrowserCacheDays; - options.MaxCacheDays = imagingSettings.MaxCacheDays; - options.CachedNameLength = imagingSettings.CachedNameLength; + options.MaxBrowserCacheDays = imagingSettings.Cache.MaxBrowserCacheDays; + options.MaxCacheDays = imagingSettings.Cache.MaxCacheDays; + options.CachedNameLength = imagingSettings.Cache.CachedNameLength; options.OnParseCommands = context => { - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.MaxResizeWidth); - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.MaxResizeHeight); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.Resize.MaxResizeWidth); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.Resize.MaxResizeHeight); }; options.OnBeforeSave = _ => { }; options.OnProcessed = _ => { }; @@ -75,7 +75,7 @@ namespace Umbraco.Extensions .SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling()) .Configure(options => { - options.CacheFolder = imagingSettings.CacheFolder; + options.CacheFolder = imagingSettings.Cache.CacheFolder; }) .SetCache() .SetCacheHash() diff --git a/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs b/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs index 8f3fcf3a95..a35628821b 100644 --- a/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs @@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Web.Common.Filters @@ -26,7 +28,7 @@ namespace Umbraco.Web.Common.Filters httpContext.Response.StatusCode = (int)_statusCode; - var disableIisCustomErrors = httpContext.RequestServices.GetService().TrySkipIisCustomErrors; + var disableIisCustomErrors = httpContext.RequestServices.GetService>().Value.TrySkipIisCustomErrors; var statusCodePagesFeature = httpContext.Features.Get(); if (statusCodePagesFeature != null) diff --git a/src/Umbraco.Web.Common/Install/InstallController.cs b/src/Umbraco.Web.Common/Install/InstallController.cs index 2b9f716516..d97bb86fed 100644 --- a/src/Umbraco.Web.Common/Install/InstallController.cs +++ b/src/Umbraco.Web.Common/Install/InstallController.cs @@ -12,6 +12,8 @@ using Umbraco.Extensions; using Umbraco.Web.Common.Filters; using Umbraco.Web.Install; using Umbraco.Web.Security; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Common.Install { @@ -26,7 +28,7 @@ namespace Umbraco.Web.Common.Install private readonly IWebSecurity _webSecurity; private readonly InstallHelper _installHelper; private readonly IRuntimeState _runtime; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IUmbracoVersion _umbracoVersion; private readonly ILogger _logger; @@ -37,7 +39,7 @@ namespace Umbraco.Web.Common.Install IWebSecurity webSecurity, InstallHelper installHelper, IRuntimeState runtime, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IRuntimeMinifier runtimeMinifier, IHostingEnvironment hostingEnvironment, IUmbracoVersion umbracoVersion, @@ -47,7 +49,7 @@ namespace Umbraco.Web.Common.Install _webSecurity = webSecurity; _installHelper = installHelper; _runtime = runtime; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _runtimeMinifier = runtimeMinifier; _hostingEnvironment = hostingEnvironment; _umbracoVersion = umbracoVersion; diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs index a0a84e893f..0cfacbbf13 100644 --- a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs @@ -1,33 +1,32 @@ +using System.Linq; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Diagnostics; using Umbraco.Core.Hosting; -using Umbraco.Net; +using Umbraco.Core.Logging; using Umbraco.Core.Runtime; using Umbraco.Core.Security; +using Umbraco.Extensions; +using Umbraco.Net; using Umbraco.Web.Common.AspNetCore; +using Umbraco.Web.Common.Controllers; using Umbraco.Web.Common.Formatters; +using Umbraco.Web.Common.Install; using Umbraco.Web.Common.Lifetime; using Umbraco.Web.Common.Macros; -using Umbraco.Web.Composing.CompositionExtensions; -using Umbraco.Web.Macros; -using Umbraco.Core.Diagnostics; -using Umbraco.Core.Logging; -using Umbraco.Web.Common.Profiler; -using Umbraco.Web.Common.Install; -using Umbraco.Extensions; -using System.Linq; -using Umbraco.Core.Configuration; -using Umbraco.Web.Common.Controllers; using Umbraco.Web.Common.Middleware; using Umbraco.Web.Common.ModelBinding; +using Umbraco.Web.Common.Profiler; using Umbraco.Web.Common.Routing; -using Umbraco.Web.Common.Templates; using Umbraco.Web.Common.Security; +using Umbraco.Web.Common.Templates; +using Umbraco.Web.Composing.CompositionExtensions; +using Umbraco.Web.Macros; using Umbraco.Web.Security; using Umbraco.Web.Templates; -using Umbraco.Configuration.Models; -using Microsoft.Extensions.Options; namespace Umbraco.Web.Common.Runtime { diff --git a/src/Umbraco.Web.Common/Security/WebSecurity.cs b/src/Umbraco.Web.Common/Security/WebSecurity.cs index c67d5a9b4f..69f5850482 100644 --- a/src/Umbraco.Web.Common/Security/WebSecurity.cs +++ b/src/Umbraco.Web.Common/Security/WebSecurity.cs @@ -1,33 +1,33 @@ using System; using System.Security; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; +using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Extensions; using Umbraco.Web.Security; -using Umbraco.Core.Models; namespace Umbraco.Web.Common.Security { - public class WebSecurity : IWebSecurity { private readonly IUserService _userService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; public WebSecurity( IUserService userService, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IHttpContextAccessor httpContextAccessor) { _userService = userService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _httpContextAccessor = httpContextAccessor; } @@ -113,7 +113,7 @@ namespace Umbraco.Web.Common.Security return ValidateRequestAttempt.Success; } - private static bool RequestIsInUmbracoApplication(IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + private static bool RequestIsInUmbracoApplication(IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToString().IndexOf(hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), StringComparison.InvariantCultureIgnoreCase) > -1; } diff --git a/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs b/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs index d692303df5..81a635a20f 100644 --- a/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs +++ b/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs @@ -11,7 +11,9 @@ using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Services; using Umbraco.Core.Strings; @@ -34,7 +36,7 @@ namespace Umbraco.Web.Common.Templates private readonly IPublishedRouter _publishedRouter; private readonly IFileService _fileService; private readonly ILocalizationService _languageService; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly IShortStringHelper _shortStringHelper; private readonly IHttpContextAccessor _httpContextAccessor; private readonly ICompositeViewEngine _viewEngine; @@ -43,7 +45,7 @@ namespace Umbraco.Web.Common.Templates IPublishedRouter publishedRouter, IFileService fileService, ILocalizationService textService, - IWebRoutingSettings webRoutingSettings, + IOptionsSnapshot webRoutingSettings, IShortStringHelper shortStringHelper, IHttpContextAccessor httpContextAccessor, ICompositeViewEngine viewEngine) @@ -52,7 +54,7 @@ namespace Umbraco.Web.Common.Templates _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); _fileService = fileService ?? throw new ArgumentNullException(nameof(fileService)); _languageService = textService ?? throw new ArgumentNullException(nameof(textService)); - _webRoutingSettings = webRoutingSettings ?? throw new ArgumentNullException(nameof(webRoutingSettings)); + _webRoutingSettings = webRoutingSettings.Value ?? throw new ArgumentNullException(nameof(webRoutingSettings)); _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper)); _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); _viewEngine = viewEngine ?? throw new ArgumentNullException(nameof(viewEngine)); diff --git a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs index 4419015105..b255013b7f 100644 --- a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs +++ b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs @@ -1,7 +1,9 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.PublishedCache; @@ -15,7 +17,7 @@ namespace Umbraco.Web /// public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd, IUmbracoContext { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly ICookieManager _cookieManager; private readonly IRequestAccessor _requestAccessor; @@ -30,7 +32,7 @@ namespace Umbraco.Web internal UmbracoContext( IPublishedSnapshotService publishedSnapshotService, IWebSecurity webSecurity, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IVariationContextAccessor variationContextAccessor, UriUtility uriUtility, diff --git a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs index 3c771a1668..a3849c532e 100644 --- a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs +++ b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs @@ -2,7 +2,9 @@ using System.IO; using System.Text; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -22,7 +24,7 @@ namespace Umbraco.Web private readonly IVariationContextAccessor _variationContextAccessor; private readonly IDefaultCultureAccessor _defaultCultureAccessor; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUserService _userService; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; @@ -39,7 +41,7 @@ namespace Umbraco.Web IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUserService userService, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, @@ -52,7 +54,7 @@ namespace Umbraco.Web _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _defaultCultureAccessor = defaultCultureAccessor ?? throw new ArgumentNullException(nameof(defaultCultureAccessor)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _uriUtility = uriUtility ?? throw new ArgumentNullException(nameof(uriUtility)); diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml index d9f39b544c..0a7c95e7fe 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml @@ -1,21 +1,22 @@ -@using Umbraco.Core +@using Microsoft.Extensions.Options; +@using Umbraco.Core @using Umbraco.Web.WebAssets @using Umbraco.Web.Common.Security @using Umbraco.Core.WebAssets @using Umbraco.Core.Configuration +@using Umbraco.Core.Configuration.Models @using Umbraco.Core.Hosting @using Umbraco.Extensions -@using Umbraco.Core.Logging @using Umbraco.Web.BackOffice.Controllers @inject BackOfficeSignInManager signInManager @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IGlobalSettings globalSettings +@inject IOptionsSnapshot globalSettings @inject IRuntimeMinifier runtimeMinifier @{ - var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment); + var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment); } diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml index 55959c27a8..bce17553d6 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml @@ -1,8 +1,10 @@ -@using Umbraco.Core +@using Microsoft.Extensions.Options; +@using Umbraco.Core @using Umbraco.Web.WebAssets @using Umbraco.Web.Common.Security @using Umbraco.Core.WebAssets @using Umbraco.Core.Configuration +@using Umbraco.Core.Configuration.Models @using Umbraco.Core.Hosting @using Umbraco.Extensions @using Umbraco.Core.Logging @@ -11,7 +13,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IGlobalSettings globalSettings +@inject IOptionsSnapshot globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml @@ -19,7 +21,7 @@ var isDebug = false; var qryDebug = Context.Request.Query["umbDebug"].ToString().TryConvertTo(); isDebug = qryDebug.Success && qryDebug.Result; - var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment); + var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment); } diff --git a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml index d399817502..bce17553d6 100644 --- a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml +++ b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml @@ -1,8 +1,10 @@ -@using Umbraco.Core +@using Microsoft.Extensions.Options; +@using Umbraco.Core @using Umbraco.Web.WebAssets @using Umbraco.Web.Common.Security @using Umbraco.Core.WebAssets @using Umbraco.Core.Configuration +@using Umbraco.Core.Configuration.Models @using Umbraco.Core.Hosting @using Umbraco.Extensions @using Umbraco.Core.Logging @@ -11,15 +13,15 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IGlobalSettings globalSettings +@inject IOptionsSnapshot globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml @{ var isDebug = false; - var qryDebug = Context.Request.Query["umbDebug"].TryConvertTo(); + var qryDebug = Context.Request.Query["umbDebug"].ToString().TryConvertTo(); isDebug = qryDebug.Success && qryDebug.Result; - var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment); + var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment); } diff --git a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml index 3bab021741..dd34dab6f4 100644 --- a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml +++ b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml @@ -1,8 +1,9 @@ -@using Umbraco.Core +@using Microsoft.Extensions.Options; @using Umbraco.Web.WebAssets @using Umbraco.Web.Common.Security @using Umbraco.Core.WebAssets @using Umbraco.Core.Configuration +@using Umbraco.Core.Configuration.Models @using Umbraco.Core.Hosting @using Umbraco.Extensions @using Umbraco.Core.Logging @@ -11,7 +12,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IGlobalSettings globalSettings +@inject IOptionsSnapshot globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index c8c6cbdf5c..2c4273b5a1 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.SignalR; using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Web.Composing; @@ -46,7 +47,7 @@ namespace Umbraco.Web /// The app builder. /// /// - public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static IAppBuilder UseSignalR(this IAppBuilder app, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; diff --git a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs index 1e60fedeea..ab3f575d36 100644 --- a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs +++ b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs @@ -1,6 +1,8 @@ using System.Web; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -9,12 +11,17 @@ namespace Umbraco.Web { public class AspNetBackOfficeInfo : IBackOfficeInfo { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; - public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IWebRoutingSettings webRoutingSettings) + public AspNetBackOfficeInfo(IOptionsSnapshot globalSettings, IIOHelper ioHelper, ILogger logger, IOptionsSnapshot webRoutingSettings) + : this(globalSettings.Value, ioHelper, logger, webRoutingSettings.Value) + { + } + + public AspNetBackOfficeInfo(GlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, WebRoutingSettings webRoutingSettings) { _globalSettings = globalSettings; _ioHelper = ioHelper; diff --git a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs index 5e7324236a..2423c7802b 100644 --- a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs @@ -2,27 +2,27 @@ using System; using System.Reflection; using System.Web; using System.Web.Hosting; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; namespace Umbraco.Web.Hosting { public class AspNetHostingEnvironment : IHostingEnvironment { - - private readonly IHostingSettings _hostingSettings; + private readonly HostingSettings _hostingSettings; private string _localTempPath; - - public AspNetHostingEnvironment(IHostingSettings hostingSettings) + public AspNetHostingEnvironment(IOptionsSnapshot hostingSettings) { - _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); + _hostingSettings = hostingSettings.Value ?? throw new ArgumentNullException(nameof(hostingSettings)); SiteName = HostingEnvironment.SiteName; ApplicationId = HostingEnvironment.ApplicationID; // when we are not hosted (i.e. unit test or otherwise) we'll need to get the root path from the executing assembly ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath ?? Assembly.GetExecutingAssembly().GetRootDirectorySafe(); - ApplicationVirtualPath = hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') + ApplicationVirtualPath = _hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') ?? HostingEnvironment.ApplicationVirtualPath?.EnsureStartsWith("/") ?? "/"; IISVersion = HttpRuntime.IISVersion; diff --git a/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs b/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs index aa2cba6949..7e1e853716 100644 --- a/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs +++ b/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Web.Routing; @@ -8,20 +10,18 @@ namespace Umbraco.Web.AspNet public class AspNetRequestAccessor : IRequestAccessor { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly ISet _applicationUrls = new HashSet(); private Uri _currentApplicationUrl; - public AspNetRequestAccessor(IHttpContextAccessor httpContextAccessor, IWebRoutingSettings webRoutingSettings) + public AspNetRequestAccessor(IHttpContextAccessor httpContextAccessor, IOptionsSnapshot webRoutingSettings) { _httpContextAccessor = httpContextAccessor; - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; UmbracoModule.EndRequest += OnEndRequest; UmbracoModule.RouteAttempt += OnRouteAttempt; } - - public string GetRequestValue(string name) { return _httpContextAccessor.GetRequiredHttpContext().Request[name]; diff --git a/src/Umbraco.Web/Compose/AuditEventsComponent.cs b/src/Umbraco.Web/Compose/AuditEventsComponent.cs index 51c47233c7..ef81a35b1c 100644 --- a/src/Umbraco.Web/Compose/AuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/AuditEventsComponent.cs @@ -11,6 +11,8 @@ using Umbraco.Net; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Extensions; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Core.Compose { @@ -20,15 +22,15 @@ namespace Umbraco.Core.Compose private readonly IUserService _userService; private readonly IEntityService _entityService; private readonly IIpResolver _ipResolver; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public AuditEventsComponent(IAuditService auditService, IUserService userService, IEntityService entityService, IIpResolver ipResolver, IGlobalSettings globalSettings) + public AuditEventsComponent(IAuditService auditService, IUserService userService, IEntityService entityService, IIpResolver ipResolver, IOptionsSnapshot globalSettings) { _auditService = auditService; _userService = userService; _entityService = entityService; _ipResolver = ipResolver; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void Initialize() @@ -49,7 +51,7 @@ namespace Umbraco.Core.Compose public void Terminate() { } - public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(globalSettings) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; + public static IUser UnknownUser(GlobalSettings globalSettings) => new User(globalSettings) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; private IUser CurrentPerformingUser { diff --git a/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs b/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs index dcb5fac32d..2357a62eb8 100644 --- a/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs @@ -1,8 +1,10 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Compose; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Web.Security; @@ -13,13 +15,13 @@ namespace Umbraco.Web.Compose { private readonly IAuditService _auditService; private readonly IUserService _userService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public BackOfficeUserAuditEventsComponent(IAuditService auditService, IUserService userService, IGlobalSettings globalSettings) + public BackOfficeUserAuditEventsComponent(IAuditService auditService, IUserService userService, IOptionsSnapshot globalSettings) { _auditService = auditService; _userService = userService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public void Initialize() diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 73fa53f7bc..d919f04077 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -39,7 +39,7 @@ namespace Umbraco.Web.Editors { private BackOfficeOwinUserManager _userManager; private BackOfficeSignInManager _signInManager; - private readonly IUserPasswordConfiguration _passwordConfiguration; + private readonly UserPasswordConfigurationSettings _passwordConfiguration; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; private readonly SecuritySettings _securitySettings; @@ -47,8 +47,8 @@ namespace Umbraco.Web.Editors private readonly IEmailSender _emailSender; public AuthenticationController( - IUserPasswordConfiguration passwordConfiguration, - IGlobalSettings globalSettings, + IOptionsSnapshot passwordConfiguration, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, @@ -63,7 +63,7 @@ namespace Umbraco.Web.Editors IEmailSender emailSender) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { - _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); + _passwordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); _securitySettings = securitySettings.Value ?? throw new ArgumentNullException(nameof(securitySettings)); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 4258267421..de94f42007 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.Editors public BackOfficeController( UmbracoFeatures features, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 0dd232cbfb..4246ffb2ec 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -28,7 +28,7 @@ namespace Umbraco.Web.Editors private readonly UrlHelper _urlHelper; private readonly IRuntimeState _runtimeState; private readonly UmbracoFeatures _features; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; private readonly IContentSettings _contentSettings; private readonly TreeCollection _treeCollection; @@ -42,7 +42,7 @@ namespace Umbraco.Web.Editors UrlHelper urlHelper, IRuntimeState runtimeState, UmbracoFeatures features, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUmbracoVersion umbracoVersion, IContentSettings contentSettings, TreeCollection treeCollection, @@ -54,7 +54,7 @@ namespace Umbraco.Web.Editors _urlHelper = urlHelper; _runtimeState = runtimeState; _features = features; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); diff --git a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs index 64aba378f4..f0f7e50be5 100644 --- a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs +++ b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs @@ -1,7 +1,9 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -31,7 +33,7 @@ namespace Umbraco.Web.Editors } protected UmbracoAuthorizedJsonController( - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 6fe069fc59..d6c4451efb 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -10,6 +10,7 @@ using System.Web.Mvc.Html; using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Web.Mvc; @@ -60,18 +61,18 @@ namespace Umbraco.Web /// /// See: http://issues.umbraco.org/issue/U4-1614 /// - public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IIOHelper ioHelper, IContentSettings contentSettings) + public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings, IIOHelper ioHelper, IContentSettings contentSettings) { if (Current.UmbracoContext.InPreviewMode) { var htmlBadge = - String.Format(contentSettings.PreviewBadge, + string.Format(contentSettings.PreviewBadge, ioHelper.ResolveUrl(globalSettings.UmbracoPath), WebUtility.UrlEncode(httpContextAccessor.GetRequiredHttpContext().Request.Path), Current.UmbracoContext.PublishedRequest.PublishedContent.Id); return new MvcHtmlString(htmlBadge); } - return new MvcHtmlString(""); + return new MvcHtmlString(string.Empty); } diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 118c53a7f0..e25ab4a69e 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -6,10 +6,8 @@ using System.Web.Routing; using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Exceptions; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Web.Composing; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -44,7 +42,7 @@ namespace Umbraco.Web.Mvc /// /// internal static Route RouteControllerPlugin(this AreaRegistration area, - IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, string controllerName, Type controllerType, RouteCollection routes, string controllerSuffixName, string defaultAction, object defaultId, string umbracoTokenValue = "backoffice", diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index 156a896bb5..2037d37914 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,8 +1,8 @@ using System.Web.Mvc; -using Umbraco.Web.Composing; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Web.Editors; namespace Umbraco.Web.Mvc @@ -10,10 +10,15 @@ namespace Umbraco.Web.Mvc // TODO: This has been ported to netcore, can be removed internal class BackOfficeArea : AreaRegistration { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - public BackOfficeArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public BackOfficeArea(IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) + : this(globalSettings.Value, hostingEnvironment) + { + } + + public BackOfficeArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Web/Mvc/PluginControllerArea.cs b/src/Umbraco.Web/Mvc/PluginControllerArea.cs index 838e304847..bf2d24086d 100644 --- a/src/Umbraco.Web/Mvc/PluginControllerArea.cs +++ b/src/Umbraco.Web/Mvc/PluginControllerArea.cs @@ -9,6 +9,8 @@ using Umbraco.Core.Composing; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Web.WebApi; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Mvc { @@ -17,7 +19,7 @@ namespace Umbraco.Web.Mvc /// internal class PluginControllerArea : AreaRegistration { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IEnumerable _surfaceControllers; private readonly IEnumerable _apiControllers; @@ -30,7 +32,12 @@ namespace Umbraco.Web.Mvc /// /// /// - public PluginControllerArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) + public PluginControllerArea(IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) + : this(globalSettings.Value, hostingEnvironment, pluginControllers) + { + } + + public PluginControllerArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) { _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; @@ -41,7 +48,7 @@ namespace Umbraco.Web.Mvc throw new InvalidOperationException("Cannot create a PluginControllerArea unless all plugin controllers assigned have a PluginControllerAttribute assigned"); } _areaName = controllers.First().AreaName; - foreach(var c in controllers) + foreach (var c in controllers) { if (c.AreaName != _areaName) { diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 7286f52c64..1e6f5a00c3 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -1,7 +1,8 @@ using System; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -10,7 +11,6 @@ using Umbraco.Web.Routing; namespace Umbraco.Web.Mvc { - /// /// Represents the default front-end rendering controller. /// @@ -25,7 +25,7 @@ namespace Umbraco.Web.Mvc ActionInvoker = new RenderActionInvoker(); } - public RenderMvcController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + public RenderMvcController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { ActionInvoker = new RenderActionInvoker(); diff --git a/src/Umbraco.Web/Mvc/RenderNoContentController.cs b/src/Umbraco.Web/Mvc/RenderNoContentController.cs index 9334591fbb..1f9a24212b 100644 --- a/src/Umbraco.Web/Mvc/RenderNoContentController.cs +++ b/src/Umbraco.Web/Mvc/RenderNoContentController.cs @@ -1,6 +1,8 @@ using System; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Models; @@ -10,13 +12,13 @@ namespace Umbraco.Web.Mvc { private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IIOHelper _ioHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IGlobalSettings globalSettings) + public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IOptionsSnapshot globalSettings) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); } public ActionResult Index() diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs index 0724cd138d..f774eb8a4e 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs @@ -1,5 +1,7 @@ -using Umbraco.Core.Cache; +using Microsoft.Extensions.Options; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Services; @@ -21,7 +23,7 @@ namespace Umbraco.Web.Mvc { } - protected UmbracoAuthorizedController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + protected UmbracoAuthorizedController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { } diff --git a/src/Umbraco.Web/Mvc/UmbracoController.cs b/src/Umbraco.Web/Mvc/UmbracoController.cs index 9cfd93ba9d..ff0ac170fb 100644 --- a/src/Umbraco.Web/Mvc/UmbracoController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoController.cs @@ -1,13 +1,14 @@ using System; using System.Web; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Microsoft.Owin; -using Umbraco.Core.Cache; -using Umbraco.Web.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Logging; using Umbraco.Core.Services; +using Umbraco.Web.Composing; using Umbraco.Web.Security; namespace Umbraco.Web.Mvc @@ -21,9 +22,9 @@ namespace Umbraco.Web.Mvc internal Guid InstanceId { get; } = Guid.NewGuid(); /// - /// Gets or sets the Umbraco context. + /// Gets the global settings from configuration. /// - public IGlobalSettings GlobalSettings { get; } + public GlobalSettings GlobalSettings { get; } /// /// Gets the Umbraco context. @@ -69,7 +70,7 @@ namespace Umbraco.Web.Mvc protected UmbracoController() : this( - Current.Factory.GetInstance(), + Current.Factory.GetInstance>(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), @@ -78,9 +79,9 @@ namespace Umbraco.Web.Mvc { } - protected UmbracoController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + protected UmbracoController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) { - GlobalSettings = globalSettings; + GlobalSettings = globalSettings.Value; UmbracoContextAccessor = umbracoContextAccessor; Services = services; AppCaches = appCaches; diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index a687e7c9cd..b9c31388a2 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -3,9 +3,11 @@ using System.Text; using System.Web; using System.Web.Mvc; using System.Web.WebPages; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -22,8 +24,8 @@ namespace Umbraco.Web.Mvc /// public abstract class UmbracoViewPage : WebViewPage { - private readonly IGlobalSettings _globalSettings; - private readonly IContentSettings _contentSettings; + private readonly GlobalSettings _globalSettings; + private readonly ContentSettings _contentSettings; private IUmbracoContext _umbracoContext; private UmbracoHelper _helper; @@ -105,18 +107,18 @@ namespace Umbraco.Web.Mvc : this( Current.Factory.GetInstance(), Current.Factory.GetInstance(), - Current.Factory.GetInstance(), - Current.Factory.GetInstance() + Current.Factory.GetInstance>(), + Current.Factory.GetInstance>() ) { } - protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IGlobalSettings globalSettings, IContentSettings contentSettings) + protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IOptionsSnapshot globalSettings, IOptionsSnapshot contentSettings) { Services = services; AppCaches = appCaches; - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); } // view logic below: diff --git a/src/Umbraco.Web/RoutableDocumentFilter.cs b/src/Umbraco.Web/RoutableDocumentFilter.cs index 43e47a39b3..5f5c832d1f 100644 --- a/src/Umbraco.Web/RoutableDocumentFilter.cs +++ b/src/Umbraco.Web/RoutableDocumentFilter.cs @@ -1,16 +1,17 @@ using System; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Threading; using System.Web; using System.Web.Routing; +using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Configuration; -using System.Threading; -using System.Collections.Generic; -using System.Linq; -using System.Collections.Concurrent; using Umbraco.Core.Collections; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; -using Umbraco.Web.Composing; namespace Umbraco.Web { @@ -22,20 +23,20 @@ namespace Umbraco.Web /// public sealed class RoutableDocumentFilter { - public RoutableDocumentFilter(IGlobalSettings globalSettings, IIOHelper ioHelper) - { - _globalSettings = globalSettings; - _ioHelper = ioHelper; - } - private static readonly ConcurrentDictionary RouteChecks = new ConcurrentDictionary(); - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private object _locker = new object(); private bool _isInit = false; private int? _routeCount; private HashSet _reservedList; + public RoutableDocumentFilter(IOptionsSnapshot globalSettings, IIOHelper ioHelper) + { + _globalSettings = globalSettings.Value; + _ioHelper = ioHelper; + } + /// /// Checks if the request is a document request (i.e. one that the module should handle) /// diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index dbd0a1fb3a..88c08cd937 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -17,6 +17,8 @@ using Umbraco.Web.WebApi; using Constants = Umbraco.Core.Constants; using Current = Umbraco.Web.Composing.Current; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Runtime { @@ -25,7 +27,7 @@ namespace Umbraco.Web.Runtime private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly SurfaceControllerTypeCollection _surfaceControllerTypes; private readonly UmbracoApiControllerTypeCollection _apiControllerTypes; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; @@ -33,14 +35,14 @@ namespace Umbraco.Web.Runtime IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper) { _umbracoContextAccessor = umbracoContextAccessor; _surfaceControllerTypes = surfaceControllerTypes; _apiControllerTypes = apiControllerTypes; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; } @@ -111,7 +113,7 @@ namespace Umbraco.Web.Runtime // internal for tests internal static void CreateRoutes( IUmbracoContextAccessor umbracoContextAccessor, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IShortStringHelper shortStringHelper, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, @@ -149,7 +151,7 @@ namespace Umbraco.Web.Runtime } private static void RoutePluginControllers( - IGlobalSettings globalSettings, + GlobalSettings globalSettings, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) diff --git a/src/Umbraco.Web/Security/AppBuilderExtensions.cs b/src/Umbraco.Web/Security/AppBuilderExtensions.cs index ac5434aa4e..885baaab79 100644 --- a/src/Umbraco.Web/Security/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/Security/AppBuilderExtensions.cs @@ -8,6 +8,7 @@ using Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.Composing; using Constants = Umbraco.Core.Constants; @@ -34,7 +35,7 @@ namespace Umbraco.Web.Security /// /// By default this will be configured to execute on PipelineStage.Authenticate /// - public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache) + public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache) { return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, hostingEnvironment, requestCache, PipelineStage.Authenticate); } @@ -53,7 +54,7 @@ namespace Umbraco.Web.Security /// public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, - IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage) + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage) { if (app == null) throw new ArgumentNullException(nameof(app)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState)); diff --git a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs index 8a093f1943..beb79d3e98 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs @@ -14,20 +14,20 @@ namespace Umbraco.Web.Security { private readonly IUserService _userService; private readonly IRuntimeState _runtimeState; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly SecuritySettings _securitySettings; public BackOfficeCookieAuthenticationProvider( IUserService userService, IRuntimeState runtimeState, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IOptionsSnapshot securitySettings) { _userService = userService; _runtimeState = runtimeState; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _securitySettings = securitySettings.Value; } diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index da3500fb25..5464902bb3 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -46,7 +46,7 @@ namespace Umbraco.Web.Security IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, UmbracoMapper mapper, UserPasswordConfigurationSettings passwordConfiguration, IIpResolver ipResolver, diff --git a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs index 021adaed97..01ed3ae30e 100644 --- a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs @@ -11,6 +11,7 @@ using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.BackOffice; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Security { @@ -25,7 +26,7 @@ namespace Umbraco.Web.Security private readonly IUserClaimsPrincipalFactory _claimsPrincipalFactory; private readonly IAuthenticationManager _authenticationManager; private readonly ILogger _logger; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IOwinRequest _request; public BackOfficeSignInManager( @@ -33,7 +34,18 @@ namespace Umbraco.Web.Security IUserClaimsPrincipalFactory claimsPrincipalFactory, IAuthenticationManager authenticationManager, ILogger logger, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, + IOwinRequest request) + :this(userManager, claimsPrincipalFactory, authenticationManager, logger, globalSettings.Value, request) + { + } + + public BackOfficeSignInManager( + BackOfficeUserManager userManager, + IUserClaimsPrincipalFactory claimsPrincipalFactory, + IAuthenticationManager authenticationManager, + ILogger logger, + GlobalSettings globalSettings, IOwinRequest request) { _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); @@ -52,7 +64,7 @@ namespace Umbraco.Web.Security return claimsPrincipal.Identity as ClaimsIdentity; } - public static BackOfficeSignInManager Create(IOwinContext context, IGlobalSettings globalSettings, ILogger logger) + public static BackOfficeSignInManager Create(IOwinContext context, GlobalSettings globalSettings, ILogger logger) { var userManager = context.GetBackOfficeUserManager(); diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index 0bf83efd34..e1227a892d 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.Security internal class GetUserSecondsMiddleWare : OwinMiddleware { private readonly UmbracoBackOfficeCookieAuthOptions _authOptions; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly SecuritySettings _securitySettings; private readonly ILogger _logger; private readonly IHostingEnvironment _hostingEnvironment; @@ -32,14 +32,14 @@ namespace Umbraco.Web.Security public GetUserSecondsMiddleWare( OwinMiddleware next, UmbracoBackOfficeCookieAuthOptions authOptions, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IOptionsSnapshot securitySettings, ILogger logger, IHostingEnvironment hostingEnvironment) : base(next) { _authOptions = authOptions ?? throw new ArgumentNullException(nameof(authOptions)); - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _securitySettings = securitySettings.Value; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 1c447b38aa..7eeea5662c 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -9,6 +9,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -44,7 +45,7 @@ namespace Umbraco.Web Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "App_Data\\Logs"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.config"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.user.config")); - var ioHelper = new IOHelper(hostingEnvironment, globalSettings); + var ioHelper = new IOHelper(hostingEnvironment); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration); var configs = configFactory.Create(); @@ -125,7 +126,7 @@ namespace Umbraco.Web /// /// Gets the application register. /// - protected virtual IRegister GetRegister(IGlobalSettings globalSettings) + protected virtual IRegister GetRegister(GlobalSettings globalSettings) { return RegisterFactory.Create(globalSettings); } diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index ae1cf885b3..703f5f9b51 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -2,6 +2,7 @@ using System; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; @@ -17,7 +18,7 @@ namespace Umbraco.Web public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd, IUmbracoContext { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly ICookieManager _cookieManager; private readonly Lazy _publishedSnapshot; @@ -31,7 +32,7 @@ namespace Umbraco.Web internal UmbracoContext(IHttpContextAccessor httpContextAccessor, IPublishedSnapshotService publishedSnapshotService, IWebSecurity webSecurity, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IVariationContextAccessor variationContextAccessor, UriUtility uriUtility, diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index bfb4dd627d..a804e4b3be 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Text; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -20,7 +22,7 @@ namespace Umbraco.Web private readonly IVariationContextAccessor _variationContextAccessor; private readonly IDefaultCultureAccessor _defaultCultureAccessor; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUserService _userService; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; @@ -35,7 +37,7 @@ namespace Umbraco.Web IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IUserService userService, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, @@ -46,7 +48,7 @@ namespace Umbraco.Web _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _defaultCultureAccessor = defaultCultureAccessor ?? throw new ArgumentNullException(nameof(defaultCultureAccessor)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _hostingEnvironment = hostingEnvironment; _uriUtility = uriUtility; diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index a832b4e823..36cf0d5c20 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -1,8 +1,10 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -20,7 +22,7 @@ namespace Umbraco.Web.WebApi { } - protected UmbracoApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoApiController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs index d009528bc7..323f09316f 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs @@ -14,11 +14,11 @@ using Umbraco.Web.Features; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi.Filters; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.WebApi { - - /// /// Provides a base class for Umbraco API controllers. /// @@ -26,7 +26,6 @@ namespace Umbraco.Web.WebApi [FeatureAuthorize] public abstract class UmbracoApiControllerBase : ApiController, IUmbracoFeature { - // note: all Umbraco controllers have two constructors: one with all dependencies, which should be used, // and one with auto dependencies, ie no dependencies - and then dependencies are automatically obtained // here from the Current service locator - this is obviously evil, but it allows us to add new dependencies @@ -38,7 +37,7 @@ namespace Umbraco.Web.WebApi /// Dependencies are obtained from the service locator. protected UmbracoApiControllerBase() : this( - Current.Factory.GetInstance(), + Current.Factory.GetInstance>(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), @@ -53,10 +52,10 @@ namespace Umbraco.Web.WebApi /// /// Initializes a new instance of the class with all its dependencies. /// - protected UmbracoApiControllerBase(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoApiControllerBase(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) { UmbracoContextAccessor = umbracoContextAccessor; - GlobalSettings = globalSettings; + GlobalSettings = globalSettings.Value; SqlContext = sqlContext; Services = services; AppCaches = appCaches; @@ -73,9 +72,9 @@ namespace Umbraco.Web.WebApi internal Guid InstanceId { get; } = Guid.NewGuid(); /// - /// Gets the Umbraco context. + /// Gets the global settings from configuration. /// - public virtual IGlobalSettings GlobalSettings { get; } + public virtual GlobalSettings GlobalSettings { get; } /// /// Gets the Umbraco context. diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 48b3de44fd..1bd9fb8f31 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -8,6 +8,8 @@ using Umbraco.Core.Services; using Umbraco.Web.Security; using Umbraco.Core.Mapping; using Umbraco.Web.Routing; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.WebApi { @@ -35,7 +37,7 @@ namespace Umbraco.Web.WebApi { } - protected UmbracoAuthorizedApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoAuthorizedApiController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs index 9a8da5a7eb..b38c775f67 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs @@ -16,16 +16,16 @@ namespace Umbraco.Web.WebAssets.CDF [ComposeAfter(typeof(WebInitialComponent))] public sealed class ClientDependencyComponent : IComponent { - private readonly IHostingSettings _hostingSettings; + private readonly HostingSettings _hostingSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly RuntimeSettings _runtimeSettings; public ClientDependencyComponent( - IHostingSettings hostingSettings, + IOptionsSnapshot hostingSettings, IHostingEnvironment hostingEnvironment, IOptionsSnapshot runtimeSettings) { - _hostingSettings = hostingSettings; + _hostingSettings = hostingSettings.Value; _hostingEnvironment = hostingEnvironment; _runtimeSettings = runtimeSettings.Value; } From 52a65caf885ed969246ffee043a026032e2a33e6 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Fri, 21 Aug 2020 15:27:06 +0100 Subject: [PATCH 05/58] Temporarily removed test and non netcore executable projects. --- .../AspNetCoreConfigsFactory.cs | 2 -- .../Umbraco.Configuration.csproj | 10 ++++++++++ .../Configuration/Models/ConnectionStrings.cs | 4 +--- src/Umbraco.Core/Routing/PublishedRequest.cs | 13 ++++++++++++- .../Install/InstallHelper.cs | 1 + .../InstallSteps/DatabaseConfigureStep.cs | 2 +- src/Umbraco.Infrastructure/Trees/TreeNode.cs | 7 ++++++- .../WebAssets/RuntimeMinifierExtensions.cs | 3 --- .../Security/BackOfficeSessionIdValidator.cs | 18 ++++++++---------- .../PreviewAuthenticationMiddleware.cs | 7 ++++--- .../Trees/ContentTreeController.cs | 9 +++++---- .../UmbracoCoreServiceCollectionExtensions.cs | 1 + 12 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index ec87be7b3d..d8c36a0046 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -3,8 +3,6 @@ using Umbraco.Configuration.Models; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; -using ConnectionStrings = Umbraco.Configuration.Models.ConnectionStrings; -using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Configuration { diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index a4dac22386..8d7a0e7f01 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -10,15 +10,25 @@ + + + + + + + + + + diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index 9d038ed17c..027adedd09 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.Data.Common; using System.Text.Json.Serialization; -using Umbraco.Core; -using Umbraco.Core.Configuration; -namespace Umbraco.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ConnectionStrings { diff --git a/src/Umbraco.Core/Routing/PublishedRequest.cs b/src/Umbraco.Core/Routing/PublishedRequest.cs index 24bad199a5..7400623a6f 100644 --- a/src/Umbraco.Core/Routing/PublishedRequest.cs +++ b/src/Umbraco.Core/Routing/PublishedRequest.cs @@ -36,10 +36,21 @@ namespace Umbraco.Web.Routing /// The Umbraco context. /// The request Uri. public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IOptionsSnapshot webRoutingSettings, Uri uri = null) + : this(publishedRouter, umbracoContext, webRoutingSettings.Value, uri) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The published router. + /// The Umbraco context. + /// The request Uri. + public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, WebRoutingSettings webRoutingSettings, Uri uri = null) { UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); - _webRoutingSettings = webRoutingSettings.Value; + _webRoutingSettings = webRoutingSettings; Uri = uri ?? umbracoContext.CleanedUmbracoUrl; } diff --git a/src/Umbraco.Infrastructure/Install/InstallHelper.cs b/src/Umbraco.Infrastructure/Install/InstallHelper.cs index b9729f4e1b..a0460c93ba 100644 --- a/src/Umbraco.Infrastructure/Install/InstallHelper.cs +++ b/src/Umbraco.Infrastructure/Install/InstallHelper.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Web.Install.Models; using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Install { diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs index 0691f39e80..b86c1c2233 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs @@ -5,7 +5,7 @@ using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Web.Install.Models; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Microsoft.Extensions.Options; namespace Umbraco.Web.Install.InstallSteps diff --git a/src/Umbraco.Infrastructure/Trees/TreeNode.cs b/src/Umbraco.Infrastructure/Trees/TreeNode.cs index 1b6945bcdd..585929c0e1 100644 --- a/src/Umbraco.Infrastructure/Trees/TreeNode.cs +++ b/src/Umbraco.Infrastructure/Trees/TreeNode.cs @@ -4,6 +4,7 @@ using System.Runtime.Serialization; using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Trees @@ -113,7 +114,11 @@ namespace Umbraco.Web.Models.Trees return Current.IOHelper.ResolveUrl("~" + Icon.TrimStart('~')); //legacy icon path - var backOfficePath = Current.Configs.Global().GetUmbracoMvcArea(Current.HostingEnvironment); + + // TODO: replace this when we have something other than Current.Configs available + //var backOfficePath = Current.Configs.Global().GetUmbracoMvcArea(Current.HostingEnvironment); + var backOfficePath = new GlobalSettings().GetUmbracoMvcArea(Current.HostingEnvironment); + return string.Format("{0}images/umbraco/{1}", backOfficePath.EnsureEndsWith("/"), Icon); } } diff --git a/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs b/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs index 929c7c9dd2..cc3be4d785 100644 --- a/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs +++ b/src/Umbraco.Infrastructure/WebAssets/RuntimeMinifierExtensions.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.WebAssets; namespace Umbraco.Web.WebAssets diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs index fdf630e01c..2b70a1b083 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs @@ -1,16 +1,14 @@  +using System; +using System.Security.Claims; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Extensions; -using System; -using System.Collections.Generic; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Extensions; @@ -37,14 +35,14 @@ namespace Umbraco.Web.BackOffice.Security { public const string CookieName = "UMB_UCONTEXT_C"; private readonly ISystemClock _systemClock; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly BackOfficeUserManager _userManager; - public BackOfficeSessionIdValidator(ISystemClock systemClock, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, BackOfficeUserManager userManager) + public BackOfficeSessionIdValidator(ISystemClock systemClock, IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, BackOfficeUserManager userManager) { _systemClock = systemClock; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _userManager = userManager; } diff --git a/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs b/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs index ff182b9f7b..f48996332c 100644 --- a/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs +++ b/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs @@ -6,6 +6,7 @@ using System; using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Extensions; @@ -16,14 +17,14 @@ namespace Umbraco.Web.BackOffice.Security /// public class PreviewAuthenticationMiddleware : IMiddleware { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; public PreviewAuthenticationMiddleware( - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; } diff --git a/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs index 0cc73af315..2f72e1f829 100644 --- a/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs +++ b/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs @@ -20,6 +20,8 @@ using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Security; using Umbraco.Web.WebApi; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.Trees { @@ -40,7 +42,7 @@ namespace Umbraco.Web.Trees { private readonly UmbracoTreeSearcher _treeSearcher; private readonly ActionCollection _actions; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; private readonly IWebSecurity _webSecurity; private readonly IContentService _contentService; @@ -49,7 +51,6 @@ namespace Umbraco.Web.Trees private readonly IUserService _userService; private readonly ILocalizationService _localizationService; - public ContentTreeController( ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, @@ -62,7 +63,7 @@ namespace Umbraco.Web.Trees IDataTypeService dataTypeService, UmbracoTreeSearcher treeSearcher, ActionCollection actions, - IGlobalSettings globalSettings, + IOptionsSnapshot globalSettings, IContentService contentService, IPublicAccessService publicAccessService, ILocalizationService localizationService) @@ -70,7 +71,7 @@ namespace Umbraco.Web.Trees { _treeSearcher = treeSearcher; _actions = actions; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _menuItemCollectionFactory = menuItemCollectionFactory; _webSecurity = webSecurity; _contentService = contentService; diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index cbdbeac873..1c7f8156f4 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -14,6 +14,7 @@ using Serilog; using Serilog.Extensions.Hosting; using Serilog.Extensions.Logging; using Umbraco.Configuration; +using Umbraco.Configuration.Models; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; From 89b725ef28b5c6b4078f1f56646ad6748fff94c2 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Sun, 23 Aug 2020 13:55:36 +0200 Subject: [PATCH 06/58] Reverted non netcore related project amends in order to limit changes to those necessary for the netcore executable call stack. --- .../AspNetCoreConfigsFactory.cs | 38 +++--- .../Models/ActiveDirectorySettings.cs | 19 +++ .../Models/ConnectionStrings.cs | 69 ++++++++++ .../Models/ContentSettings.cs | 119 ++++++++++++++++++ .../Models/CoreDebugSettings.cs | 23 ++++ .../Models/ExceptionFilterSettings.cs | 19 +++ .../Models/GlobalSettings.cs | 101 +++++++++++++++ .../Models/HostingSettings.cs | 29 +++++ .../Models/ImagingSettings.cs | 26 ++++ .../Models/IndexCreatorSettings.cs | 20 +++ .../Models/KeepAliveSettings.cs | 23 ++++ .../Models/LoggingSettings.cs | 19 +++ .../MemberPasswordConfigurationSettings.cs | 38 ++++++ .../Models/ModelsBuilderConfig.cs | 86 +++++++++++++ .../Models/NuCacheSettings.cs | 19 +++ .../Models/RuntimeSettings.cs | 19 +++ .../Models/SecuritySettings.cs | 33 +++++ .../Models/TourSettings.cs | 21 ++++ .../Models/TypeFinderSettings.cs | 20 +++ .../UserPasswordConfigurationSettings.cs | 36 ++++++ .../Models/WebRoutingSettings.cs | 42 +++++++ .../BackOffice/ContentTypeModelValidator.cs | 5 +- .../ContentTypeModelValidatorBase.cs | 9 +- .../BackOffice/DashboardReport.cs | 5 +- .../BackOffice/MediaTypeModelValidator.cs | 5 +- .../ModelsBuilderDashboardController.cs | 10 +- .../Building/Builder.cs | 3 +- .../Building/ModelsGenerator.cs | 5 +- .../Building/TextBuilder.cs | 4 +- .../Compose/ModelsBuilderComponent.cs | 8 +- .../LiveModelsProvider.cs | 5 +- .../ModelsGenerationError.cs | 5 +- .../OutOfDateModelsStatus.cs | 5 +- .../PureLiveModelFactory.cs | 6 +- src/Umbraco.Tests.Common/SettingsForTests.cs | 38 +++--- src/Umbraco.Tests.Common/TestHelperBase.cs | 5 +- .../Implementations/TestHostingEnvironment.cs | 6 +- .../BackOfficeCookieManagerTests.cs | 10 +- .../Components/ComponentTests.cs | 3 +- src/Umbraco.Tests/Models/MediaXmlTest.cs | 3 +- .../Routing/MediaUrlProviderTests.cs | 7 +- .../BackOfficeOwinUserManagerTests.cs | 10 +- .../TestHelpers/SettingsForTests.cs | 5 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 5 +- .../TestHelpers/TestObjects-Mocks.cs | 4 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 3 +- src/Umbraco.Web/AppBuilderExtensions.cs | 3 +- .../AspNet/AspNetBackOfficeInfo.cs | 13 +- .../AspNet/AspNetHostingEnvironment.cs | 12 +- .../AspNet/AspNetRequestAccessor.cs | 10 +- .../Compose/AuditEventsComponent.cs | 10 +- .../BackOfficeUserAuditEventsComponent.cs | 8 +- .../Editors/AuthenticationController.cs | 39 +++--- .../Editors/BackOfficeController.cs | 25 ++-- .../Editors/BackOfficeServerVariables.cs | 32 ++--- .../UmbracoAuthorizedJsonController.cs | 4 +- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 7 +- .../Mvc/AreaRegistrationExtensions.cs | 6 +- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 13 +- src/Umbraco.Web/Mvc/PluginControllerArea.cs | 13 +- src/Umbraco.Web/Mvc/RenderMvcController.cs | 6 +- .../Mvc/RenderNoContentController.cs | 8 +- .../Mvc/UmbracoAuthorizedController.cs | 6 +- src/Umbraco.Web/Mvc/UmbracoController.cs | 19 ++- .../Mvc/UmbracoViewPageOfTModel.cs | 16 ++- src/Umbraco.Web/RoutableDocumentFilter.cs | 27 ++-- .../Runtime/WebInitialComponent.cs | 12 +- .../Security/AppBuilderExtensions.cs | 5 +- .../BackOfficeCookieAuthenticationProvider.cs | 32 ++--- .../Security/BackOfficeOwinUserManager.cs | 13 +- .../Security/BackOfficeSignInManager.cs | 18 +-- .../Security/GetUserSecondsMiddleWare.cs | 21 ++-- src/Umbraco.Web/UmbracoApplicationBase.cs | 5 +- src/Umbraco.Web/UmbracoContext.cs | 5 +- src/Umbraco.Web/UmbracoContextFactory.cs | 8 +- src/Umbraco.Web/UmbracoDefaultOwinStartup.cs | 8 +- .../WebApi/UmbracoApiController.cs | 4 +- .../WebApi/UmbracoApiControllerBase.cs | 15 +-- .../WebApi/UmbracoAuthorizedApiController.cs | 4 +- .../CDF/ClientDependencyComponent.cs | 18 ++- 80 files changed, 1073 insertions(+), 365 deletions(-) create mode 100644 src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs create mode 100644 src/Umbraco.Configuration/Models/ConnectionStrings.cs create mode 100644 src/Umbraco.Configuration/Models/ContentSettings.cs create mode 100644 src/Umbraco.Configuration/Models/CoreDebugSettings.cs create mode 100644 src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs create mode 100644 src/Umbraco.Configuration/Models/GlobalSettings.cs create mode 100644 src/Umbraco.Configuration/Models/HostingSettings.cs create mode 100644 src/Umbraco.Configuration/Models/ImagingSettings.cs create mode 100644 src/Umbraco.Configuration/Models/IndexCreatorSettings.cs create mode 100644 src/Umbraco.Configuration/Models/KeepAliveSettings.cs create mode 100644 src/Umbraco.Configuration/Models/LoggingSettings.cs create mode 100644 src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs create mode 100644 src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs create mode 100644 src/Umbraco.Configuration/Models/NuCacheSettings.cs create mode 100644 src/Umbraco.Configuration/Models/RuntimeSettings.cs create mode 100644 src/Umbraco.Configuration/Models/SecuritySettings.cs create mode 100644 src/Umbraco.Configuration/Models/TourSettings.cs create mode 100644 src/Umbraco.Configuration/Models/TypeFinderSettings.cs create mode 100644 src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs create mode 100644 src/Umbraco.Configuration/Models/WebRoutingSettings.cs diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index d8c36a0046..d8b5e666b9 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -19,27 +19,27 @@ namespace Umbraco.Configuration { var configs = new Configs(); - //configs.Add(() => new TourSettings(_configuration)); - //configs.Add(() => new CoreDebugSettings(_configuration)); + configs.Add(() => new TourSettings(_configuration)); + configs.Add(() => new CoreDebugSettings(_configuration)); configs.Add(() => new RequestHandlerSettings(_configuration)); - //configs.Add(() => new SecuritySettings(_configuration)); - //configs.Add(() => new UserPasswordConfigurationSettings(_configuration)); - //configs.Add(() => new MemberPasswordConfigurationSettings(_configuration)); - //configs.Add(() => new KeepAliveSettings(_configuration)); - //configs.Add(() => new ContentSettings(_configuration)); + configs.Add(() => new SecuritySettings(_configuration)); + configs.Add(() => new UserPasswordConfigurationSettings(_configuration)); + configs.Add(() => new MemberPasswordConfigurationSettings(_configuration)); + configs.Add(() => new KeepAliveSettings(_configuration)); + configs.Add(() => new ContentSettings(_configuration)); configs.Add(() => new HealthChecksSettings(_configuration)); - //configs.Add(() => new LoggingSettings(_configuration)); - //configs.Add(() => new ExceptionFilterSettings(_configuration)); - //configs.Add(() => new ActiveDirectorySettings(_configuration)); - //configs.Add(() => new RuntimeSettings(_configuration)); - //configs.Add(() => new TypeFinderSettings(_configuration)); - //configs.Add(() => new NuCacheSettings(_configuration)); - //configs.Add(() => new WebRoutingSettings(_configuration)); - //configs.Add(() => new IndexCreatorSettings(_configuration)); - //configs.Add(() => new ModelsBuilderConfig(_configuration)); - //configs.Add(() => new HostingSettings(_configuration)); - //configs.Add(() => new GlobalSettings(_configuration)); - //configs.Add(() => new ImagingSettings(_configuration)); + configs.Add(() => new LoggingSettings(_configuration)); + configs.Add(() => new ExceptionFilterSettings(_configuration)); + configs.Add(() => new ActiveDirectorySettings(_configuration)); + configs.Add(() => new RuntimeSettings(_configuration)); + configs.Add(() => new TypeFinderSettings(_configuration)); + configs.Add(() => new NuCacheSettings(_configuration)); + configs.Add(() => new WebRoutingSettings(_configuration)); + configs.Add(() => new IndexCreatorSettings(_configuration)); + configs.Add(() => new ModelsBuilderConfig(_configuration)); + configs.Add(() => new HostingSettings(_configuration)); + configs.Add(() => new GlobalSettings(_configuration)); + configs.Add(() => new ImagingSettings(_configuration)); return configs; } diff --git a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs new file mode 100644 index 0000000000..015fb17a8e --- /dev/null +++ b/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class ActiveDirectorySettings : IActiveDirectorySettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "ActiveDirectory:"; + private readonly IConfiguration _configuration; + + public ActiveDirectorySettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string ActiveDirectoryDomain => _configuration.GetValue(Prefix+"Domain"); + } +} diff --git a/src/Umbraco.Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Configuration/Models/ConnectionStrings.cs new file mode 100644 index 0000000000..586765714c --- /dev/null +++ b/src/Umbraco.Configuration/Models/ConnectionStrings.cs @@ -0,0 +1,69 @@ +using System; +using System.Data.Common; +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + public class ConnectionStrings : IConnectionStrings + { + private readonly IConfiguration _configuration; + + public ConnectionStrings(IConfiguration configuration) + { + _configuration = configuration; + } + + public ConfigConnectionString this[string key] + { + get + { + var connectionString = _configuration.GetConnectionString(key); + var provider = ParseProvider(connectionString); + return new ConfigConnectionString(connectionString, provider, key); + } + set => throw new NotImplementedException(); + } + + private string ParseProvider(string connectionString) + { + if (string.IsNullOrEmpty(connectionString)) + { + return null; + } + + var builder = new DbConnectionStringBuilder(); + + builder.ConnectionString = connectionString; + + if (builder.TryGetValue("Data Source", out var ds) && ds is string dataSource) + { + if (dataSource.EndsWith(".sdf")) + { + return Constants.DbProviderNames.SqlCe; + } + } + + if (builder.TryGetValue("Server", out var s) && s is string server && !string.IsNullOrEmpty(server)) + { + if (builder.TryGetValue("Database", out var db) && db is string database && !string.IsNullOrEmpty(database)) + { + return Constants.DbProviderNames.SqlServer; + } + + if (builder.TryGetValue("AttachDbFileName", out var a) && a is string attachDbFileName && !string.IsNullOrEmpty(attachDbFileName)) + { + return Constants.DbProviderNames.SqlServer; + } + + if (builder.TryGetValue("Initial Catalog", out var i) && i is string initialCatalog && !string.IsNullOrEmpty(initialCatalog)) + { + return Constants.DbProviderNames.SqlServer; + } + } + + throw new ArgumentException("Cannot determine provider name from connection string", nameof(connectionString)); + } + } +} diff --git a/src/Umbraco.Configuration/Models/ContentSettings.cs b/src/Umbraco.Configuration/Models/ContentSettings.cs new file mode 100644 index 0000000000..6c9b986dd1 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ContentSettings.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Macros; + +namespace Umbraco.Configuration.Models +{ + internal class ContentSettings : IContentSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Content:"; + private const string NotificationsPrefix = Prefix + "Notifications:"; + private const string ImagingPrefix = Prefix + "Imaging:"; + private const string DefaultPreviewBadge = + @"
Preview modeClick to end
"; + + private static readonly ImagingAutoFillUploadField[] DefaultImagingAutoFillUploadField = + { + new ImagingAutoFillUploadField + { + Alias = Constants.Conventions.Media.File, + WidthFieldAlias = Constants.Conventions.Media.Width, + HeightFieldAlias =Constants.Conventions.Media.Height, + ExtensionFieldAlias =Constants.Conventions.Media.Extension, + LengthFieldAlias =Constants.Conventions.Media.Bytes, + } + }; + + private readonly IConfiguration _configuration; + + public ContentSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string NotificationEmailAddress => + _configuration.GetValue(NotificationsPrefix+"Email"); + + public bool DisableHtmlEmail => + _configuration.GetValue(NotificationsPrefix+"DisableHtmlEmail", false); + + public IEnumerable ImageFileTypes => _configuration.GetValue( + ImagingPrefix+"ImageFileTypes", new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }); + + public IEnumerable ImageAutoFillProperties => + _configuration.GetValue(ImagingPrefix+"AutoFillImageProperties", + DefaultImagingAutoFillUploadField); + + + public bool ResolveUrlsFromTextString => + _configuration.GetValue(Prefix+"ResolveUrlsFromTextString", false); + + public IEnumerable Error404Collection => _configuration + .GetSection(Prefix+"Errors:Error404") + .GetChildren() + .Select(x => new ContentErrorPage(x)); + + public string PreviewBadge => _configuration.GetValue(Prefix+"PreviewBadge", DefaultPreviewBadge); + + public MacroErrorBehaviour MacroErrorBehaviour => + _configuration.GetValue(Prefix+"MacroErrors", MacroErrorBehaviour.Inline); + + public IEnumerable DisallowedUploadFiles => _configuration.GetValue( + Prefix+"DisallowedUploadFiles", + new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }); + + public IEnumerable AllowedUploadFiles => + _configuration.GetValue(Prefix+"AllowedUploadFiles", Array.Empty()); + + public bool ShowDeprecatedPropertyEditors => + _configuration.GetValue(Prefix+"ShowDeprecatedPropertyEditors", false); + + public string LoginBackgroundImage => + _configuration.GetValue(Prefix+"LoginBackgroundImage", "assets/img/login.jpg"); + + private class ContentErrorPage : IContentErrorPage + { + public ContentErrorPage(IConfigurationSection configurationSection) + { + Culture = configurationSection.Key; + + var value = configurationSection.Value; + + if (int.TryParse(value, out var contentId)) + { + HasContentId = true; + ContentId = contentId; + } + else if (Guid.TryParse(value, out var contentKey)) + { + HasContentKey = true; + ContentKey = contentKey; + } + else + { + ContentXPath = value; + } + } + + public int ContentId { get; } + public Guid ContentKey { get; } + public string ContentXPath { get; } + public bool HasContentId { get; } + public bool HasContentKey { get; } + public string Culture { get; set; } + } + + private class ImagingAutoFillUploadField : IImagingAutoFillUploadField + { + public string Alias { get; set; } + public string WidthFieldAlias { get; set; } + public string HeightFieldAlias { get; set; } + public string LengthFieldAlias { get; set; } + public string ExtensionFieldAlias { get; set; } + } + } +} diff --git a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs b/src/Umbraco.Configuration/Models/CoreDebugSettings.cs new file mode 100644 index 0000000000..6d6c0eaf0d --- /dev/null +++ b/src/Umbraco.Configuration/Models/CoreDebugSettings.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class CoreDebugSettings : ICoreDebugSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Core:Debug:"; + private readonly IConfiguration _configuration; + + public CoreDebugSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public bool LogUncompletedScopes => + _configuration.GetValue(Prefix+"LogUncompletedScopes", false); + + public bool DumpOnTimeoutThreadAbort => + _configuration.GetValue(Prefix+"DumpOnTimeoutThreadAbort", false); + } +} diff --git a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs b/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs new file mode 100644 index 0000000000..581daf9f40 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class ExceptionFilterSettings : IExceptionFilterSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "ExceptionFilter:"; + private readonly IConfiguration _configuration; + + public ExceptionFilterSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public bool Disabled => _configuration.GetValue(Prefix+"Disabled", false); + } +} diff --git a/src/Umbraco.Configuration/Models/GlobalSettings.cs b/src/Umbraco.Configuration/Models/GlobalSettings.cs new file mode 100644 index 0000000000..908ba71590 --- /dev/null +++ b/src/Umbraco.Configuration/Models/GlobalSettings.cs @@ -0,0 +1,101 @@ +using System; +using System.Linq; +using System.Net.Mail; +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + /// + /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information + /// from web.config appsettings + /// + internal class GlobalSettings : IGlobalSettings + { + private const string Prefix = Constants.Configuration.ConfigGlobalPrefix; + + 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! + + private readonly IConfiguration _configuration; + + public GlobalSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string ReservedUrls => _configuration.GetValue(Prefix + "ReservedUrls", StaticReservedUrls); + public string ReservedPaths => _configuration.GetValue(Prefix + "ReservedPaths", StaticReservedPaths); + + // TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings + public string ConfigurationStatus + { + get => _configuration.GetValue(Prefix + "ConfigurationStatus"); + set => throw new NotImplementedException("We should remove this and only use the value from database"); + } + + public int TimeOutInMinutes => _configuration.GetValue(Prefix + "TimeOutInMinutes", 20); + public string DefaultUILanguage => _configuration.GetValue(Prefix + "DefaultUILanguage", "en-US"); + + public bool HideTopLevelNodeFromPath => + _configuration.GetValue(Prefix + "HideTopLevelNodeFromPath", false); + + public bool UseHttps => _configuration.GetValue(Prefix + "UseHttps", false); + public int VersionCheckPeriod => _configuration.GetValue(Prefix + "VersionCheckPeriod", 7); + public string UmbracoPath => _configuration.GetValue(Prefix + "UmbracoPath", "~/umbraco"); + public string UmbracoCssPath => _configuration.GetValue(Prefix + "UmbracoCssPath", "~/css"); + + public string UmbracoScriptsPath => + _configuration.GetValue(Prefix + "UmbracoScriptsPath", "~/scripts"); + + public string UmbracoMediaPath => _configuration.GetValue(Prefix + "UmbracoMediaPath", "~/media"); + + public bool InstallMissingDatabase => + _configuration.GetValue(Prefix + "InstallMissingDatabase", false); + + public bool InstallEmptyDatabase => _configuration.GetValue(Prefix + "InstallEmptyDatabase", false); + + public bool DisableElectionForSingleServer => + _configuration.GetValue(Prefix + "DisableElectionForSingleServer", false); + + public string RegisterType => _configuration.GetValue(Prefix + "RegisterType", string.Empty); + + public string DatabaseFactoryServerVersion => + _configuration.GetValue(Prefix + "DatabaseFactoryServerVersion", string.Empty); + + public string MainDomLock => _configuration.GetValue(Prefix + "MainDomLock", string.Empty); + + public string NoNodesViewPath => + _configuration.GetValue(Prefix + "NoNodesViewPath", "~/config/splashes/NoNodes.cshtml"); + + public bool IsSmtpServerConfigured => + _configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")?.GetChildren().Any() ?? false; + + public ISmtpSettings SmtpSettings => + new SmtpSettingsImpl(_configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")); + + private class SmtpSettingsImpl : ISmtpSettings + { + private readonly IConfigurationSection _configurationSection; + + public SmtpSettingsImpl(IConfigurationSection configurationSection) + { + _configurationSection = configurationSection; + } + + public string From => _configurationSection.GetValue("From"); + public string Host => _configurationSection.GetValue("Host"); + public int Port => _configurationSection.GetValue("Port"); + public string PickupDirectoryLocation => _configurationSection.GetValue("PickupDirectoryLocation"); + public SmtpDeliveryMethod DeliveryMethod => _configurationSection.GetValue("DeliveryMethod"); + + public string Username => _configurationSection.GetValue("Username"); + + public string Password => _configurationSection.GetValue("Password"); + } + } +} diff --git a/src/Umbraco.Configuration/Models/HostingSettings.cs b/src/Umbraco.Configuration/Models/HostingSettings.cs new file mode 100644 index 0000000000..f0fbcf4cab --- /dev/null +++ b/src/Umbraco.Configuration/Models/HostingSettings.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class HostingSettings : IHostingSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Hosting:"; + private readonly IConfiguration _configuration; + + public HostingSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + /// + public LocalTempStorage LocalTempStorageLocation => + _configuration.GetValue(Prefix+"LocalTempStorage", LocalTempStorage.Default); + + public string ApplicationVirtualPath => null; + + /// + /// Gets a value indicating whether umbraco is running in [debug mode]. + /// + /// true if [debug mode]; otherwise, false. + public bool DebugMode => _configuration.GetValue(Prefix+"Debug", false); + } +} diff --git a/src/Umbraco.Configuration/Models/ImagingSettings.cs b/src/Umbraco.Configuration/Models/ImagingSettings.cs new file mode 100644 index 0000000000..4a9501b2ba --- /dev/null +++ b/src/Umbraco.Configuration/Models/ImagingSettings.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class ImagingSettings : IImagingSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Imaging:"; + private const string CachePrefix = Prefix + "Cache:"; + private const string ResizePrefix = Prefix + "Resize:"; + private readonly IConfiguration _configuration; + + public ImagingSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public int MaxBrowserCacheDays => _configuration.GetValue(CachePrefix + "MaxBrowserCacheDays", 7); + public int MaxCacheDays => _configuration.GetValue(CachePrefix + "MaxCacheDays", 365); + public uint CachedNameLength => _configuration.GetValue(CachePrefix + "CachedNameLength", (uint) 8); + public string CacheFolder => _configuration.GetValue(CachePrefix + "Folder", "../App_Data/Cache"); + public int MaxResizeWidth => _configuration.GetValue(ResizePrefix + "MaxWidth", 5000); + public int MaxResizeHeight => _configuration.GetValue(ResizePrefix + "MaxHeight", 5000); + } +} diff --git a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs b/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs new file mode 100644 index 0000000000..b4bb000552 --- /dev/null +++ b/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class IndexCreatorSettings : IIndexCreatorSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Examine:"; + private readonly IConfiguration _configuration; + + public IndexCreatorSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string LuceneDirectoryFactory => + _configuration.GetValue(Prefix + "LuceneDirectoryFactory"); + } +} diff --git a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs b/src/Umbraco.Configuration/Models/KeepAliveSettings.cs new file mode 100644 index 0000000000..04194e1a3c --- /dev/null +++ b/src/Umbraco.Configuration/Models/KeepAliveSettings.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Configuration.Models +{ + internal class KeepAliveSettings : IKeepAliveSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "KeepAlive:"; + private readonly IConfiguration _configuration; + + public KeepAliveSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public bool DisableKeepAliveTask => + _configuration.GetValue(Prefix + "DisableKeepAliveTask", false); + + public string KeepAlivePingUrl => _configuration.GetValue(Prefix + "KeepAlivePingUrl", + "{umbracoApplicationUrl}/api/keepalive/ping"); + } +} diff --git a/src/Umbraco.Configuration/Models/LoggingSettings.cs b/src/Umbraco.Configuration/Models/LoggingSettings.cs new file mode 100644 index 0000000000..b05fe03875 --- /dev/null +++ b/src/Umbraco.Configuration/Models/LoggingSettings.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Configuration.Models +{ + internal class LoggingSettings : ILoggingSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Logging:"; + private readonly IConfiguration _configuration; + + public LoggingSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public int MaxLogAge => _configuration.GetValue(Prefix + "MaxLogAge", -1); + } +} diff --git a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs new file mode 100644 index 0000000000..5a8313a351 --- /dev/null +++ b/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class MemberPasswordConfigurationSettings : IMemberPasswordConfiguration + { + private const string Prefix = Constants.Configuration.ConfigSecurityPrefix + "MemberPassword:"; + private readonly IConfiguration _configuration; + + public MemberPasswordConfigurationSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public int RequiredLength => + _configuration.GetValue(Prefix + "RequiredLength", 10); + + public bool RequireNonLetterOrDigit => + _configuration.GetValue(Prefix + "RequireNonLetterOrDigit", false); + + public bool RequireDigit => + _configuration.GetValue(Prefix + "RequireDigit", false); + + public bool RequireLowercase => + _configuration.GetValue(Prefix + "RequireLowercase", false); + + public bool RequireUppercase => + _configuration.GetValue(Prefix + "RequireUppercase", false); + + public string HashAlgorithmType => + _configuration.GetValue(Prefix + "HashAlgorithmType", Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName); // TODO: Need to change to current format when we do members + + public int MaxFailedAccessAttemptsBeforeLockout => + _configuration.GetValue(Prefix + "MaxFailedAccessAttemptsBeforeLockout", 5); + } +} diff --git a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs b/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs new file mode 100644 index 0000000000..d111dbba70 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + /// + /// Represents the models builder configuration. + /// + internal class ModelsBuilderConfig : IModelsBuilderConfig + { + private const string Prefix = Constants.Configuration.ConfigModelsBuilderPrefix; + private readonly IConfiguration _configuration; + + /// + /// Initializes a new instance of the class. + /// + public ModelsBuilderConfig(IConfiguration configuration) + { + _configuration = configuration; + } + + public string DefaultModelsDirectory => "~/App_Data/Models"; + + /// + /// Gets a value indicating whether the whole models experience is enabled. + /// + /// + /// If this is false then absolutely nothing happens. + /// Default value is false which means that unless we have this setting, nothing happens. + /// + public bool Enable => _configuration.GetValue(Prefix+"Enable", false); + + /// + /// Gets the models mode. + /// + public ModelsMode ModelsMode => + _configuration.GetValue(Prefix+"ModelsMode", ModelsMode.Nothing); + + /// + /// Gets the models namespace. + /// + /// That value could be overriden by other (attribute in user's code...). Return default if no value was supplied. + public string ModelsNamespace => _configuration.GetValue(Prefix+"ModelsNamespace"); + + /// + /// Gets a value indicating whether we should enable the models factory. + /// + /// Default value is true because no factory is enabled by default in Umbraco. + public bool EnableFactory => _configuration.GetValue(Prefix+"EnableFactory", true); + + /// + /// Gets a value indicating whether we should flag out-of-date models. + /// + /// + /// Models become out-of-date when data types or content types are updated. When this + /// setting is activated the ~/App_Data/Models/ood.txt file is then created. When models are + /// generated through the dashboard, the files is cleared. Default value is false. + /// + public bool FlagOutOfDateModels => + _configuration.GetValue(Prefix+"FlagOutOfDateModels", false) && !ModelsMode.IsLive(); + + /// + /// Gets the models directory. + /// + /// Default is ~/App_Data/Models but that can be changed. + public string ModelsDirectory => + _configuration.GetValue(Prefix+"ModelsDirectory", "~/App_Data/Models"); + + /// + /// Gets a value indicating whether to accept an unsafe value for ModelsDirectory. + /// + /// + /// An unsafe value is an absolute path, or a relative path pointing outside + /// of the website root. + /// + public bool AcceptUnsafeModelsDirectory => + _configuration.GetValue(Prefix+"AcceptUnsafeModelsDirectory", false); + + /// + /// Gets a value indicating the debug log level. + /// + /// 0 means minimal (safe on live site), anything else means more and more details (maybe not safe). + public int DebugLevel => _configuration.GetValue(Prefix+"DebugLevel", 0); + } +} diff --git a/src/Umbraco.Configuration/Models/NuCacheSettings.cs b/src/Umbraco.Configuration/Models/NuCacheSettings.cs new file mode 100644 index 0000000000..51b8b1fe08 --- /dev/null +++ b/src/Umbraco.Configuration/Models/NuCacheSettings.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class NuCacheSettings : INuCacheSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "NuCache:"; + private readonly IConfiguration _configuration; + + public NuCacheSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string BTreeBlockSize => _configuration.GetValue(Prefix+"BTreeBlockSize"); + } +} diff --git a/src/Umbraco.Configuration/Models/RuntimeSettings.cs b/src/Umbraco.Configuration/Models/RuntimeSettings.cs new file mode 100644 index 0000000000..ef129030b6 --- /dev/null +++ b/src/Umbraco.Configuration/Models/RuntimeSettings.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class RuntimeSettings : IRuntimeSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Runtime:"; + private readonly IConfiguration _configuration; + public RuntimeSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public int? MaxQueryStringLength => _configuration.GetValue(Prefix+"MaxRequestLength"); + public int? MaxRequestLength => _configuration.GetValue(Prefix+"MaxRequestLength"); + } +} diff --git a/src/Umbraco.Configuration/Models/SecuritySettings.cs b/src/Umbraco.Configuration/Models/SecuritySettings.cs new file mode 100644 index 0000000000..297c95b1af --- /dev/null +++ b/src/Umbraco.Configuration/Models/SecuritySettings.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Configuration.Models +{ + internal class SecuritySettings : ISecuritySettings + { + private const string Prefix = Constants.Configuration.ConfigSecurityPrefix; + private readonly IConfiguration _configuration; + + public SecuritySettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public bool KeepUserLoggedIn => _configuration.GetValue(Prefix + "KeepUserLoggedIn", false); + + public bool HideDisabledUsersInBackoffice => + _configuration.GetValue(Prefix + "HideDisabledUsersInBackoffice", false); + + public bool AllowPasswordReset => + _configuration.GetValue(Prefix + "AllowPasswordResetAllowPasswordReset", true); + + public string AuthCookieName => + _configuration.GetValue(Prefix + "AuthCookieName", "UMB_UCONTEXT"); + + public string AuthCookieDomain => + _configuration.GetValue(Prefix + "AuthCookieDomain"); + + public bool UsernameIsEmail => _configuration.GetValue(Prefix + "UsernameIsEmail", true); + } +} diff --git a/src/Umbraco.Configuration/Models/TourSettings.cs b/src/Umbraco.Configuration/Models/TourSettings.cs new file mode 100644 index 0000000000..9fe1814ff5 --- /dev/null +++ b/src/Umbraco.Configuration/Models/TourSettings.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Configuration.Models +{ + internal class TourSettings : ITourSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "Tours:"; + private readonly IConfiguration _configuration; + + public TourSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string Type { get; set; } + + public bool EnableTours => _configuration.GetValue(Prefix+"EnableTours", true); + } +} diff --git a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs b/src/Umbraco.Configuration/Models/TypeFinderSettings.cs new file mode 100644 index 0000000000..8a1f7ac9e0 --- /dev/null +++ b/src/Umbraco.Configuration/Models/TypeFinderSettings.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class TypeFinderSettings : ITypeFinderSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "TypeFinder:"; + private readonly IConfiguration _configuration; + + public TypeFinderSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public string AssembliesAcceptingLoadExceptions => + _configuration.GetValue(Prefix+"AssembliesAcceptingLoadExceptions"); + } +} diff --git a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs new file mode 100644 index 0000000000..25ce3e3d9a --- /dev/null +++ b/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + internal class UserPasswordConfigurationSettings : IUserPasswordConfiguration + { + private const string Prefix = Constants.Configuration.ConfigSecurityPrefix + "UserPassword:"; + private readonly IConfiguration _configuration; + + public UserPasswordConfigurationSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public int RequiredLength => _configuration.GetValue(Prefix + "RequiredLength", 10); + + public bool RequireNonLetterOrDigit => + _configuration.GetValue(Prefix + "RequireNonLetterOrDigit", false); + + public bool RequireDigit => _configuration.GetValue(Prefix + "RequireDigit", false); + + public bool RequireLowercase => + _configuration.GetValue(Prefix + "RequireLowercase", false); + + public bool RequireUppercase => + _configuration.GetValue(Prefix + "RequireUppercase", false); + + public string HashAlgorithmType => + _configuration.GetValue(Prefix + "HashAlgorithmType", Constants.Security.AspNetCoreV3PasswordHashAlgorithmName); + + public int MaxFailedAccessAttemptsBeforeLockout => + _configuration.GetValue(Prefix + "MaxFailedAccessAttemptsBeforeLockout", 5); + } +} diff --git a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs b/src/Umbraco.Configuration/Models/WebRoutingSettings.cs new file mode 100644 index 0000000000..9ac856ca9f --- /dev/null +++ b/src/Umbraco.Configuration/Models/WebRoutingSettings.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Configuration.Models +{ + internal class WebRoutingSettings : IWebRoutingSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "WebRouting:"; + private readonly IConfiguration _configuration; + + public WebRoutingSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public bool TrySkipIisCustomErrors => + _configuration.GetValue(Prefix + "TrySkipIisCustomErrors", false); + + public bool InternalRedirectPreservesTemplate => + _configuration.GetValue(Prefix + "InternalRedirectPreservesTemplate", false); + + public bool DisableAlternativeTemplates => + _configuration.GetValue(Prefix + "DisableAlternativeTemplates", false); + + public bool ValidateAlternativeTemplates => + _configuration.GetValue(Prefix + "ValidateAlternativeTemplates", false); + + public bool DisableFindContentByIdPath => + _configuration.GetValue(Prefix + "DisableFindContentByIdPath", false); + + public bool DisableRedirectUrlTracking => + _configuration.GetValue(Prefix + "DisableRedirectUrlTracking", false); + + public string UrlProviderMode => + _configuration.GetValue(Prefix + "UrlProviderMode", UrlMode.Auto.ToString()); + + public string UmbracoApplicationUrl => + _configuration.GetValue(Prefix + "UmbracoApplicationUrl"); + } +} diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs index 1da5e44a77..75affe09e7 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -11,7 +10,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class ContentTypeModelValidator : ContentTypeModelValidatorBase { - public ContentTypeModelValidator(IOptionsSnapshot config) : base(config) + public ContentTypeModelValidator(IModelsBuilderConfig config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs index dc78b31abd..1e96e64df8 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs @@ -1,9 +1,8 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration; using Umbraco.Core; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Editors; using Umbraco.Web.Models.ContentEditing; @@ -14,11 +13,11 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice where TModel : ContentTypeSave where TProperty : PropertyTypeBasic { - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; - public ContentTypeModelValidatorBase(IOptionsSnapshot config) + public ContentTypeModelValidatorBase(IModelsBuilderConfig config) { - _config = config.Value; + _config = config; } protected override IEnumerable Validate(TModel model) diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs index 9dc4d8bfb4..6e22313474 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs @@ -1,17 +1,16 @@ using System.Text; using Umbraco.Configuration; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.BackOffice { internal class DashboardReport { - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly ModelsGenerationError _mbErrors; - public DashboardReport(ModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) + public DashboardReport(IModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { _config = config; _outOfDateModels = outOfDateModels; diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs index fc03c24704..fcd42908e7 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -11,7 +10,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class MediaTypeModelValidator : ContentTypeModelValidatorBase { - public MediaTypeModelValidator(IOptionsSnapshot config) : base(config) + public MediaTypeModelValidator(IModelsBuilderConfig config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs index 92f42121e2..17b694de56 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs @@ -3,10 +3,8 @@ using System.Net; using System.Net.Http; using System.Runtime.Serialization; using System.Web.Hosting; -using Microsoft.Extensions.Options; using Umbraco.Configuration; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Exceptions; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Web.Editors; @@ -25,20 +23,20 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice [UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)] public class ModelsBuilderDashboardController : UmbracoAuthorizedJsonController { - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly ModelsGenerator _modelGenerator; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly ModelsGenerationError _mbErrors; private readonly DashboardReport _dashboardReport; - public ModelsBuilderDashboardController(IOptionsSnapshot config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) + public ModelsBuilderDashboardController(IModelsBuilderConfig config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { //_umbracoServices = umbracoServices; - _config = config.Value; + _config = config; _modelGenerator = modelsGenerator; _outOfDateModels = outOfDateModels; _mbErrors = mbErrors; - _dashboardReport = new DashboardReport(_config, outOfDateModels, mbErrors); + _dashboardReport = new DashboardReport(config, outOfDateModels, mbErrors); } // invoked by the dashboard diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs index c053f94649..f64e5ed1ce 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -71,7 +70,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building /// /// The list of models to generate. /// The models namespace. - protected Builder(ModelsBuilderConfig config, IList typeModels) + protected Builder(IModelsBuilderConfig config, IList typeModels) { _typeModels = typeModels ?? throw new ArgumentNullException(nameof(typeModels)); diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs index 29da569102..648a2e76fa 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs @@ -1,7 +1,6 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded.Building @@ -9,11 +8,11 @@ namespace Umbraco.ModelsBuilder.Embedded.Building public class ModelsGenerator { private readonly UmbracoServices _umbracoService; - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly IIOHelper _ioHelper; - public ModelsGenerator(UmbracoServices umbracoService, ModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) + public ModelsGenerator(UmbracoServices umbracoService, IModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) { _umbracoService = umbracoService; _config = config; diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs index 6caca6c8ab..723ee10f35 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -17,7 +17,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building /// and the result of code parsing. /// /// The list of models to generate. - public TextBuilder(ModelsBuilderConfig config, IList typeModels) + public TextBuilder(IModelsBuilderConfig config, IList typeModels) : base(config, typeModels) { } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs index a794f45616..32cfd3057e 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs @@ -15,21 +15,19 @@ using Umbraco.ModelsBuilder.Embedded.BackOffice; using Umbraco.Web; using Umbraco.Web.Mvc; using Umbraco.Web.WebAssets; -using Umbraco.Core.Configuration.Models; -using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded.Compose { internal class ModelsBuilderComponent : IComponent { - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly IShortStringHelper _shortStringHelper; private readonly LiveModelsProvider _liveModelsProvider; private readonly OutOfDateModelsStatus _outOfDateModels; - public ModelsBuilderComponent(IOptionsSnapshot config, IShortStringHelper shortStringHelper, LiveModelsProvider liveModelsProvider, OutOfDateModelsStatus outOfDateModels) + public ModelsBuilderComponent(IModelsBuilderConfig config, IShortStringHelper shortStringHelper, LiveModelsProvider liveModelsProvider, OutOfDateModelsStatus outOfDateModels) { - _config = config.Value; + _config = config; _shortStringHelper = shortStringHelper; _liveModelsProvider = liveModelsProvider; _outOfDateModels = outOfDateModels; diff --git a/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs b/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs index e1ba236839..61d39cd373 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs @@ -6,7 +6,6 @@ using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Web.Cache; -using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded { @@ -16,7 +15,7 @@ namespace Umbraco.ModelsBuilder.Embedded private static Mutex _mutex; private static int _req; private readonly ILogger _logger; - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly ModelsGenerator _modelGenerator; private readonly ModelsGenerationError _mbErrors; private readonly IHostingEnvironment _hostingEnvironment; @@ -24,7 +23,7 @@ namespace Umbraco.ModelsBuilder.Embedded // we do not manage pure live here internal bool IsEnabled => _config.ModelsMode.IsLiveNotPure(); - public LiveModelsProvider(ILogger logger, ModelsBuilderConfig config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IHostingEnvironment hostingEnvironment) + public LiveModelsProvider(ILogger logger, IModelsBuilderConfig config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IHostingEnvironment hostingEnvironment) { _logger = logger; _config = config ?? throw new ArgumentNullException(nameof(config)); diff --git a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs index 0181701f1f..f8f6e8c7bc 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs @@ -2,17 +2,16 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded { public sealed class ModelsGenerationError { - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public ModelsGenerationError(ModelsBuilderConfig config, IIOHelper ioHelper) + public ModelsGenerationError(IModelsBuilderConfig config, IIOHelper ioHelper) { _config = config; _ioHelper = ioHelper; diff --git a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs index 4fb23ad5b3..b8105eeef2 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs @@ -1,6 +1,5 @@ using System.IO; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Cache; @@ -8,10 +7,10 @@ namespace Umbraco.ModelsBuilder.Embedded { public sealed class OutOfDateModelsStatus { - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public OutOfDateModelsStatus(ModelsBuilderConfig config, IIOHelper ioHelper) + public OutOfDateModelsStatus(IModelsBuilderConfig config, IIOHelper ioHelper) { _config = config; _ioHelper = ioHelper; diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index 6e5ba18888..7809d2bf48 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -19,8 +19,6 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; using File = System.IO.File; -using Umbraco.Core.Configuration.Models; -using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded { @@ -43,7 +41,7 @@ namespace Umbraco.ModelsBuilder.Embedded private const string ProjVirt = "~/App_Data/Models/all.generated.cs"; private static readonly string[] OurFiles = { "models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err" }; - private readonly ModelsBuilderConfig _config; + private readonly IModelsBuilderConfig _config; private readonly IApplicationShutdownRegistry _hostingLifetime; private readonly IIOHelper _ioHelper; private readonly ModelsGenerationError _errors; @@ -51,7 +49,7 @@ namespace Umbraco.ModelsBuilder.Embedded public PureLiveModelFactory( Lazy umbracoServices, IProfilingLogger logger, - IOptionsSnapshot config, + IModelsBuilderConfig config, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IIOHelper ioHelper) diff --git a/src/Umbraco.Tests.Common/SettingsForTests.cs b/src/Umbraco.Tests.Common/SettingsForTests.cs index e60f6ad0a4..1a14dc6bc1 100644 --- a/src/Umbraco.Tests.Common/SettingsForTests.cs +++ b/src/Umbraco.Tests.Common/SettingsForTests.cs @@ -3,7 +3,7 @@ using Moq; using Semver; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration.Legacy; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; @@ -16,23 +16,25 @@ namespace Umbraco.Tests.Common { } - public GlobalSettings GenerateStubGlobalSettings(IUmbracoVersion umbVersion = null) + public IGlobalSettings GenerateMockGlobalSettings(IUmbracoVersion umbVersion = null) { var semanticVersion = umbVersion?.SemanticVersion ?? new SemVersion(9); - var config = new GlobalSettings - { - UseHttps = false, - HideTopLevelNodeFromPath = false, - TimeOutInMinutes = 20, - DefaultUILanguage = "en", - ReservedPaths = (GlobalSettings.StaticReservedPaths + "~/umbraco"), - ReservedUrls = GlobalSettings.StaticReservedUrls, - UmbracoPath = "~/umbraco", - UmbracoMediaPath = "~/media", - UmbracoCssPath = "~/css", - UmbracoScriptsPath = "~/scripts", - }; + var config = Mock.Of( + settings => + settings.UseHttps == false && + settings.HideTopLevelNodeFromPath == false && + settings.TimeOutInMinutes == 20 && + settings.DefaultUILanguage == "en" && + settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") && + settings.ReservedUrls == GlobalSettings.StaticReservedUrls && + settings.UmbracoPath == "~/umbraco" && + settings.UmbracoMediaPath == "~/media" && + settings.UmbracoCssPath == "~/css" && + settings.UmbracoScriptsPath == "~/scripts" + ); + + return config; } @@ -102,15 +104,15 @@ namespace Umbraco.Tests.Common _defaultHostingSettings = null; } - private readonly Dictionary _defaultGlobalSettings = new Dictionary(); + private readonly Dictionary _defaultGlobalSettings = new Dictionary(); private IHostingSettings _defaultHostingSettings; - public GlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion) + public IGlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion) { if (_defaultGlobalSettings.TryGetValue(umbVersion.SemanticVersion, out var settings)) return settings; - settings = GenerateStubGlobalSettings(umbVersion); + settings = GenerateMockGlobalSettings(umbVersion); _defaultGlobalSettings[umbVersion.SemanticVersion] = settings; return settings; } diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 461cbf4097..85a463ddfa 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -18,7 +18,6 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Strings; using Umbraco.Web; using Umbraco.Web.Routing; -using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Tests.Common { @@ -83,14 +82,14 @@ namespace Umbraco.Tests.Common public abstract IDbProviderFactoryCreator DbProviderFactoryCreator { get; } public abstract IBulkSqlInsertProvider BulkSqlInsertProvider { get; } public abstract IMarchal Marchal { get; } - public CoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); + public ICoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); public IIOHelper IOHelper { get { if (_ioHelper == null) - _ioHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateStubGlobalSettings()); + _ioHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateMockGlobalSettings()); return _ioHelper; } } diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs index 73076522c8..076cecef4a 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; @@ -9,7 +9,7 @@ namespace Umbraco.Tests.Integration.Implementations public class TestHostingEnvironment : AspNetCoreHostingEnvironment, IHostingEnvironment { - public TestHostingEnvironment(IOptionsSnapshot hostingSettings, IWebHostEnvironment webHostEnvironment) + public TestHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) : base(hostingSettings, webHostEnvironment) { } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs index a25a21f27c..3464259052 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs @@ -25,7 +25,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( @@ -50,7 +50,7 @@ namespace Umbraco.Tests.Security //hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); var mgr = new BackOfficeCookieManager( @@ -72,7 +72,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -97,7 +97,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -119,7 +119,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateStubGlobalSettings(); + var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 3bd7b0a7cc..a20b220940 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -14,7 +14,6 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Scoping; using Umbraco.Tests.TestHelpers; -using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Tests.Components { @@ -36,7 +35,7 @@ namespace Umbraco.Tests.Components var typeFinder = TestHelper.GetTypeFinder(); var f = new UmbracoDatabaseFactory(logger, SettingsForTests.DefaultGlobalSettings, Mock.Of(), new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); - var coreDebug = new CoreDebugSettings(); + var coreDebug = Mock.Of(); var mediaFileSystem = Mock.Of(); var p = new ScopeProvider(f, fs, coreDebug, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index 1dd9f3d7cb..632f433c5b 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -3,7 +3,6 @@ using System.Xml.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -32,7 +31,7 @@ namespace Umbraco.Tests.Models // and then, this will reset the width, height... because the file does not exist, of course ;-( var logger = Mock.Of(); var scheme = Mock.Of(); - var config = new ContentSettings(); + var config = Mock.Of(); var mediaFileSystem = new MediaFileSystem(Mock.Of(), scheme, logger, ShortStringHelper); var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, config, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper); diff --git a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs index c191bc1b43..e55a22065b 100644 --- a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs @@ -4,7 +4,6 @@ using Moq; using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -35,12 +34,12 @@ namespace Umbraco.Tests.Routing var logger = Mock.Of(); var mediaFileSystemMock = Mock.Of(); - var contentSettings = new ContentSettings(); + var contentSection = Mock.Of(); var dataTypeService = Mock.Of(); var propertyEditors = new MediaUrlGeneratorCollection(new IMediaUrlGenerator[] { - new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), - new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), + new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), + new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), }); _mediaUrlProvider = new DefaultMediaUrlProvider(propertyEditors, UriUtility); } diff --git a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs index d2a17d1004..8958eabd42 100644 --- a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs @@ -9,7 +9,6 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Net; using Umbraco.Web.Security; @@ -24,19 +23,18 @@ namespace Umbraco.Tests.Security const string v7Hash = "7Uob6fMTTxDIhWGebYiSxg==P+hgvWlXLbDd4cFLADn811KOaVI/9pg1PNvTuG5NklY="; const string plaintext = "4XxzH3s3&J"; - var passwordConfiguration = new UserPasswordConfigurationSettings - { - HashAlgorithmType = Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName - }; + var mockPasswordConfiguration = new Mock(); var mockIpResolver = new Mock(); var mockUserStore = new Mock>(); var mockDataProtectionProvider = new Mock(); mockDataProtectionProvider.Setup(x => x.Create(It.IsAny())) .Returns(new Mock().Object); + mockPasswordConfiguration.Setup(x => x.HashAlgorithmType) + .Returns(Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName); var userManager = BackOfficeOwinUserManager.Create( - passwordConfiguration, + mockPasswordConfiguration.Object, mockIpResolver.Object, mockUserStore.Object, null, diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index 6abe44d0fd..b58301287b 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -1,5 +1,4 @@ using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Tests.TestHelpers @@ -8,7 +7,7 @@ namespace Umbraco.Tests.TestHelpers { private static Common.SettingsForTests _settingsForTests = new Common.SettingsForTests(); - public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateStubGlobalSettings(TestHelper.GetUmbracoVersion()); + public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateMockGlobalSettings(TestHelper.GetUmbracoVersion()); /// /// Returns generated settings which can be stubbed to return whatever values necessary @@ -46,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers public static void Reset() => _settingsForTests.Reset(); - internal static GlobalSettings DefaultGlobalSettings => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion()); + internal static IGlobalSettings DefaultGlobalSettings => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion()); internal static IHostingSettings DefaultHostingSettings => _settingsForTests.DefaultHostingSettings; diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 08b21dda8d..5512f50254 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -33,7 +33,6 @@ using Umbraco.Web; using Umbraco.Web.Hosting; using Umbraco.Web.Routing; using File = System.IO.File; -using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Tests.TestHelpers { @@ -58,7 +57,7 @@ namespace Umbraco.Tests.TestHelpers public override IBackOfficeInfo GetBackOfficeInfo() => new AspNetBackOfficeInfo( - SettingsForTests.GenerateStubGlobalSettings(GetUmbracoVersion()), + SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion()), TestHelper.IOHelper, Mock.Of(), SettingsForTests.GenerateMockWebRoutingSettings()); public override IHostingEnvironment GetHostingEnvironment() @@ -95,7 +94,7 @@ namespace Umbraco.Tests.TestHelpers public static IDbProviderFactoryCreator DbProviderFactoryCreator => _testHelperInternal.DbProviderFactoryCreator; public static IBulkSqlInsertProvider BulkSqlInsertProvider => _testHelperInternal.BulkSqlInsertProvider; public static IMarchal Marchal => _testHelperInternal.Marchal; - public static CoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings; + public static ICoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings; public static IIOHelper IOHelper => _testHelperInternal.IOHelper; diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 24aa171c87..1b63bcc98d 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -8,7 +8,6 @@ using Moq; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -137,11 +136,10 @@ namespace Umbraco.Tests.TestHelpers return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext; } - public GlobalSettings GetGlobalSettings() + public IGlobalSettings GetGlobalSettings() { return SettingsForTests.DefaultGlobalSettings; } - public IFileSystems GetFileSystemsMock() { var fileSystems = Mock.Of(); diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 5077563e78..7e8914f78e 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -7,7 +7,6 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.Hosting; @@ -96,7 +95,7 @@ namespace Umbraco.Tests.TestHelpers ILogger logger, IIOHelper ioHelper, IGlobalSettings globalSettings, - ContentSettings contentSettings, + IContentSettings contentSettings, IEventMessagesFactory eventMessagesFactory, UrlSegmentProviderCollection urlSegmentProviders, IUmbracoVersion umbracoVersion, diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index 2c4273b5a1..c8c6cbdf5c 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.SignalR; using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Web.Composing; @@ -47,7 +46,7 @@ namespace Umbraco.Web /// The app builder. /// /// - public static IAppBuilder UseSignalR(this IAppBuilder app, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; diff --git a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs index ab3f575d36..1e60fedeea 100644 --- a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs +++ b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs @@ -1,8 +1,6 @@ using System.Web; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -11,17 +9,12 @@ namespace Umbraco.Web { public class AspNetBackOfficeInfo : IBackOfficeInfo { - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; - private readonly WebRoutingSettings _webRoutingSettings; + private readonly IWebRoutingSettings _webRoutingSettings; - public AspNetBackOfficeInfo(IOptionsSnapshot globalSettings, IIOHelper ioHelper, ILogger logger, IOptionsSnapshot webRoutingSettings) - : this(globalSettings.Value, ioHelper, logger, webRoutingSettings.Value) - { - } - - public AspNetBackOfficeInfo(GlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, WebRoutingSettings webRoutingSettings) + public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IWebRoutingSettings webRoutingSettings) { _globalSettings = globalSettings; _ioHelper = ioHelper; diff --git a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs index 2423c7802b..5e7324236a 100644 --- a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs @@ -2,27 +2,27 @@ using System; using System.Reflection; using System.Web; using System.Web.Hosting; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; namespace Umbraco.Web.Hosting { public class AspNetHostingEnvironment : IHostingEnvironment { - private readonly HostingSettings _hostingSettings; + + private readonly IHostingSettings _hostingSettings; private string _localTempPath; - public AspNetHostingEnvironment(IOptionsSnapshot hostingSettings) + + public AspNetHostingEnvironment(IHostingSettings hostingSettings) { - _hostingSettings = hostingSettings.Value ?? throw new ArgumentNullException(nameof(hostingSettings)); + _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); SiteName = HostingEnvironment.SiteName; ApplicationId = HostingEnvironment.ApplicationID; // when we are not hosted (i.e. unit test or otherwise) we'll need to get the root path from the executing assembly ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath ?? Assembly.GetExecutingAssembly().GetRootDirectorySafe(); - ApplicationVirtualPath = _hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') + ApplicationVirtualPath = hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') ?? HostingEnvironment.ApplicationVirtualPath?.EnsureStartsWith("/") ?? "/"; IISVersion = HttpRuntime.IISVersion; diff --git a/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs b/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs index 7e1e853716..aa2cba6949 100644 --- a/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs +++ b/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Web.Routing; @@ -10,18 +8,20 @@ namespace Umbraco.Web.AspNet public class AspNetRequestAccessor : IRequestAccessor { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly WebRoutingSettings _webRoutingSettings; + private readonly IWebRoutingSettings _webRoutingSettings; private readonly ISet _applicationUrls = new HashSet(); private Uri _currentApplicationUrl; - public AspNetRequestAccessor(IHttpContextAccessor httpContextAccessor, IOptionsSnapshot webRoutingSettings) + public AspNetRequestAccessor(IHttpContextAccessor httpContextAccessor, IWebRoutingSettings webRoutingSettings) { _httpContextAccessor = httpContextAccessor; - _webRoutingSettings = webRoutingSettings.Value; + _webRoutingSettings = webRoutingSettings; UmbracoModule.EndRequest += OnEndRequest; UmbracoModule.RouteAttempt += OnRouteAttempt; } + + public string GetRequestValue(string name) { return _httpContextAccessor.GetRequiredHttpContext().Request[name]; diff --git a/src/Umbraco.Web/Compose/AuditEventsComponent.cs b/src/Umbraco.Web/Compose/AuditEventsComponent.cs index ef81a35b1c..51c47233c7 100644 --- a/src/Umbraco.Web/Compose/AuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/AuditEventsComponent.cs @@ -11,8 +11,6 @@ using Umbraco.Net; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Extensions; -using Umbraco.Core.Configuration.Models; -using Microsoft.Extensions.Options; namespace Umbraco.Core.Compose { @@ -22,15 +20,15 @@ namespace Umbraco.Core.Compose private readonly IUserService _userService; private readonly IEntityService _entityService; private readonly IIpResolver _ipResolver; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; - public AuditEventsComponent(IAuditService auditService, IUserService userService, IEntityService entityService, IIpResolver ipResolver, IOptionsSnapshot globalSettings) + public AuditEventsComponent(IAuditService auditService, IUserService userService, IEntityService entityService, IIpResolver ipResolver, IGlobalSettings globalSettings) { _auditService = auditService; _userService = userService; _entityService = entityService; _ipResolver = ipResolver; - _globalSettings = globalSettings.Value; + _globalSettings = globalSettings; } public void Initialize() @@ -51,7 +49,7 @@ namespace Umbraco.Core.Compose public void Terminate() { } - public static IUser UnknownUser(GlobalSettings globalSettings) => new User(globalSettings) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; + public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(globalSettings) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; private IUser CurrentPerformingUser { diff --git a/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs b/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs index 2357a62eb8..dcb5fac32d 100644 --- a/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs @@ -1,10 +1,8 @@ using System; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Compose; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Web.Security; @@ -15,13 +13,13 @@ namespace Umbraco.Web.Compose { private readonly IAuditService _auditService; private readonly IUserService _userService; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; - public BackOfficeUserAuditEventsComponent(IAuditService auditService, IUserService userService, IOptionsSnapshot globalSettings) + public BackOfficeUserAuditEventsComponent(IAuditService auditService, IUserService userService, IGlobalSettings globalSettings) { _auditService = auditService; _userService = userService; - _globalSettings = globalSettings.Value; + _globalSettings = globalSettings; } public void Initialize() diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index d919f04077..e4773a85d5 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -1,30 +1,35 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Collections.Generic; +using System.Net.Mail; using System.Security.Principal; using System.Threading.Tasks; +using System.Web; using System.Web.Http; +using System.Web.Mvc; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; -using Umbraco.Core.Mapping; -using Umbraco.Core.Persistence; +using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web.Models; +using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Mvc; -using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; -using Constants = Umbraco.Core.Constants; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Persistence; using IUser = Umbraco.Core.Models.Membership.IUser; +using Umbraco.Core.Mapping; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Hosting; +using Umbraco.Extensions; +using Umbraco.Web.Routing; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors { @@ -39,16 +44,16 @@ namespace Umbraco.Web.Editors { private BackOfficeOwinUserManager _userManager; private BackOfficeSignInManager _signInManager; - private readonly UserPasswordConfigurationSettings _passwordConfiguration; + private readonly IUserPasswordConfiguration _passwordConfiguration; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; - private readonly SecuritySettings _securitySettings; + private readonly ISecuritySettings _securitySettings; private readonly IRequestAccessor _requestAccessor; private readonly IEmailSender _emailSender; public AuthenticationController( - IOptionsSnapshot passwordConfiguration, - IOptionsSnapshot globalSettings, + IUserPasswordConfiguration passwordConfiguration, + IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, @@ -57,16 +62,16 @@ namespace Umbraco.Web.Editors IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, - IOptionsSnapshot securitySettings, + ISecuritySettings securitySettings, IPublishedUrlProvider publishedUrlProvider, IRequestAccessor requestAccessor, IEmailSender emailSender) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { - _passwordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); + _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); - _securitySettings = securitySettings.Value ?? throw new ArgumentNullException(nameof(securitySettings)); + _securitySettings = securitySettings ?? throw new ArgumentNullException(nameof(securitySettings)); _requestAccessor = requestAccessor ?? throw new ArgumentNullException(nameof(securitySettings)); _emailSender = emailSender; } diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index de94f42007..b963871a58 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -4,21 +4,19 @@ using System.Threading.Tasks; using System.Web; using System.Web.Mvc; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Hosting; using Umbraco.Core.Logging; +using Umbraco.Web.Mvc; using Umbraco.Core.Services; using Umbraco.Web.Features; -using Umbraco.Web.Mvc; using Umbraco.Web.Security; -using BackOfficeIdentityUser = Umbraco.Core.BackOffice.BackOfficeIdentityUser; using Constants = Umbraco.Core.Constants; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Hosting; +using BackOfficeIdentityUser = Umbraco.Core.BackOffice.BackOfficeIdentityUser; namespace Umbraco.Web.Editors { @@ -36,12 +34,12 @@ namespace Umbraco.Web.Editors private readonly IUmbracoVersion _umbracoVersion; private readonly IContentSettings _contentSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly RuntimeSettings _runtimeSettings; - private readonly SecuritySettings _securitySettings; + private readonly IRuntimeSettings _runtimeSettings; + private readonly ISecuritySettings _securitySettings; public BackOfficeController( UmbracoFeatures features, - IOptionsSnapshot globalSettings, + IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, @@ -49,16 +47,17 @@ namespace Umbraco.Web.Editors IUmbracoVersion umbracoVersion, IContentSettings contentSettings, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot runtimeSettings, - IOptionsSnapshot securitySettings) + IRuntimeSettings settings, + ISecuritySettings securitySettings) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) + { _features = features; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _hostingEnvironment = hostingEnvironment; - _runtimeSettings = runtimeSettings.Value; - _securitySettings = securitySettings.Value; + _runtimeSettings = settings; + _securitySettings = securitySettings; } protected BackOfficeSignInManager SignInManager => _signInManager ?? (_signInManager = OwinContext.GetBackOfficeSignInManager()); diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 4246ffb2ec..454338112c 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -5,18 +5,18 @@ using System.Linq; using System.Runtime.Serialization; using System.Web; using System.Web.Mvc; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; +using Umbraco.Web.Features; +using Umbraco.Web.HealthCheck; +using Umbraco.Web.Models.ContentEditing; +using Umbraco.Web.Mvc; +using Umbraco.Web.Trees; +using Constants = Umbraco.Core.Constants; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.WebAssets; -using Umbraco.Web.Features; -using Umbraco.Web.Mvc; using Umbraco.Web.Security; -using Umbraco.Web.Trees; -using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors { @@ -28,39 +28,39 @@ namespace Umbraco.Web.Editors private readonly UrlHelper _urlHelper; private readonly IRuntimeState _runtimeState; private readonly UmbracoFeatures _features; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; private readonly IContentSettings _contentSettings; private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; - private readonly RuntimeSettings _runtimeSettings; - private readonly SecuritySettings _securitySettings; + private readonly IRuntimeSettings _settings; + private readonly ISecuritySettings _securitySettings; private readonly IRuntimeMinifier _runtimeMinifier; internal BackOfficeServerVariables( UrlHelper urlHelper, IRuntimeState runtimeState, UmbracoFeatures features, - IOptionsSnapshot globalSettings, + IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IContentSettings contentSettings, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot runtimeSettings, - IOptionsSnapshot securitySettings, + IRuntimeSettings settings, + ISecuritySettings securitySettings, IRuntimeMinifier runtimeMinifier) { _urlHelper = urlHelper; _runtimeState = runtimeState; _features = features; - _globalSettings = globalSettings.Value; + _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; - _runtimeSettings = runtimeSettings.Value; - _securitySettings = securitySettings.Value; + _settings = settings; + _securitySettings = securitySettings; _runtimeMinifier = runtimeMinifier; } @@ -288,7 +288,7 @@ namespace Umbraco.Web.Editors private string GetMaxRequestLength() { - return _runtimeSettings.MaxRequestLength.HasValue ? _runtimeSettings.MaxRequestLength.Value.ToString() : string.Empty; + return _settings.MaxRequestLength.HasValue ? _settings.MaxRequestLength.Value.ToString() : string.Empty; } } } diff --git a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs index f0f7e50be5..64aba378f4 100644 --- a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs +++ b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs @@ -1,9 +1,7 @@ using System; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -33,7 +31,7 @@ namespace Umbraco.Web.Editors } protected UmbracoAuthorizedJsonController( - IOptionsSnapshot globalSettings, + IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index d6c4451efb..6fe069fc59 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -10,7 +10,6 @@ using System.Web.Mvc.Html; using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Web.Mvc; @@ -61,18 +60,18 @@ namespace Umbraco.Web /// /// See: http://issues.umbraco.org/issue/U4-1614 /// - public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings, IIOHelper ioHelper, IContentSettings contentSettings) + public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IIOHelper ioHelper, IContentSettings contentSettings) { if (Current.UmbracoContext.InPreviewMode) { var htmlBadge = - string.Format(contentSettings.PreviewBadge, + String.Format(contentSettings.PreviewBadge, ioHelper.ResolveUrl(globalSettings.UmbracoPath), WebUtility.UrlEncode(httpContextAccessor.GetRequiredHttpContext().Request.Path), Current.UmbracoContext.PublishedRequest.PublishedContent.Id); return new MvcHtmlString(htmlBadge); } - return new MvcHtmlString(string.Empty); + return new MvcHtmlString(""); } diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index e25ab4a69e..118c53a7f0 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -6,8 +6,10 @@ using System.Web.Routing; using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; +using Umbraco.Core.IO; +using Umbraco.Web.Composing; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -42,7 +44,7 @@ namespace Umbraco.Web.Mvc /// /// internal static Route RouteControllerPlugin(this AreaRegistration area, - GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, + IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, string controllerName, Type controllerType, RouteCollection routes, string controllerSuffixName, string defaultAction, object defaultId, string umbracoTokenValue = "backoffice", diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index 2037d37914..156a896bb5 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,8 +1,8 @@ using System.Web.Mvc; -using Microsoft.Extensions.Options; +using Umbraco.Web.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; +using Umbraco.Core.IO; using Umbraco.Web.Editors; namespace Umbraco.Web.Mvc @@ -10,15 +10,10 @@ namespace Umbraco.Web.Mvc // TODO: This has been ported to netcore, can be removed internal class BackOfficeArea : AreaRegistration { - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - public BackOfficeArea(IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) - : this(globalSettings.Value, hostingEnvironment) - { - } - - public BackOfficeArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public BackOfficeArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Web/Mvc/PluginControllerArea.cs b/src/Umbraco.Web/Mvc/PluginControllerArea.cs index bf2d24086d..838e304847 100644 --- a/src/Umbraco.Web/Mvc/PluginControllerArea.cs +++ b/src/Umbraco.Web/Mvc/PluginControllerArea.cs @@ -9,8 +9,6 @@ using Umbraco.Core.Composing; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Web.WebApi; -using Umbraco.Core.Configuration.Models; -using Microsoft.Extensions.Options; namespace Umbraco.Web.Mvc { @@ -19,7 +17,7 @@ namespace Umbraco.Web.Mvc /// internal class PluginControllerArea : AreaRegistration { - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IEnumerable _surfaceControllers; private readonly IEnumerable _apiControllers; @@ -32,12 +30,7 @@ namespace Umbraco.Web.Mvc /// /// /// - public PluginControllerArea(IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) - : this(globalSettings.Value, hostingEnvironment, pluginControllers) - { - } - - public PluginControllerArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) + public PluginControllerArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) { _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; @@ -48,7 +41,7 @@ namespace Umbraco.Web.Mvc throw new InvalidOperationException("Cannot create a PluginControllerArea unless all plugin controllers assigned have a PluginControllerAttribute assigned"); } _areaName = controllers.First().AreaName; - foreach (var c in controllers) + foreach(var c in controllers) { if (c.AreaName != _areaName) { diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 1e6f5a00c3..7286f52c64 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -1,8 +1,7 @@ using System; using System.Web.Mvc; -using Microsoft.Extensions.Options; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -11,6 +10,7 @@ using Umbraco.Web.Routing; namespace Umbraco.Web.Mvc { + /// /// Represents the default front-end rendering controller. /// @@ -25,7 +25,7 @@ namespace Umbraco.Web.Mvc ActionInvoker = new RenderActionInvoker(); } - public RenderMvcController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + public RenderMvcController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { ActionInvoker = new RenderActionInvoker(); diff --git a/src/Umbraco.Web/Mvc/RenderNoContentController.cs b/src/Umbraco.Web/Mvc/RenderNoContentController.cs index 1f9a24212b..9334591fbb 100644 --- a/src/Umbraco.Web/Mvc/RenderNoContentController.cs +++ b/src/Umbraco.Web/Mvc/RenderNoContentController.cs @@ -1,8 +1,6 @@ using System; using System.Web.Mvc; -using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Models; @@ -12,13 +10,13 @@ namespace Umbraco.Web.Mvc { private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IIOHelper _ioHelper; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; - public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IOptionsSnapshot globalSettings) + public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IGlobalSettings globalSettings) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); } public ActionResult Index() diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs index f774eb8a4e..0724cd138d 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs @@ -1,7 +1,5 @@ -using Microsoft.Extensions.Options; -using Umbraco.Core.Cache; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Services; @@ -23,7 +21,7 @@ namespace Umbraco.Web.Mvc { } - protected UmbracoAuthorizedController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + protected UmbracoAuthorizedController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { } diff --git a/src/Umbraco.Web/Mvc/UmbracoController.cs b/src/Umbraco.Web/Mvc/UmbracoController.cs index ff0ac170fb..9cfd93ba9d 100644 --- a/src/Umbraco.Web/Mvc/UmbracoController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoController.cs @@ -1,14 +1,13 @@ using System; using System.Web; using System.Web.Mvc; -using Microsoft.Extensions.Options; using Microsoft.Owin; -using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Logging; -using Umbraco.Core.Services; using Umbraco.Web.Composing; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core; +using Umbraco.Core.Services; using Umbraco.Web.Security; namespace Umbraco.Web.Mvc @@ -22,9 +21,9 @@ namespace Umbraco.Web.Mvc internal Guid InstanceId { get; } = Guid.NewGuid(); /// - /// Gets the global settings from configuration. + /// Gets or sets the Umbraco context. /// - public GlobalSettings GlobalSettings { get; } + public IGlobalSettings GlobalSettings { get; } /// /// Gets the Umbraco context. @@ -70,7 +69,7 @@ namespace Umbraco.Web.Mvc protected UmbracoController() : this( - Current.Factory.GetInstance>(), + Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), @@ -79,9 +78,9 @@ namespace Umbraco.Web.Mvc { } - protected UmbracoController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + protected UmbracoController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) { - GlobalSettings = globalSettings.Value; + GlobalSettings = globalSettings; UmbracoContextAccessor = umbracoContextAccessor; Services = services; AppCaches = appCaches; diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index b9c31388a2..a687e7c9cd 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -3,11 +3,9 @@ using System.Text; using System.Web; using System.Web.Mvc; using System.Web.WebPages; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -24,8 +22,8 @@ namespace Umbraco.Web.Mvc /// public abstract class UmbracoViewPage : WebViewPage { - private readonly GlobalSettings _globalSettings; - private readonly ContentSettings _contentSettings; + private readonly IGlobalSettings _globalSettings; + private readonly IContentSettings _contentSettings; private IUmbracoContext _umbracoContext; private UmbracoHelper _helper; @@ -107,18 +105,18 @@ namespace Umbraco.Web.Mvc : this( Current.Factory.GetInstance(), Current.Factory.GetInstance(), - Current.Factory.GetInstance>(), - Current.Factory.GetInstance>() + Current.Factory.GetInstance(), + Current.Factory.GetInstance() ) { } - protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IOptionsSnapshot globalSettings, IOptionsSnapshot contentSettings) + protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IGlobalSettings globalSettings, IContentSettings contentSettings) { Services = services; AppCaches = appCaches; - _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); - _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); + _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); } // view logic below: diff --git a/src/Umbraco.Web/RoutableDocumentFilter.cs b/src/Umbraco.Web/RoutableDocumentFilter.cs index 5f5c832d1f..43e47a39b3 100644 --- a/src/Umbraco.Web/RoutableDocumentFilter.cs +++ b/src/Umbraco.Web/RoutableDocumentFilter.cs @@ -1,17 +1,16 @@ using System; -using System.Collections.Concurrent; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading; using System.Web; using System.Web.Routing; -using Microsoft.Extensions.Options; using Umbraco.Core; -using Umbraco.Core.Collections; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; +using System.Threading; +using System.Collections.Generic; +using System.Linq; +using System.Collections.Concurrent; +using Umbraco.Core.Collections; using Umbraco.Core.IO; +using Umbraco.Web.Composing; namespace Umbraco.Web { @@ -23,20 +22,20 @@ namespace Umbraco.Web /// public sealed class RoutableDocumentFilter { + public RoutableDocumentFilter(IGlobalSettings globalSettings, IIOHelper ioHelper) + { + _globalSettings = globalSettings; + _ioHelper = ioHelper; + } + private static readonly ConcurrentDictionary RouteChecks = new ConcurrentDictionary(); - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private object _locker = new object(); private bool _isInit = false; private int? _routeCount; private HashSet _reservedList; - public RoutableDocumentFilter(IOptionsSnapshot globalSettings, IIOHelper ioHelper) - { - _globalSettings = globalSettings.Value; - _ioHelper = ioHelper; - } - /// /// Checks if the request is a document request (i.e. one that the module should handle) /// diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index 88c08cd937..dbd0a1fb3a 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -17,8 +17,6 @@ using Umbraco.Web.WebApi; using Constants = Umbraco.Core.Constants; using Current = Umbraco.Web.Composing.Current; -using Umbraco.Core.Configuration.Models; -using Microsoft.Extensions.Options; namespace Umbraco.Web.Runtime { @@ -27,7 +25,7 @@ namespace Umbraco.Web.Runtime private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly SurfaceControllerTypeCollection _surfaceControllerTypes; private readonly UmbracoApiControllerTypeCollection _apiControllerTypes; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; @@ -35,14 +33,14 @@ namespace Umbraco.Web.Runtime IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, - IOptionsSnapshot globalSettings, + IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper) { _umbracoContextAccessor = umbracoContextAccessor; _surfaceControllerTypes = surfaceControllerTypes; _apiControllerTypes = apiControllerTypes; - _globalSettings = globalSettings.Value; + _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; } @@ -113,7 +111,7 @@ namespace Umbraco.Web.Runtime // internal for tests internal static void CreateRoutes( IUmbracoContextAccessor umbracoContextAccessor, - GlobalSettings globalSettings, + IGlobalSettings globalSettings, IShortStringHelper shortStringHelper, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, @@ -151,7 +149,7 @@ namespace Umbraco.Web.Runtime } private static void RoutePluginControllers( - GlobalSettings globalSettings, + IGlobalSettings globalSettings, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) diff --git a/src/Umbraco.Web/Security/AppBuilderExtensions.cs b/src/Umbraco.Web/Security/AppBuilderExtensions.cs index 885baaab79..ac5434aa4e 100644 --- a/src/Umbraco.Web/Security/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/Security/AppBuilderExtensions.cs @@ -8,7 +8,6 @@ using Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.Composing; using Constants = Umbraco.Core.Constants; @@ -35,7 +34,7 @@ namespace Umbraco.Web.Security /// /// By default this will be configured to execute on PipelineStage.Authenticate /// - public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache) + public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache) { return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, hostingEnvironment, requestCache, PipelineStage.Authenticate); } @@ -54,7 +53,7 @@ namespace Umbraco.Web.Security /// public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, - GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage) + IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage) { if (app == null) throw new ArgumentNullException(nameof(app)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState)); diff --git a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs index beb79d3e98..26b85d6c39 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs @@ -1,10 +1,15 @@ -using Microsoft.Extensions.Options; +using System; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Umbraco.Core; +using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Hosting; using Umbraco.Core.Services; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Hosting; +using Umbraco.Core.Security; namespace Umbraco.Web.Security { @@ -14,27 +19,26 @@ namespace Umbraco.Web.Security { private readonly IUserService _userService; private readonly IRuntimeState _runtimeState; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly SecuritySettings _securitySettings; + private readonly ISecuritySettings _securitySettings; - public BackOfficeCookieAuthenticationProvider( - IUserService userService, - IRuntimeState runtimeState, - IOptionsSnapshot globalSettings, - IHostingEnvironment hostingEnvironment, - IOptionsSnapshot securitySettings) + public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, ISecuritySettings securitySettings) { _userService = userService; _runtimeState = runtimeState; - _globalSettings = globalSettings.Value; + _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; - _securitySettings = securitySettings.Value; + _securitySettings = securitySettings; } public override void ResponseSignOut(CookieResponseSignOutContext context) - { + { + } + + + } } diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index 5464902bb3..771c3239b6 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -8,7 +8,6 @@ using Microsoft.Owin.Security.DataProtection; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Security; using Umbraco.Core.Services; @@ -21,7 +20,7 @@ namespace Umbraco.Web.Security public const string OwinMarkerKey = "Umbraco.Web.Security.Identity.BackOfficeUserManagerMarker"; public BackOfficeOwinUserManager( - IOptions passwordConfiguration, + IUserPasswordConfiguration passwordConfiguration, IIpResolver ipResolver, IUserStore store, IOptions optionsAccessor, @@ -33,7 +32,7 @@ namespace Umbraco.Web.Security ILogger> logger) : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, passwordConfiguration) { - PasswordConfiguration = passwordConfiguration.Value; + PasswordConfiguration = passwordConfiguration; InitUserManager(this, dataProtectionProvider); } @@ -46,9 +45,9 @@ namespace Umbraco.Web.Security IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, - GlobalSettings globalSettings, + IGlobalSettings globalSettings, UmbracoMapper mapper, - UserPasswordConfigurationSettings passwordConfiguration, + IUserPasswordConfiguration passwordConfiguration, IIpResolver ipResolver, BackOfficeIdentityErrorDescriber errors, IDataProtectionProvider dataProtectionProvider, @@ -69,7 +68,7 @@ namespace Umbraco.Web.Security /// Creates a BackOfficeUserManager instance with all default options and a custom BackOfficeUserManager instance /// public static BackOfficeOwinUserManager Create( - UserPasswordConfigurationSettings passwordConfiguration, + IUserPasswordConfiguration passwordConfiguration, IIpResolver ipResolver, IUserStore customUserStore, BackOfficeIdentityErrorDescriber errors, @@ -104,7 +103,7 @@ namespace Umbraco.Web.Security options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(30); return new BackOfficeOwinUserManager( - new OptionsWrapper(passwordConfiguration), + passwordConfiguration, ipResolver, customUserStore, new OptionsWrapper(options), diff --git a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs index 01ed3ae30e..021adaed97 100644 --- a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs @@ -11,7 +11,6 @@ using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Security { @@ -26,7 +25,7 @@ namespace Umbraco.Web.Security private readonly IUserClaimsPrincipalFactory _claimsPrincipalFactory; private readonly IAuthenticationManager _authenticationManager; private readonly ILogger _logger; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IOwinRequest _request; public BackOfficeSignInManager( @@ -34,18 +33,7 @@ namespace Umbraco.Web.Security IUserClaimsPrincipalFactory claimsPrincipalFactory, IAuthenticationManager authenticationManager, ILogger logger, - IOptionsSnapshot globalSettings, - IOwinRequest request) - :this(userManager, claimsPrincipalFactory, authenticationManager, logger, globalSettings.Value, request) - { - } - - public BackOfficeSignInManager( - BackOfficeUserManager userManager, - IUserClaimsPrincipalFactory claimsPrincipalFactory, - IAuthenticationManager authenticationManager, - ILogger logger, - GlobalSettings globalSettings, + IGlobalSettings globalSettings, IOwinRequest request) { _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); @@ -64,7 +52,7 @@ namespace Umbraco.Web.Security return claimsPrincipal.Identity as ClaimsIdentity; } - public static BackOfficeSignInManager Create(IOwinContext context, GlobalSettings globalSettings, ILogger logger) + public static BackOfficeSignInManager Create(IOwinContext context, IGlobalSettings globalSettings, ILogger logger) { var userManager = context.GetBackOfficeUserManager(); diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index e1227a892d..3ab37f0f70 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -3,13 +3,14 @@ using System.Diagnostics; using System.Globalization; using System.Threading.Tasks; using System.Web; -using Microsoft.Extensions.Options; using Microsoft.Owin; using Microsoft.Owin.Logging; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; +using Umbraco.Core.IO; +using Umbraco.Core.Security; namespace Umbraco.Web.Security { @@ -24,23 +25,23 @@ namespace Umbraco.Web.Security internal class GetUserSecondsMiddleWare : OwinMiddleware { private readonly UmbracoBackOfficeCookieAuthOptions _authOptions; - private readonly GlobalSettings _globalSettings; - private readonly SecuritySettings _securitySettings; + private readonly IGlobalSettings _globalSettings; + private readonly ISecuritySettings _security; private readonly ILogger _logger; private readonly IHostingEnvironment _hostingEnvironment; public GetUserSecondsMiddleWare( OwinMiddleware next, UmbracoBackOfficeCookieAuthOptions authOptions, - IOptionsSnapshot globalSettings, - IOptionsSnapshot securitySettings, + IGlobalSettings globalSettings, + ISecuritySettings security, ILogger logger, IHostingEnvironment hostingEnvironment) : base(next) { _authOptions = authOptions ?? throw new ArgumentNullException(nameof(authOptions)); - _globalSettings = globalSettings.Value; - _securitySettings = securitySettings.Value; + _globalSettings = globalSettings; + _security = security; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _hostingEnvironment = hostingEnvironment; } @@ -54,7 +55,7 @@ namespace Umbraco.Web.Security && request.Uri.AbsolutePath.InvariantEquals( $"{_globalSettings.GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) { - var cookie = _authOptions.CookieManager.GetRequestCookie(context, _securitySettings.AuthCookieName); + var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName); if (cookie.IsNullOrWhiteSpace() == false) { var ticket = _authOptions.TicketDataFormat.Unprotect(cookie); @@ -74,7 +75,7 @@ namespace Umbraco.Web.Security //Ok, so here we need to check if we want to process/renew the auth ticket for each // of these requests. If that is the case, the user will really never be logged out until they // close their browser (there will be edge cases of that, especially when debugging) - if (_securitySettings.KeepUserLoggedIn) + if (_security.KeepUserLoggedIn) { var currentUtc = _authOptions.SystemClock.UtcNow; var issuedUtc = ticket.Properties.IssuedUtc; diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 7eeea5662c..1c447b38aa 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -9,7 +9,6 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -45,7 +44,7 @@ namespace Umbraco.Web Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "App_Data\\Logs"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.config"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.user.config")); - var ioHelper = new IOHelper(hostingEnvironment); + var ioHelper = new IOHelper(hostingEnvironment, globalSettings); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration); var configs = configFactory.Create(); @@ -126,7 +125,7 @@ namespace Umbraco.Web /// /// Gets the application register. /// - protected virtual IRegister GetRegister(GlobalSettings globalSettings) + protected virtual IRegister GetRegister(IGlobalSettings globalSettings) { return RegisterFactory.Create(globalSettings); } diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 703f5f9b51..ae1cf885b3 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -2,7 +2,6 @@ using System; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; @@ -18,7 +17,7 @@ namespace Umbraco.Web public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd, IUmbracoContext { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly ICookieManager _cookieManager; private readonly Lazy _publishedSnapshot; @@ -32,7 +31,7 @@ namespace Umbraco.Web internal UmbracoContext(IHttpContextAccessor httpContextAccessor, IPublishedSnapshotService publishedSnapshotService, IWebSecurity webSecurity, - GlobalSettings globalSettings, + IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IVariationContextAccessor variationContextAccessor, UriUtility uriUtility, diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index a804e4b3be..bfb4dd627d 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -1,9 +1,7 @@ using System; using System.IO; using System.Text; -using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -22,7 +20,7 @@ namespace Umbraco.Web private readonly IVariationContextAccessor _variationContextAccessor; private readonly IDefaultCultureAccessor _defaultCultureAccessor; - private readonly GlobalSettings _globalSettings; + private readonly IGlobalSettings _globalSettings; private readonly IUserService _userService; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; @@ -37,7 +35,7 @@ namespace Umbraco.Web IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, - IOptionsSnapshot globalSettings, + IGlobalSettings globalSettings, IUserService userService, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, @@ -48,7 +46,7 @@ namespace Umbraco.Web _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _defaultCultureAccessor = defaultCultureAccessor ?? throw new ArgumentNullException(nameof(defaultCultureAccessor)); - _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); + _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _hostingEnvironment = hostingEnvironment; _uriUtility = uriUtility; diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index af10009a0e..600b58cf06 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -1,20 +1,20 @@ using System; -using Microsoft.Extensions.Options; using Microsoft.Owin; using Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; +using Umbraco.Core.IO; using Umbraco.Core.Mapping; -using Umbraco.Core.Services; using Umbraco.Net; +using Umbraco.Core.Services; using Umbraco.Web; using Umbraco.Web.Composing; using Umbraco.Web.Security; + [assembly: OwinStartup("UmbracoDefaultOwinStartup", typeof(UmbracoDefaultOwinStartup))] namespace Umbraco.Web @@ -30,7 +30,7 @@ namespace Umbraco.Web protected IUmbracoContextAccessor UmbracoContextAccessor => Current.UmbracoContextAccessor; protected IGlobalSettings GlobalSettings => Current.Factory.GetInstance(); protected IContentSettings ContentSettings => Current.Factory.GetInstance(); - protected SecuritySettings SecuritySettings => Current.Factory.GetInstance>().Value; + protected ISecuritySettings SecuritySettings => Current.Factory.GetInstance(); protected IUserPasswordConfiguration UserPasswordConfig => Current.Factory.GetInstance(); protected IRuntimeState RuntimeState => Current.RuntimeState; protected ServiceContext Services => Current.Services; diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index 36cf0d5c20..a832b4e823 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -1,10 +1,8 @@ using System; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -22,7 +20,7 @@ namespace Umbraco.Web.WebApi { } - protected UmbracoApiController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs index 323f09316f..d009528bc7 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs @@ -14,11 +14,11 @@ using Umbraco.Web.Features; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi.Filters; -using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.WebApi { + + /// /// Provides a base class for Umbraco API controllers. /// @@ -26,6 +26,7 @@ namespace Umbraco.Web.WebApi [FeatureAuthorize] public abstract class UmbracoApiControllerBase : ApiController, IUmbracoFeature { + // note: all Umbraco controllers have two constructors: one with all dependencies, which should be used, // and one with auto dependencies, ie no dependencies - and then dependencies are automatically obtained // here from the Current service locator - this is obviously evil, but it allows us to add new dependencies @@ -37,7 +38,7 @@ namespace Umbraco.Web.WebApi /// Dependencies are obtained from the service locator. protected UmbracoApiControllerBase() : this( - Current.Factory.GetInstance>(), + Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), @@ -52,10 +53,10 @@ namespace Umbraco.Web.WebApi /// /// Initializes a new instance of the class with all its dependencies. /// - protected UmbracoApiControllerBase(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoApiControllerBase(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) { UmbracoContextAccessor = umbracoContextAccessor; - GlobalSettings = globalSettings.Value; + GlobalSettings = globalSettings; SqlContext = sqlContext; Services = services; AppCaches = appCaches; @@ -72,9 +73,9 @@ namespace Umbraco.Web.WebApi internal Guid InstanceId { get; } = Guid.NewGuid(); /// - /// Gets the global settings from configuration. + /// Gets the Umbraco context. /// - public virtual GlobalSettings GlobalSettings { get; } + public virtual IGlobalSettings GlobalSettings { get; } /// /// Gets the Umbraco context. diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 1bd9fb8f31..48b3de44fd 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -8,8 +8,6 @@ using Umbraco.Core.Services; using Umbraco.Web.Security; using Umbraco.Core.Mapping; using Umbraco.Web.Routing; -using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.WebApi { @@ -37,7 +35,7 @@ namespace Umbraco.Web.WebApi { } - protected UmbracoAuthorizedApiController(IOptionsSnapshot globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoAuthorizedApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs index b38c775f67..0d8d4b8bf2 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs @@ -3,11 +3,9 @@ using System.Collections.Specialized; using System.IO; using ClientDependency.Core.CompositeFiles.Providers; using ClientDependency.Core.Config; -using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.Runtime; @@ -16,18 +14,18 @@ namespace Umbraco.Web.WebAssets.CDF [ComposeAfter(typeof(WebInitialComponent))] public sealed class ClientDependencyComponent : IComponent { - private readonly HostingSettings _hostingSettings; + private readonly IHostingSettings _hostingSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly RuntimeSettings _runtimeSettings; + private readonly IRuntimeSettings _settings; public ClientDependencyComponent( - IOptionsSnapshot hostingSettings, + IHostingSettings hostingSettings, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot runtimeSettings) + IRuntimeSettings settings) { - _hostingSettings = hostingSettings.Value; + _hostingSettings = hostingSettings; _hostingEnvironment = hostingEnvironment; - _runtimeSettings = runtimeSettings.Value; + _settings = settings; } public void Initialize() @@ -56,10 +54,10 @@ namespace Umbraco.Web.WebAssets.CDF = Path.Combine(cachePath, "ClientDependency"); } - if (_runtimeSettings.MaxQueryStringLength.HasValue || _runtimeSettings.MaxRequestLength.HasValue) + if (_settings.MaxQueryStringLength.HasValue || _settings.MaxRequestLength.HasValue) { //set the max url length for CDF to be the smallest of the max query length, max request length - ClientDependency.Core.CompositeFiles.CompositeDependencyHandler.MaxHandlerUrlLength = Math.Min(_runtimeSettings.MaxQueryStringLength.GetValueOrDefault(), _runtimeSettings.MaxRequestLength.GetValueOrDefault()); + ClientDependency.Core.CompositeFiles.CompositeDependencyHandler.MaxHandlerUrlLength = Math.Min(_settings.MaxQueryStringLength.GetValueOrDefault(), _settings.MaxRequestLength.GetValueOrDefault()); } //Register a custom renderer - used to process property editor dependencies From 2f22313ceb3a260a2582eb5f24634639d05f7b85 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Sun, 23 Aug 2020 15:58:37 +0200 Subject: [PATCH 07/58] Restored Umbraco.Web and added temporary methods for converstion between legacy and new configuration models to maintain build. --- .../AspNetCoreConfigsFactory.cs | 1 + .../Umbraco.Configuration.csproj | 10 -- .../MemberPasswordConfigurationSettings.cs | 5 +- .../UserPasswordConfigurationSettings.cs | 5 +- .../Umbraco.Infrastructure.csproj | 1 - .../Building/Builder.cs | 5 +- .../Building/ModelsGenerator.cs | 8 +- .../Building/TextBuilder.cs | 3 +- .../Compose/ModelsBuilderComposer.cs | 15 ++- .../ModelsGenerationError.cs | 8 +- .../OutOfDateModelsStatus.cs | 5 +- .../PureLiveModelFactory.cs | 8 +- .../UmbracoCoreServiceCollectionExtensions.cs | 4 + src/Umbraco.Web/AppBuilderExtensions.cs | 5 +- .../Compose/AuditEventsComponent.cs | 3 +- .../Configuration/ConfigModelConversions.cs | 99 +++++++++++++++++++ .../Editors/BackOfficeController.cs | 5 +- .../Editors/BackOfficeServerVariables.cs | 7 +- .../Mvc/AreaRegistrationExtensions.cs | 3 +- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 3 +- .../Mvc/UmbracoAuthorizeAttribute.cs | 3 +- .../Runtime/WebInitialComponent.cs | 5 +- .../Security/BackOfficeOwinUserManager.cs | 11 ++- .../Security/BackOfficeSignInManager.cs | 3 +- .../Security/GetUserSecondsMiddleWare.cs | 3 +- src/Umbraco.Web/Umbraco.Web.csproj | 1 + src/Umbraco.Web/UmbracoApplication.cs | 7 +- src/Umbraco.Web/UmbracoApplicationBase.cs | 7 +- src/Umbraco.Web/UmbracoContext.cs | 3 +- src/Umbraco.Web/UmbracoInjectedModule.cs | 7 +- .../CheckIfUserTicketDataIsStaleAttribute.cs | 3 +- 31 files changed, 187 insertions(+), 69 deletions(-) create mode 100644 src/Umbraco.Web/Configuration/ConfigModelConversions.cs diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index d8b5e666b9..f957074881 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -3,6 +3,7 @@ using Umbraco.Configuration.Models; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; +using CoreDebugSettings = Umbraco.Configuration.Models.CoreDebugSettings; namespace Umbraco.Configuration { diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index 8d7a0e7f01..a4dac22386 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -10,25 +10,15 @@ - - - - - - - - - - diff --git a/src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs b/src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs index 1f2808ef7e..52bba6f4b8 100644 --- a/src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/MemberPasswordConfigurationSettings.cs @@ -1,7 +1,4 @@ -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class MemberPasswordConfigurationSettings : IPasswordConfiguration { diff --git a/src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs b/src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs index a0c26b2410..445a0f545c 100644 --- a/src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/UserPasswordConfigurationSettings.cs @@ -1,7 +1,4 @@ -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class UserPasswordConfigurationSettings : IPasswordConfiguration { diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index fa0ac89c61..d9cd6bf498 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -97,7 +97,6 @@ - diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs index f64e5ed1ce..dc093d3c2d 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/Builder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -70,7 +71,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building /// /// The list of models to generate. /// The models namespace. - protected Builder(IModelsBuilderConfig config, IList typeModels) + protected Builder(ModelsBuilderConfig config, IList typeModels) { _typeModels = typeModels ?? throw new ArgumentNullException(nameof(typeModels)); @@ -87,7 +88,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building protected Builder() { } - protected IModelsBuilderConfig Config { get; } + protected ModelsBuilderConfig Config { get; } /// /// Prepares generation by processing the result of code parsing. diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs index 648a2e76fa..1572fc9b92 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs @@ -1,6 +1,8 @@ using System.IO; using System.Text; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded.Building @@ -8,14 +10,14 @@ namespace Umbraco.ModelsBuilder.Embedded.Building public class ModelsGenerator { private readonly UmbracoServices _umbracoService; - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly IIOHelper _ioHelper; - public ModelsGenerator(UmbracoServices umbracoService, IModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) + public ModelsGenerator(UmbracoServices umbracoService, IOptionsSnapshot config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) { _umbracoService = umbracoService; - _config = config; + _config = config.Value; _outOfDateModels = outOfDateModels; _ioHelper = ioHelper; } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs index 723ee10f35..9a2ad6f600 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/TextBuilder.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.Building { @@ -17,7 +18,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building /// and the result of code parsing. /// /// The list of models to generate. - public TextBuilder(IModelsBuilderConfig config, IList typeModels) + public TextBuilder(ModelsBuilderConfig config, IList typeModels) : base(config, typeModels) { } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs index e582301740..3873080605 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs @@ -6,15 +6,22 @@ using Umbraco.Core.Logging; using Umbraco.Core.Composing; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded.Compose { - - [ComposeBefore(typeof(IPublishedCacheComposer))] [RuntimeLevel(MinLevel = RuntimeLevel.Run)] public sealed class ModelsBuilderComposer : ICoreComposer { + private readonly ModelsBuilderConfig _config; + + public ModelsBuilderComposer(IOptionsSnapshot config) + { + _config = config.Value; + } + public void Compose(Composition composition) { var isLegacyModelsBuilderInstalled = IsLegacyModelsBuilderInstalled(); @@ -32,9 +39,9 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose composition.RegisterUnique(); composition.RegisterUnique(); - if (composition.Configs.ModelsBuilder().ModelsMode == ModelsMode.PureLive) + if (_config.ModelsMode == ModelsMode.PureLive) ComposeForLiveModels(composition); - else if (composition.Configs.ModelsBuilder().EnableFactory) + else if (_config.EnableFactory) ComposeForDefaultModelsFactory(composition); } diff --git a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs index f8f6e8c7bc..92c73e2c6d 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs @@ -1,19 +1,21 @@ using System; using System.IO; using System.Text; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded { public sealed class ModelsGenerationError { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public ModelsGenerationError(IModelsBuilderConfig config, IIOHelper ioHelper) + public ModelsGenerationError(IOptionsSnapshot config, IIOHelper ioHelper) { - _config = config; + _config = config.Value; _ioHelper = ioHelper; } diff --git a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs index b8105eeef2..4fb23ad5b3 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs @@ -1,5 +1,6 @@ using System.IO; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Cache; @@ -7,10 +8,10 @@ namespace Umbraco.ModelsBuilder.Embedded { public sealed class OutOfDateModelsStatus { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public OutOfDateModelsStatus(IModelsBuilderConfig config, IIOHelper ioHelper) + public OutOfDateModelsStatus(ModelsBuilderConfig config, IIOHelper ioHelper) { _config = config; _ioHelper = ioHelper; diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index 7809d2bf48..da48621c7d 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -19,6 +19,8 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; using File = System.IO.File; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded { @@ -41,7 +43,7 @@ namespace Umbraco.ModelsBuilder.Embedded private const string ProjVirt = "~/App_Data/Models/all.generated.cs"; private static readonly string[] OurFiles = { "models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err" }; - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IApplicationShutdownRegistry _hostingLifetime; private readonly IIOHelper _ioHelper; private readonly ModelsGenerationError _errors; @@ -49,14 +51,14 @@ namespace Umbraco.ModelsBuilder.Embedded public PureLiveModelFactory( Lazy umbracoServices, IProfilingLogger logger, - IModelsBuilderConfig config, + IOptionsSnapshot config, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IIOHelper ioHelper) { _umbracoServices = umbracoServices; _logger = logger; - _config = config; + _config = config.Value; _hostingLifetime = hostingLifetime; _ioHelper = ioHelper; _errors = new ModelsGenerationError(config, ioHelper); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 1c7f8156f4..4653bc7bbd 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -28,6 +28,7 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Runtime; using Umbraco.Web.Common.AspNetCore; using Umbraco.Web.Common.Profiler; +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; namespace Umbraco.Extensions @@ -124,6 +125,9 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigModelsBuilderPrefix)); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging:")); + // TODO: HealthChecksSettings (+ one other?) + + // TODO: remove this var configsFactory = new AspNetCoreConfigsFactory(configuration); var configs = configsFactory.Create(); services.AddSingleton(configs); diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index c8c6cbdf5c..18eb3a54fe 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -4,8 +4,7 @@ using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Web.Composing; +using Umbraco.Web.Configuration; using Umbraco.Web.Logging; namespace Umbraco.Web @@ -48,7 +47,7 @@ namespace Umbraco.Web /// public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true }); } diff --git a/src/Umbraco.Web/Compose/AuditEventsComponent.cs b/src/Umbraco.Web/Compose/AuditEventsComponent.cs index 51c47233c7..9b9a1671f3 100644 --- a/src/Umbraco.Web/Compose/AuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/AuditEventsComponent.cs @@ -11,6 +11,7 @@ using Umbraco.Net; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Extensions; +using Umbraco.Web.Configuration; namespace Umbraco.Core.Compose { @@ -49,7 +50,7 @@ namespace Umbraco.Core.Compose public void Terminate() { } - public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(globalSettings) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; + public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(ConfigModelConversions.ConvertGlobalSettings(globalSettings)) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; private IUser CurrentPerformingUser { diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs new file mode 100644 index 0000000000..752983c7c9 --- /dev/null +++ b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs @@ -0,0 +1,99 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; +using Umbraco.Core; +using Umbraco.Core.BackOffice; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Web.Configuration +{ + /// + /// TEMPORARY: this class has been added just to ensure Umbraco.Web functionality continues to compile, by + /// converting between (used by + /// legacy configuration and (used by Netcore/IOptions configuration). + /// + public static class ConfigModelConversions + { + public static GlobalSettings ConvertGlobalSettings(IGlobalSettings globalSettings) + { + return new GlobalSettings + { + DatabaseFactoryServerVersion = globalSettings.DatabaseFactoryServerVersion, + DefaultUILanguage = globalSettings.DefaultUILanguage, + DisableElectionForSingleServer = globalSettings.DisableElectionForSingleServer, + HideTopLevelNodeFromPath = globalSettings.HideTopLevelNodeFromPath, + InstallEmptyDatabase = globalSettings.InstallEmptyDatabase, + InstallMissingDatabase = globalSettings.InstallMissingDatabase, + MainDomLock = globalSettings.MainDomLock, + NoNodesViewPath = globalSettings.NoNodesViewPath, + RegisterType = globalSettings.RegisterType, + ReservedPaths = globalSettings.ReservedPaths, + ReservedUrls = globalSettings.ReservedUrls, + SmtpSettings = new SmtpSettings + { + DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, + From = globalSettings.SmtpSettings.From, + Host = globalSettings.SmtpSettings.Host, + Password = globalSettings.SmtpSettings.Password, + PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, + Port = globalSettings.SmtpSettings.Port, + Username = globalSettings.SmtpSettings.Username, + }, + TimeOutInMinutes = globalSettings.TimeOutInMinutes, + UmbracoCssPath = globalSettings.UmbracoCssPath, + UmbracoMediaPath = globalSettings.UmbracoMediaPath, + UmbracoPath = globalSettings.UmbracoPath, + UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, + UseHttps = globalSettings.UseHttps, + VersionCheckPeriod = globalSettings.VersionCheckPeriod, + }; + } + + public static Umbraco.Core.Configuration.Models.ConnectionStrings ConvertConnectionStrings(IConnectionStrings connectionStrings) + { + return new Umbraco.Core.Configuration.Models.ConnectionStrings + { + UmbracoConnectionString = connectionStrings[Constants.System.UmbracoConnectionName].ConnectionString + }; + } + + public static IOptions ConvertToOptionsOfUserPasswordConfigurationSettings(IOptions identityOptions) + { + var passwordOptions = identityOptions.Value.Password; + var lockOutOptions = identityOptions.Value.Lockout; + var passwordConfiguration = new UserPasswordConfigurationSettings + { + MaxFailedAccessAttemptsBeforeLockout = lockOutOptions.MaxFailedAccessAttempts, + HashAlgorithmType = Constants.Security.AspNetCoreV3PasswordHashAlgorithmName, // TODO: not sure where to map this from. + RequireDigit = passwordOptions.RequireDigit, + RequiredLength = passwordOptions.RequiredLength, + RequireLowercase = passwordOptions.RequireLowercase, + RequireNonLetterOrDigit = passwordOptions.RequireNonAlphanumeric, + RequireUppercase = passwordOptions.RequireUppercase, + }; + + return Options.Create(passwordConfiguration); + } + + public static IOptions ConvertToOptionsOfBackOfficeIdentityOptions(IUserPasswordConfiguration passwordConfiguration) + { + var identityOptions = new BackOfficeIdentityOptions + { + Lockout = new LockoutOptions + { + MaxFailedAccessAttempts = passwordConfiguration.MaxFailedAccessAttemptsBeforeLockout, + }, + Password = new PasswordOptions + { + RequireDigit = passwordConfiguration.RequireDigit, + RequiredLength = passwordConfiguration.RequiredLength, + RequireLowercase = passwordConfiguration.RequireLowercase, + RequireNonAlphanumeric = passwordConfiguration.RequireNonLetterOrDigit, + RequireUppercase = passwordConfiguration.RequireUppercase, + } + }; + + return Options.Create(identityOptions); + } + } +} diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index b963871a58..3106d02dc8 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Web.Mvc; using Umbraco.Core.Services; +using Umbraco.Web.Configuration; using Umbraco.Web.Features; using Umbraco.Web.Security; using Constants = Umbraco.Core.Constants; @@ -139,7 +140,7 @@ namespace Umbraco.Web.Editors if (defaultResponse == null) throw new ArgumentNullException("defaultResponse"); if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse"); - ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(_hostingEnvironment)); + ViewData.SetUmbracoPath(ConfigModelConversions.ConvertGlobalSettings(GlobalSettings).GetUmbracoMvcArea(_hostingEnvironment)); //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) || @@ -254,7 +255,7 @@ namespace Umbraco.Web.Editors var groups = Services.UserService.GetUserGroupsByAlias(autoLinkOptions.GetDefaultUserGroups(UmbracoContext, loginInfo)); var autoLinkUser = BackOfficeIdentityUser.CreateNew( - GlobalSettings, + ConfigModelConversions.ConvertGlobalSettings(GlobalSettings), loginInfo.Email, loginInfo.Email, autoLinkOptions.GetDefaultCulture(UmbracoContext, loginInfo)); diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 454338112c..ec8d7e5dd5 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -7,6 +7,7 @@ using System.Web; using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Web.Configuration; using Umbraco.Web.Features; using Umbraco.Web.HealthCheck; using Umbraco.Web.Models.ContentEditing; @@ -143,7 +144,7 @@ namespace Umbraco.Web.Editors { "umbracoSettings", new Dictionary { - {"umbracoPath", _globalSettings.GetBackOfficePath(_hostingEnvironment)}, + {"umbracoPath", ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}, {"mediaPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath).TrimEnd('/')}, {"appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd('/')}, { @@ -167,8 +168,8 @@ namespace Umbraco.Web.Editors {"cssPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoCssPath).TrimEnd('/')}, {"allowPasswordReset", _securitySettings.AllowPasswordReset}, {"loginBackgroundImage", _contentSettings.LoginBackgroundImage}, - {"showUserInvite", EmailSender.CanSendRequiredEmail(globalSettings)}, - {"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(globalSettings)}, + {"showUserInvite", EmailSender.CanSendRequiredEmail(ConfigModelConversions.ConvertGlobalSettings(globalSettings))}, + {"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(ConfigModelConversions.ConvertGlobalSettings(globalSettings))}, {"showAllowSegmentationForDocumentTypes", false}, } }, diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 118c53a7f0..eee675e9fd 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Web.Composing; +using Umbraco.Web.Configuration; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -60,7 +61,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(hostingEnvironment); + var umbracoArea = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); //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 156a896bb5..4a4202b42b 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -3,6 +3,7 @@ using Umbraco.Web.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; +using Umbraco.Web.Configuration; using Umbraco.Web.Editors; namespace Umbraco.Web.Mvc @@ -50,6 +51,6 @@ namespace Umbraco.Web.Mvc new[] {typeof (BackOfficeController).Namespace}); } - public override string AreaName => _globalSettings.GetUmbracoMvcArea(_hostingEnvironment); + public override string AreaName => ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetUmbracoMvcArea(_hostingEnvironment); } } diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index b5c6185069..9fc58a208f 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -4,6 +4,7 @@ using System.Web.Mvc; using Umbraco.Core; using Umbraco.Web.Composing; using Umbraco.Core.Configuration; +using Umbraco.Web.Configuration; using Umbraco.Web.Security; namespace Umbraco.Web.Mvc @@ -55,7 +56,7 @@ namespace Umbraco.Web.Mvc { if (redirectToUmbracoLogin) { - _redirectUrl = Current.Configs.Global().GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); + _redirectUrl = ConfigModelConversions.ConvertGlobalSettings(Current.Configs.Global()).GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index dbd0a1fb3a..5ad51acbc0 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Strings; using Umbraco.Core.IO; +using Umbraco.Web.Configuration; using Umbraco.Web.Install; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; @@ -117,7 +118,7 @@ namespace Umbraco.Web.Runtime UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); // create the front-end route var defaultRoute = RouteTable.Routes.MapRoute( @@ -154,7 +155,7 @@ namespace Umbraco.Web.Runtime UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); // need to find the plugin controllers and route them var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray(); diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index 771c3239b6..92e4fca420 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Mapping; using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Net; +using Umbraco.Web.Configuration; namespace Umbraco.Web.Security { @@ -20,7 +21,7 @@ namespace Umbraco.Web.Security public const string OwinMarkerKey = "Umbraco.Web.Security.Identity.BackOfficeUserManagerMarker"; public BackOfficeOwinUserManager( - IUserPasswordConfiguration passwordConfiguration, + IOptions passwordConfiguration, IIpResolver ipResolver, IUserStore store, IOptions optionsAccessor, @@ -30,9 +31,9 @@ namespace Umbraco.Web.Security BackOfficeIdentityErrorDescriber errors, IDataProtectionProvider dataProtectionProvider, ILogger> logger) - : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, passwordConfiguration) + : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, ConfigModelConversions.ConvertToOptionsOfUserPasswordConfigurationSettings(passwordConfiguration)) { - PasswordConfiguration = passwordConfiguration; + PasswordConfiguration = ConfigModelConversions.ConvertToOptionsOfUserPasswordConfigurationSettings(passwordConfiguration).Value; InitUserManager(this, dataProtectionProvider); } @@ -53,7 +54,7 @@ namespace Umbraco.Web.Security IDataProtectionProvider dataProtectionProvider, ILogger> logger) { - var store = new BackOfficeUserStore(userService, entityService, externalLoginService, globalSettings, mapper); + var store = new BackOfficeUserStore(userService, entityService, externalLoginService, ConfigModelConversions.ConvertGlobalSettings(globalSettings), mapper); return Create( passwordConfiguration, @@ -103,7 +104,7 @@ namespace Umbraco.Web.Security options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(30); return new BackOfficeOwinUserManager( - passwordConfiguration, + ConfigModelConversions.ConvertToOptionsOfBackOfficeIdentityOptions(passwordConfiguration), ipResolver, customUserStore, new OptionsWrapper(options), diff --git a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs index 021adaed97..c998b579a1 100644 --- a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs @@ -11,6 +11,7 @@ using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.BackOffice; +using Umbraco.Web.Configuration; namespace Umbraco.Web.Security { @@ -78,7 +79,7 @@ namespace Umbraco.Web.Security var user = await _userManager.FindByNameAsync(userName); //if the user is null, create an empty one which can be used for auto-linking - if (user == null) user = BackOfficeIdentityUser.CreateNew(_globalSettings, userName, null, _globalSettings.DefaultUILanguage); + if (user == null) user = BackOfficeIdentityUser.CreateNew(ConfigModelConversions.ConvertGlobalSettings(_globalSettings), userName, null, _globalSettings.DefaultUILanguage); //check the password for the user, this will allow a developer to auto-link //an account if they have specified an IBackOfficeUserPasswordChecker diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index 3ab37f0f70..f73f25f859 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Security; +using Umbraco.Web.Configuration; namespace Umbraco.Web.Security { @@ -53,7 +54,7 @@ namespace Umbraco.Web.Security if (request.Uri.Scheme.InvariantStartsWith("http") && request.Uri.AbsolutePath.InvariantEquals( - $"{_globalSettings.GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) + $"{ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) { var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName); if (cookie.IsNullOrWhiteSpace() == false) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 64fc7b5886..82af69a21c 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -148,6 +148,7 @@ + diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 6334f96d4b..4cdcecc1ce 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Web.Runtime; +using Umbraco.Web.Configuration; namespace Umbraco.Web { @@ -29,8 +30,8 @@ namespace Umbraco.Web var dbProviderFactoryCreator = new UmbracoDbProviderFactoryCreator(); - var globalSettings = configs.Global(); - var connectionStrings = configs.ConnectionStrings(); + var globalSettings = ConfigModelConversions.ConvertGlobalSettings(configs.Global()); + var connectionStrings = ConfigModelConversions.ConvertConnectionStrings(configs.ConnectionStrings()); // Determine if we should use the sql main dom or the default var appSettingMainDomLock = globalSettings.MainDomLock; @@ -44,7 +45,7 @@ namespace Umbraco.Web var requestCache = new HttpRequestAppCache(() => HttpContext.Current != null ? HttpContext.Current.Items : null); var umbracoBootPermissionChecker = new AspNetUmbracoBootPermissionChecker(); - return new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, + return new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, GetTypeFinder(hostingEnvironment, logger, profiler), requestCache); } diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 1c447b38aa..984f46bd60 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Logging.Serilog.Enrichers; using Umbraco.Net; using Umbraco.Web.AspNet; +using Umbraco.Web.Configuration; using Umbraco.Web.Hosting; using Umbraco.Web.Logging; using Current = Umbraco.Web.Composing.Current; @@ -44,7 +45,7 @@ namespace Umbraco.Web Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "App_Data\\Logs"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.config"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.user.config")); - var ioHelper = new IOHelper(hostingEnvironment, globalSettings); + var ioHelper = new IOHelper(hostingEnvironment); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration); var configs = configFactory.Create(); @@ -127,7 +128,7 @@ namespace Umbraco.Web /// protected virtual IRegister GetRegister(IGlobalSettings globalSettings) { - return RegisterFactory.Create(globalSettings); + return RegisterFactory.Create(ConfigModelConversions.ConvertGlobalSettings(globalSettings)); } // events - in the order they trigger @@ -160,7 +161,7 @@ namespace Umbraco.Web var globalSettings = Umbraco.Composing.Current.Configs.Global(); - var umbracoVersion = new UmbracoVersion(globalSettings); + var umbracoVersion = new UmbracoVersion(ConfigModelConversions.ConvertGlobalSettings(globalSettings)); // create the register for the application, and boot // the boot manager is responsible for registrations diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index ae1cf885b3..e94e0acc0b 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; +using Umbraco.Web.Configuration; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -181,7 +182,7 @@ namespace Umbraco.Web { var request = GetRequestFromContext(); if (request?.Url != null - && request.Url.IsBackOfficeRequest(_globalSettings, _hostingEnvironment) == false + && request.Url.IsBackOfficeRequest(ConfigModelConversions.ConvertGlobalSettings(_globalSettings), _hostingEnvironment) == false && Security.CurrentUser != null) { var previewToken = _cookieManager.GetPreviewCookieValue(); // may be null or empty diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index ecb67c997d..a610d216a3 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Logging; using Umbraco.Web.Composing; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Umbraco.Web.Configuration; namespace Umbraco.Web { @@ -113,7 +114,7 @@ namespace Umbraco.Web var umbracoContext = Current.UmbracoContext; // re-write for the default back office path - if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_globalSettings, _hostingEnvironment)) + if (httpContext.Request.Url.IsDefaultBackOfficeRequest(ConfigModelConversions.ConvertGlobalSettings(_globalSettings), _hostingEnvironment)) { if (EnsureRuntime(httpContext, umbracoContext.OriginalRequestUrl)) RewriteToBackOfficeHandler(httpContext); @@ -246,7 +247,7 @@ namespace Umbraco.Web private void RewriteToBackOfficeHandler(HttpContextBase context) { // GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any) - var rewritePath = _globalSettings.GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default"; + var rewritePath = ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default"; // rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc) context.RewritePath(rewritePath, "", "", false); @@ -279,7 +280,7 @@ namespace Umbraco.Web var query = pcr.Uri.Query.TrimStart('?'); // GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any) - var rewritePath = _globalSettings.GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc"; + var rewritePath = ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc"; // rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc) context.RewritePath(rewritePath, "", query, false); diff --git a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index 09fd5e080c..bae6d00048 100644 --- a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Security; using Umbraco.Web.Security; using Umbraco.Core.Mapping; using Umbraco.Core.Models; +using Umbraco.Web.Configuration; namespace Umbraco.Web.WebApi.Filters { @@ -78,7 +79,7 @@ namespace Umbraco.Web.WebApi.Filters () => user.Username != identity.Username, () => { - var culture = user.GetUserCulture(Current.Services.TextService, Current.Configs.Global()); + var culture = user.GetUserCulture(Current.Services.TextService, ConfigModelConversions.ConvertGlobalSettings(Current.Configs.Global())); return culture != null && culture.ToString() != identity.Culture; }, () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, From 2cd91a5a542c7adea172dfec8569f6d8b67e2753 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Sun, 23 Aug 2020 23:36:48 +0200 Subject: [PATCH 08/58] Converted to IOptions over IOptionsSnapshot due to the latter only working in scoped services. Further amends to return to booting application. --- .../BackOffice/IdentityMapDefinition.cs | 2 +- .../Configuration/Models/ContentSettings.cs | 4 +- .../Configuration/Models/ImagingSettings.cs | 4 +- .../Models/RequestHandlerSettings.cs | 74 +++++++++++++++++++ src/Umbraco.Core/IO/FileSystems.cs | 8 +- .../Packaging/PackagesRepository.cs | 2 +- src/Umbraco.Core/Routing/AliasUrlProvider.cs | 14 ++-- .../Routing/ContentFinderByIdPath.cs | 2 +- .../Routing/ContentFinderByUrlAndTemplate.cs | 2 +- .../Routing/DefaultUrlProvider.cs | 16 ++-- src/Umbraco.Core/Routing/PublishedRequest.cs | 2 +- src/Umbraco.Core/Routing/PublishedRouter.cs | 2 +- src/Umbraco.Core/Routing/UriUtility.cs | 3 +- src/Umbraco.Core/Routing/UrlProvider.cs | 2 +- src/Umbraco.Core/Scheduling/KeepAlive.cs | 2 +- .../Strings/DefaultShortStringHelper.cs | 6 +- .../Strings/DefaultShortStringHelperConfig.cs | 3 +- src/Umbraco.Core/Templates/HtmlUrlParser.cs | 2 +- .../LuceneIndexCreator.cs | 2 +- .../UmbracoIndexesCreator.cs | 2 +- .../BackOffice/BackOfficeUserStore.cs | 2 +- .../Compose/NotificationsComponent.cs | 2 +- .../CompositionExtensions/FileSystems.cs | 2 +- .../CompositionExtensions/Services.cs | 4 +- .../EmailNotificationMethod.cs | 4 +- .../Install/FilePermissionHelper.cs | 2 +- .../Install/InstallHelper.cs | 2 +- .../InstallSteps/DatabaseConfigureStep.cs | 2 +- .../InstallSteps/DatabaseUpgradeStep.cs | 4 +- .../Install/InstallSteps/NewInstallStep.cs | 6 +- .../Enrichers/ThreadAbortExceptionEnricher.cs | 2 +- .../Media/UploadAutoFillProperties.cs | 2 +- .../Migrations/Install/DatabaseBuilder.cs | 2 +- .../Mapping/ContentTypeMapDefinition.cs | 2 +- .../Models/Mapping/DataTypeMapDefinition.cs | 2 +- .../Mapping/MemberTabsAndPropertiesMapper.cs | 2 +- .../Models/Mapping/UserMapDefinition.cs | 2 +- .../Implement/LanguageRepository.cs | 2 +- .../Implement/ScriptRepository.cs | 2 +- .../Implement/StylesheetRepository.cs | 2 +- .../Repositories/Implement/UserRepository.cs | 4 +- .../FileUploadPropertyEditor.cs | 2 +- .../FileUploadPropertyValueEditor.cs | 2 +- .../ImageCropperPropertyEditor.cs | 2 +- .../UploadFileTypeValidator.cs | 2 +- .../Routing/ContentFinderByConfigured404.cs | 2 +- .../Routing/RedirectTrackingComponent.cs | 2 +- .../Runtime/CoreInitialComponent.cs | 3 +- .../Runtime/CoreInitialComposer.cs | 4 +- .../Scheduling/LogScrubber.cs | 2 +- .../Scheduling/SchedulerComponent.cs | 2 +- .../Scoping/ScopeProvider.cs | 2 +- .../Services/Implement/FileService.cs | 2 +- .../Services/Implement/NotificationService.cs | 2 +- .../Services/Implement/UserService.cs | 2 +- .../Users/EmailSender.cs | 4 +- .../WebAssets/BackOfficeWebAssets.cs | 2 +- .../Building/ModelsGenerator.cs | 2 +- .../Compose/ModelsBuilderComposer.cs | 2 +- .../ModelsGenerationError.cs | 2 +- .../PureLiveModelFactory.cs | 2 +- .../ContentCache.cs | 2 +- .../PublishedSnapshotService.cs | 4 +- .../Controllers/AuthenticationController.cs | 6 +- .../Controllers/BackOfficeAssetsController.cs | 2 +- .../Controllers/BackOfficeController.cs | 2 +- .../Controllers/BackOfficeServerVariables.cs | 8 +- .../Controllers/CodeFileController.cs | 2 +- .../Controllers/ContentTypeController.cs | 2 +- .../Controllers/CurrentUserController.cs | 2 +- .../Controllers/DataTypeController.cs | 2 +- .../Controllers/DictionaryController.cs | 2 +- .../Controllers/ImagesController.cs | 2 +- .../Controllers/LanguageController.cs | 2 +- .../Controllers/MediaController.cs | 2 +- .../Controllers/MemberController.cs | 2 +- .../Controllers/PreviewController.cs | 2 +- .../RedirectUrlManagementController.cs | 2 +- .../Controllers/TinyMceController.cs | 2 +- .../Controllers/TourController.cs | 2 +- .../Controllers/UpdateCheckController.cs | 4 +- .../Controllers/UsersController.cs | 6 +- ...coBackOfficeServiceCollectionExtensions.cs | 2 +- .../SetAngularAntiForgeryTokensAttribute.cs | 2 +- .../UmbracoWebApiRequireHttpsAttribute.cs | 2 +- .../Mapping/MediaMapDefinition.cs | 2 +- .../Routing/BackOfficeAreaRoutes.cs | 2 +- .../Security/BackOfficeSessionIdValidator.cs | 2 +- .../ConfigureBackOfficeCookieOptions.cs | 4 +- .../ConfigureBackOfficeIdentityOptions.cs | 2 +- .../PreviewAuthenticationMiddleware.cs | 2 +- .../Trees/ContentTreeController.cs | 2 +- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 2 +- .../AspNetCoreHostingEnvironment.cs | 2 +- .../AspNetCore/AspNetCoreRequestAccessor.cs | 2 +- .../AspNetCore/UmbracoViewPage.cs | 4 +- .../UmbracoCoreServiceCollectionExtensions.cs | 9 ++- .../UmbracoWebServiceCollectionExtensions.cs | 2 +- .../Filters/ModelBindingExceptionFilter.cs | 2 +- .../Filters/StatusCodeResultAttribute.cs | 2 +- .../Install/InstallController.cs | 2 +- .../Macros/MacroRenderer.cs | 2 +- .../Runtime/AspNetCoreComposer.cs | 2 +- .../Security/WebSecurity.cs | 2 +- .../Templates/TemplateRenderer.cs | 2 +- .../UmbracoContext/UmbracoContextFactory.cs | 2 +- .../umbraco/UmbracoBackOffice/Default.cshtml | 2 +- .../umbraco/UmbracoBackOffice/Preview.cshtml | 2 +- 108 files changed, 230 insertions(+), 146 deletions(-) create mode 100644 src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs diff --git a/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs b/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs index e002ea1c8d..61fdf82d19 100644 --- a/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs +++ b/src/Umbraco.Core/BackOffice/IdentityMapDefinition.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.BackOffice private readonly IEntityService _entityService; private readonly GlobalSettings _globalSettings; - public IdentityMapDefinition(ILocalizedTextService textService, IEntityService entityService, IOptionsSnapshot globalSettings) + public IdentityMapDefinition(ILocalizedTextService textService, IEntityService entityService, IOptions globalSettings) { _textService = textService; _entityService = entityService; diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index d1664c2985..4cc74f709a 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -11,9 +11,9 @@ namespace Umbraco.Core.Configuration.Models private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; - public ContentNotificationSettings Notifications { get; set; } + public ContentNotificationSettings Notifications { get; set; } = new ContentNotificationSettings(); - public ContentImagingSettings Imaging { get; set; } + public ContentImagingSettings Imaging { get; set; } = new ContentImagingSettings(); public bool ResolveUrlsFromTextString { get; set; } = false; diff --git a/src/Umbraco.Core/Configuration/Models/ImagingSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingSettings.cs index afc55561bb..2f253b151b 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingSettings.cs @@ -2,8 +2,8 @@ { public class ImagingSettings { - public ImagingCacheSettings Cache { get; set; } + public ImagingCacheSettings Cache { get; set; } = new ImagingCacheSettings(); - public ImagingResizeSettings Resize { get; set; } + public ImagingResizeSettings Resize { get; set; } = new ImagingResizeSettings(); } } diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs new file mode 100644 index 0000000000..f00658a0be --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Core.Configuration.Models +{ + public class RequestHandlerSettings + { + private const string Prefix = Constants.Configuration.ConfigPrefix + "RequestHandler:"; + private static readonly CharItem[] DefaultCharCollection = + { + new CharItem { Char = " ", Replacement = "-" }, + new CharItem { Char = "\"", Replacement = "" }, + new CharItem { Char = "'", Replacement = "" }, + new CharItem { Char = "%", Replacement = "" }, + new CharItem { Char = ".", Replacement = "" }, + new CharItem { Char = ";", Replacement = "" }, + new CharItem { Char = "/", Replacement = "" }, + new CharItem { Char = "\\", Replacement = "" }, + new CharItem { Char = ":", Replacement = "" }, + new CharItem { Char = "#", Replacement = "" }, + new CharItem { Char = "+", Replacement = "plus" }, + new CharItem { Char = "*", Replacement = "star" }, + new CharItem { Char = "&", Replacement = "" }, + new CharItem { Char = "?", Replacement = "" }, + new CharItem { Char = "æ", Replacement = "ae" }, + new CharItem { Char = "ä", Replacement = "ae" }, + new CharItem { Char = "ø", Replacement = "oe" }, + new CharItem { Char = "ö", Replacement = "oe" }, + new CharItem { Char = "å", Replacement = "aa" }, + new CharItem { Char = "ü", Replacement = "ue" }, + new CharItem { Char = "ß", Replacement = "ss" }, + new CharItem { Char = "|", Replacement = "-" }, + new CharItem { Char = "<", Replacement = "" }, + new CharItem { Char = ">", Replacement = "" } + }; + + public bool AddTrailingSlash { get; set; } = true; + + public bool ConvertUrlsToAscii { get; set; } = true; + + public bool TryConvertUrlsToAscii { get; set; } = false; + + //We need to special handle ":", as this character is special in keys + public IEnumerable CharCollection + { + get + { + // TODO: implement from configuration + + //var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren() + // .Select(x => new CharItem() + // { + // Char = x.GetValue("Char"), + // Replacement = x.GetValue("Replacement"), + // }).ToArray(); + + //if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x => + // x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase))) + //{ + // return collection; + //} + + return DefaultCharCollection; + } + } + + + public class CharItem : IChar + { + public string Char { get; set; } + public string Replacement { get; set; } + } + } +} diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Core/IO/FileSystems.cs index ba5fcb91f3..505f714620 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Core/IO/FileSystems.cs @@ -6,6 +6,8 @@ using Umbraco.Core.Logging; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Core.IO { @@ -36,12 +38,12 @@ namespace Umbraco.Core.IO #region Constructor // DI wants a public ctor - public FileSystems(IFactory container, ILogger logger, IIOHelper ioHelper, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public FileSystems(IFactory container, ILogger logger, IIOHelper ioHelper, IOptions globalSettings, IHostingEnvironment hostingEnvironment) { _container = container; _logger = logger; _ioHelper = ioHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; } @@ -156,7 +158,7 @@ namespace Umbraco.Core.IO // internal for tests internal IReadOnlyDictionary Paths => _paths; - private IGlobalSettings _globalSettings; + private GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; /// diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index b73747fab8..d9c802121d 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -63,7 +63,7 @@ namespace Umbraco.Core.Packaging IHostingEnvironment hostingEnvironment, IEntityXmlSerializer serializer, ILogger logger, IUmbracoVersion umbracoVersion, - IOptionsSnapshot globalSettings, + IOptions globalSettings, string packageRepositoryFileName, string tempFolderPath = null, string packagesFolderPath = null, string mediaFolderPath = null) { diff --git a/src/Umbraco.Core/Routing/AliasUrlProvider.cs b/src/Umbraco.Core/Routing/AliasUrlProvider.cs index e71de2f6c6..0d919614f3 100644 --- a/src/Umbraco.Core/Routing/AliasUrlProvider.cs +++ b/src/Umbraco.Core/Routing/AliasUrlProvider.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; @@ -13,17 +15,15 @@ namespace Umbraco.Web.Routing /// public class AliasUrlProvider : IUrlProvider { - private readonly IGlobalSettings _globalSettings; - private readonly IRequestHandlerSettings _requestConfig; + private readonly RequestHandlerSettings _requestConfig; private readonly ISiteDomainHelper _siteDomainHelper; private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly UriUtility _uriUtility; private readonly IPublishedValueFallback _publishedValueFallback; - public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSettings requestConfig, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback, IUmbracoContextAccessor umbracoContextAccessor) + public AliasUrlProvider(IOptions requestConfig, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback, IUmbracoContextAccessor umbracoContextAccessor) { - _globalSettings = globalSettings; - _requestConfig = requestConfig; + _requestConfig = requestConfig.Value; _siteDomainHelper = siteDomainHelper; _uriUtility = uriUtility; _publishedValueFallback = publishedValueFallback; @@ -100,7 +100,7 @@ namespace Umbraco.Web.Routing { var path = "/" + alias; var uri = new Uri(path, UriKind.Relative); - yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString()); + yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _requestConfig).ToString()); } } else @@ -127,7 +127,7 @@ namespace Umbraco.Web.Routing { var path = "/" + alias; var uri = new Uri(CombinePaths(domainUri.Uri.GetLeftPart(UriPartial.Path), path)); - yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString(), domainUri.Culture.Name); + yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _requestConfig).ToString(), domainUri.Culture.Name); } } } diff --git a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs index 3d69f8ab46..a9d67c24fb 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.Routing private readonly IRequestAccessor _requestAccessor; private readonly WebRoutingSettings _webRoutingSettings; - public ContentFinderByIdPath(IOptionsSnapshot webRoutingSettings, ILogger logger, IRequestAccessor requestAccessor) + public ContentFinderByIdPath(IOptions webRoutingSettings, ILogger logger, IRequestAccessor requestAccessor) { _webRoutingSettings = webRoutingSettings.Value ?? throw new System.ArgumentNullException(nameof(webRoutingSettings)); _logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs b/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs index 47dc729654..b6a01c0c51 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Routing private readonly IContentTypeService _contentTypeService; private readonly WebRoutingSettings _webRoutingSettings; - public ContentFinderByUrlAndTemplate(ILogger logger, IFileService fileService, IContentTypeService contentTypeService, IOptionsSnapshot webRoutingSettings) + public ContentFinderByUrlAndTemplate(ILogger logger, IFileService fileService, IContentTypeService contentTypeService, IOptions webRoutingSettings) : base(logger) { _fileService = fileService; diff --git a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs index f56d96b6b3..2af36465dd 100644 --- a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; @@ -12,18 +14,18 @@ namespace Umbraco.Web.Routing /// public class DefaultUrlProvider : IUrlProvider { - private readonly IRequestHandlerSettings _requestSettings; + private readonly RequestHandlerSettings _requestSettings; private readonly ILogger _logger; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly ISiteDomainHelper _siteDomainHelper; private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly UriUtility _uriUtility; - public DefaultUrlProvider(IRequestHandlerSettings requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility) + public DefaultUrlProvider(IOptions requestSettings, ILogger logger, IOptions globalSettings, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility) { - _requestSettings = requestSettings; + _requestSettings = requestSettings.Value; _logger = logger; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _siteDomainHelper = siteDomainHelper; _uriUtility = uriUtility; _umbracoContextAccessor = umbracoContextAccessor; @@ -113,7 +115,7 @@ namespace Umbraco.Web.Routing var path = pos == 0 ? route : route.Substring(pos); var uri = new Uri(CombinePaths(d.Uri.GetLeftPart(UriPartial.Path), path)); - uri = _uriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings); + uri = _uriUtility.UriFromUmbraco(uri, _requestSettings); yield return UrlInfo.Url(uri.ToString(), culture); } } @@ -172,7 +174,7 @@ namespace Umbraco.Web.Routing // UriFromUmbraco will handle vdir // meaning it will add vdir into domain urls too! - return _uriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings); + return _uriUtility.UriFromUmbraco(uri, _requestSettings); } string CombinePaths(string path1, string path2) diff --git a/src/Umbraco.Core/Routing/PublishedRequest.cs b/src/Umbraco.Core/Routing/PublishedRequest.cs index 7400623a6f..d1bf6fda0f 100644 --- a/src/Umbraco.Core/Routing/PublishedRequest.cs +++ b/src/Umbraco.Core/Routing/PublishedRequest.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Routing /// The published router. /// The Umbraco context. /// The request Uri. - public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IOptionsSnapshot webRoutingSettings, Uri uri = null) + public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IOptions webRoutingSettings, Uri uri = null) : this(publishedRouter, umbracoContext, webRoutingSettings.Value, uri) { } diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs index d77f64ca5e..207e8d7ed4 100644 --- a/src/Umbraco.Core/Routing/PublishedRouter.cs +++ b/src/Umbraco.Core/Routing/PublishedRouter.cs @@ -38,7 +38,7 @@ namespace Umbraco.Web.Routing /// Initializes a new instance of the class. /// public PublishedRouter( - IOptionsSnapshot webRoutingSettings, + IOptions webRoutingSettings, ContentFinderCollection contentFinders, IContentLastChanceFinder contentLastChanceFinder, IVariationContextAccessor variationContextAccessor, diff --git a/src/Umbraco.Core/Routing/UriUtility.cs b/src/Umbraco.Core/Routing/UriUtility.cs index 1ff6ba7436..1bcfab6490 100644 --- a/src/Umbraco.Core/Routing/UriUtility.cs +++ b/src/Umbraco.Core/Routing/UriUtility.cs @@ -2,6 +2,7 @@ using System.Text; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; @@ -62,7 +63,7 @@ namespace Umbraco.Web // maps an internal umbraco uri to a public uri // ie with virtual directory, .aspx if required... - public Uri UriFromUmbraco(Uri uri, IGlobalSettings globalSettings, IRequestHandlerSettings requestConfig) + public Uri UriFromUmbraco(Uri uri, RequestHandlerSettings requestConfig) { var path = uri.GetSafeAbsolutePath(); diff --git a/src/Umbraco.Core/Routing/UrlProvider.cs b/src/Umbraco.Core/Routing/UrlProvider.cs index 9e1dd9a01d..6ad44c7716 100644 --- a/src/Umbraco.Core/Routing/UrlProvider.cs +++ b/src/Umbraco.Core/Routing/UrlProvider.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.Routing /// The list of media url providers. /// The current variation accessor. /// - public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IOptionsSnapshot routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor) + public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IOptions routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor) { if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings)); diff --git a/src/Umbraco.Core/Scheduling/KeepAlive.cs b/src/Umbraco.Core/Scheduling/KeepAlive.cs index d085569e97..dec9d9daad 100644 --- a/src/Umbraco.Core/Scheduling/KeepAlive.cs +++ b/src/Umbraco.Core/Scheduling/KeepAlive.cs @@ -20,7 +20,7 @@ namespace Umbraco.Web.Scheduling private static HttpClient _httpClient; public KeepAlive(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IRequestAccessor requestAccessor, IMainDom mainDom, IOptionsSnapshot keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) + IRequestAccessor requestAccessor, IMainDom mainDom, IOptions keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) : this(runner, delayMilliseconds, periodMilliseconds, requestAccessor, mainDom, keepAliveSettings.Value, logger, serverRegistrar) { } diff --git a/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs b/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs index c3e7fa85c3..3894525d2d 100644 --- a/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs +++ b/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs @@ -4,6 +4,8 @@ using System.IO; using System.Linq; using System.Globalization; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Core.Strings { @@ -19,9 +21,9 @@ namespace Umbraco.Core.Strings { #region Ctor, consts and vars - public DefaultShortStringHelper(IRequestHandlerSettings settings) + public DefaultShortStringHelper(IOptions settings) { - _config = new DefaultShortStringHelperConfig().WithDefault(settings); + _config = new DefaultShortStringHelperConfig().WithDefault(settings.Value); } // clones the config so it cannot be changed at runtime diff --git a/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs b/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs index 25ee781ae9..32c02c09fb 100644 --- a/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs +++ b/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Core.Strings @@ -57,7 +58,7 @@ namespace Umbraco.Core.Strings /// Sets the default configuration. /// /// The short string helper. - public DefaultShortStringHelperConfig WithDefault(IRequestHandlerSettings requestHandlerSettings) + public DefaultShortStringHelperConfig WithDefault(RequestHandlerSettings requestHandlerSettings) { UrlReplaceCharacters = requestHandlerSettings.CharCollection .Where(x => string.IsNullOrEmpty(x.Char) == false) diff --git a/src/Umbraco.Core/Templates/HtmlUrlParser.cs b/src/Umbraco.Core/Templates/HtmlUrlParser.cs index 8a6baa0aa3..60b6f829b0 100644 --- a/src/Umbraco.Core/Templates/HtmlUrlParser.cs +++ b/src/Umbraco.Core/Templates/HtmlUrlParser.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.Templates private static readonly Regex ResolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); - public HtmlUrlParser(IOptionsSnapshot contentSettings, IProfilingLogger logger, IIOHelper ioHelper) + public HtmlUrlParser(IOptions contentSettings, IProfilingLogger logger, IIOHelper ioHelper) { _contentSettings = contentSettings.Value; _ioHelper = ioHelper; diff --git a/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs b/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs index 6edbb05b85..5c6b111d87 100644 --- a/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs +++ b/src/Umbraco.Examine.Lucene/LuceneIndexCreator.cs @@ -22,7 +22,7 @@ namespace Umbraco.Examine private readonly IHostingEnvironment _hostingEnvironment; private readonly IndexCreatorSettings _settings; - protected LuceneIndexCreator(ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IOptionsSnapshot settings) + protected LuceneIndexCreator(ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IOptions settings) { _typeFinder = typeFinder; _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs b/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs index 09dc40b32b..c4eb2249fa 100644 --- a/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs +++ b/src/Umbraco.Examine.Lucene/UmbracoIndexesCreator.cs @@ -30,7 +30,7 @@ namespace Umbraco.Examine IUmbracoIndexConfig umbracoIndexConfig, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, - IOptionsSnapshot settings) : base(typeFinder, hostingEnvironment, settings) + IOptions settings) : base(typeFinder, hostingEnvironment, settings) { ProfilingLogger = profilingLogger ?? throw new System.ArgumentNullException(nameof(profilingLogger)); LanguageService = languageService ?? throw new System.ArgumentNullException(nameof(languageService)); diff --git a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs index 7c2eb1adfd..0c5f5fd6ab 100644 --- a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs @@ -38,7 +38,7 @@ namespace Umbraco.Core.BackOffice private readonly UmbracoMapper _mapper; private bool _disposed = false; - public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, IOptionsSnapshot globalSettings, UmbracoMapper mapper) + public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, IOptions globalSettings, UmbracoMapper mapper) : this(userService, entityService, externalLoginService, globalSettings.Value, mapper) { } diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs index c725826fd7..15d01bdd12 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs @@ -174,7 +174,7 @@ namespace Umbraco.Web.Compose INotificationService notificationService, IUserService userService, ILocalizedTextService textService, - IOptionsSnapshot globalSettings, + IOptions globalSettings, ILogger logger) { _umbracoContextAccessor = umbracoContextAccessor; diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs index fec14bfbd2..4b941727ca 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs @@ -99,7 +99,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions var ioHelper = factory.GetInstance(); var hostingEnvironment = factory.GetInstance(); var logger = factory.GetInstance(); - var globalSettings = factory.GetInstance>().Value; + var globalSettings = factory.GetInstance>().Value; var rootPath = hostingEnvironment.MapPathWebRoot(globalSettings.UmbracoMediaPath); var rootUrl = hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath); diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs index dd4db120ce..ffd8b880f2 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs @@ -96,13 +96,13 @@ namespace Umbraco.Core.Composing.CompositionExtensions factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), - factory.GetInstance>(), + factory.GetInstance>(), packageRepoFileName); private static LocalizedTextServiceFileSources SourcesFactory(IFactory container) { var hostingEnvironment = container.GetInstance(); - var globalSettings = container.GetInstance>().Value; + var globalSettings = container.GetInstance>().Value; var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.UmbracoPath , "config","lang"))); var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins)); var configLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Config ,"lang"))); diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index 96eee5f458..68d72f36fc 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -23,9 +23,9 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods public EmailNotificationMethod( ILocalizedTextService textService, IRequestAccessor requestAccessor, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IHealthChecksSettings healthChecksSettings, - IOptionsSnapshot contentSettings) + IOptions contentSettings) : base(healthChecksSettings) { var recipientEmail = Settings?["recipientEmail"]?.Value; diff --git a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs index d5dc5307ab..7a20a1189e 100644 --- a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.Install private readonly IIOHelper _ioHelper; private readonly IPublishedSnapshotService _publishedSnapshotService; - public FilePermissionHelper(IOptionsSnapshot globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService) + public FilePermissionHelper(IOptions globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService) { _globalSettings = globalSettings.Value; _ioHelper = ioHelper; diff --git a/src/Umbraco.Infrastructure/Install/InstallHelper.cs b/src/Umbraco.Infrastructure/Install/InstallHelper.cs index a0460c93ba..af00034983 100644 --- a/src/Umbraco.Infrastructure/Install/InstallHelper.cs +++ b/src/Umbraco.Infrastructure/Install/InstallHelper.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Install public InstallHelper(DatabaseBuilder databaseBuilder, ILogger logger, IUmbracoVersion umbracoVersion, - IOptionsSnapshot connectionStrings, + IOptions connectionStrings, IInstallationService installationService, ICookieManager cookieManager, IUserAgentProvider userAgentProvider, diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs index b86c1c2233..d995002daa 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.Install.InstallSteps private readonly ILogger _logger; private readonly ConnectionStrings _connectionStrings; - public DatabaseConfigureStep(DatabaseBuilder databaseBuilder, IOptionsSnapshot connectionStrings) + public DatabaseConfigureStep(DatabaseBuilder databaseBuilder, IOptions connectionStrings) { _databaseBuilder = databaseBuilder; _connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings)); diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs index 44214d1b73..e19fac4028 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs @@ -32,8 +32,8 @@ namespace Umbraco.Web.Install.InstallSteps IRuntimeState runtime, ILogger logger, IUmbracoVersion umbracoVersion, - IOptionsSnapshot globalSettings, - IOptionsSnapshot connectionStrings, + IOptions globalSettings, + IOptions connectionStrings, IIOHelper ioHelper, IConfigManipulator configManipulator) { diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index a8a516199f..11f8f916ed 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -39,9 +39,9 @@ namespace Umbraco.Web.Install.InstallSteps public NewInstallStep( IUserService userService, DatabaseBuilder databaseBuilder, - IOptionsSnapshot passwordConfiguration, - IOptionsSnapshot securitySettings, - IOptionsSnapshot connectionStrings, + IOptions passwordConfiguration, + IOptions securitySettings, + IOptions connectionStrings, ICookieManager cookieManager, BackOfficeUserManager userManager) { diff --git a/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs b/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs index c9386ea210..8428b60fde 100644 --- a/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs +++ b/src/Umbraco.Infrastructure/Logging/Serilog/Enrichers/ThreadAbortExceptionEnricher.cs @@ -19,7 +19,7 @@ namespace Umbraco.Infrastructure.Logging.Serilog.Enrichers private readonly IHostingEnvironment _hostingEnvironment; private readonly IMarchal _marchal; - public ThreadAbortExceptionEnricher(IOptionsSnapshot coreDebugSettings, IHostingEnvironment hostingEnvironment, IMarchal marchal) + public ThreadAbortExceptionEnricher(IOptions coreDebugSettings, IHostingEnvironment hostingEnvironment, IMarchal marchal) { _coreDebugSettings = coreDebugSettings.Value; _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs b/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs index 38c77aefb5..3f8c1c217f 100644 --- a/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs +++ b/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.Media public UploadAutoFillProperties( IMediaFileSystem mediaFileSystem, ILogger logger, - IOptionsSnapshot contentSettings) + IOptions contentSettings) : this(mediaFileSystem, logger, contentSettings.Value) { } diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index 8bf8ceb33e..c272ebc15b 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -40,7 +40,7 @@ namespace Umbraco.Core.Migrations.Install /// public DatabaseBuilder( IScopeProvider scopeProvider, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtime, ILogger logger, diff --git a/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs index 83da0c306c..82658c5366 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs @@ -37,7 +37,7 @@ namespace Umbraco.Web.Models.Mapping public ContentTypeMapDefinition(CommonMapper commonMapper, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, - ILogger logger, IShortStringHelper shortStringHelper, IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) + ILogger logger, IShortStringHelper shortStringHelper, IOptions globalSettings, IHostingEnvironment hostingEnvironment) { _commonMapper = commonMapper; _propertyEditors = propertyEditors; diff --git a/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs index 069333e55d..b55b18db46 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.Models.Mapping private readonly ILogger _logger; private readonly ContentSettings _contentSettings; - public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger, IOptionsSnapshot contentSettings) + public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger, IOptions contentSettings) { _propertyEditors = propertyEditors; _logger = logger; diff --git a/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs index b77214fac5..b281e18b73 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs @@ -38,7 +38,7 @@ namespace Umbraco.Web.Models.Mapping IMemberTypeService memberTypeService, IMemberService memberService, IMemberGroupService memberGroupService, - IOptionsSnapshot memberPasswordConfiguration, + IOptions memberPasswordConfiguration, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, PropertyEditorCollection propertyEditorCollection) : base(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider) diff --git a/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs index ca17bffd5d..58a0d98be1 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs @@ -37,7 +37,7 @@ namespace Umbraco.Web.Models.Mapping private readonly IImageUrlGenerator _imageUrlGenerator; public UserMapDefinition(ILocalizedTextService textService, IUserService userService, IEntityService entityService, ISectionService sectionService, - AppCaches appCaches, ActionCollection actions, IOptionsSnapshot globalSettings, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, + AppCaches appCaches, ActionCollection actions, IOptions globalSettings, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IImageUrlGenerator imageUrlGenerator) { _sectionService = sectionService; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs index 80afef181e..6b6ab37001 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs @@ -25,7 +25,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement private readonly Dictionary _codeIdMap = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly Dictionary _idCodeMap = new Dictionary(); - public LanguageRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger, IOptionsSnapshot globalSettings) + public LanguageRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger, IOptions globalSettings) : base(scopeAccessor, cache, logger) { _globalSettings = globalSettings.Value; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs index b137f36bc4..aae888e0c5 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ScriptRepository.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement private readonly IIOHelper _ioHelper; private readonly GlobalSettings _globalSettings; - public ScriptRepository(IFileSystems fileSystems, IIOHelper ioHelper, IOptionsSnapshot globalSettings) + public ScriptRepository(IFileSystems fileSystems, IIOHelper ioHelper, IOptions globalSettings) : base(fileSystems.ScriptsFileSystem) { _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs index 4ee18c635c..4243d534aa 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/StylesheetRepository.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement private readonly IIOHelper _ioHelper; private readonly GlobalSettings _globalSettings; - public StylesheetRepository(IFileSystems fileSystems, IIOHelper ioHelper, IOptionsSnapshot globalSettings) + public StylesheetRepository(IFileSystems fileSystems, IIOHelper ioHelper, IOptions globalSettings) : base(fileSystems.StylesheetsFileSystem) { _ioHelper = ioHelper; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs index e054c4423a..83bc3730b8 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs @@ -47,8 +47,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement AppCaches appCaches, ILogger logger, IMapperCollection mapperCollection, - IOptionsSnapshot globalSettings, - IOptionsSnapshot passwordConfiguration, + IOptions globalSettings, + IOptions passwordConfiguration, IJsonSerializer jsonSerializer) : this(scopeAccessor, appCaches, logger, mapperCollection, globalSettings.Value, passwordConfiguration.Value, jsonSerializer) { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs index 5205cfd15b..1297a0ba2d 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web.PropertyEditors public FileUploadPropertyEditor( ILogger logger, IMediaFileSystem mediaFileSystem, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs index e518005526..7425051480 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.PropertyEditors ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, - IOptionsSnapshot contentSettings) + IOptions contentSettings) : this(attribute, mediaFileSystem, dataTypeService, localizationService, localizedTextService, shortStringHelper, contentSettings.Value) { } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs index 398b7110e3..2b1efb6d2b 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.PropertyEditors public ImageCropperPropertyEditor( ILogger logger, IMediaFileSystem mediaFileSystem, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper, diff --git a/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs index 063ac1cc97..72391c99c0 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.PropertyEditors _contentSettings = contentSettings; } - public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IOptionsSnapshot contentSettings) + public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IOptions contentSettings) : this(localizedTextService, contentSettings.Value) { } diff --git a/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs index ae47b85365..5b7a720a40 100644 --- a/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs +++ b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Routing public ContentFinderByConfigured404( ILogger logger, IEntityService entityService, - IOptionsSnapshot contentConfigSettings, + IOptions contentConfigSettings, IExamineManager examineManager) { _logger = logger; diff --git a/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs b/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs index 63a6725fb8..cd623b585a 100644 --- a/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs +++ b/src/Umbraco.Infrastructure/Routing/RedirectTrackingComponent.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Routing private readonly IRedirectUrlService _redirectUrlService; private readonly IVariationContextAccessor _variationContextAccessor; - public RedirectTrackingComponent(IOptionsSnapshot webRoutingSettings, IPublishedSnapshotAccessor publishedSnapshotAccessor, IRedirectUrlService redirectUrlService, IVariationContextAccessor variationContextAccessor) + public RedirectTrackingComponent(IOptions webRoutingSettings, IPublishedSnapshotAccessor publishedSnapshotAccessor, IRedirectUrlService redirectUrlService, IVariationContextAccessor variationContextAccessor) { _webRoutingSettings = webRoutingSettings.Value; _publishedSnapshotAccessor = publishedSnapshotAccessor; diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs index 3a4cd60901..a473511e56 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComponent.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Options; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; @@ -11,7 +10,7 @@ namespace Umbraco.Core.Runtime private readonly IIOHelper _ioHelper; private readonly GlobalSettings _globalSettings; - public CoreInitialComponent(IIOHelper ioHelper, IOptionsSnapshot globalSettings) + public CoreInitialComponent(IIOHelper ioHelper, IOptions globalSettings) { _ioHelper = ioHelper; _globalSettings = globalSettings.Value; diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs index 4f1109a8cb..1d8d8a8f79 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs @@ -54,6 +54,8 @@ using Umbraco.Web.Templates; using Umbraco.Web.Trees; using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator; using TextStringValueConverter = Umbraco.Core.PropertyEditors.ValueConverters.TextStringValueConverter; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Core.Runtime { @@ -162,7 +164,7 @@ namespace Umbraco.Core.Runtime composition.RegisterUnique(); composition.RegisterUnique(factory - => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance()))); + => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance>().Value))); composition.UrlSegmentProviders() .Append(); diff --git a/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs b/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs index 2c5d8afbff..2aff2ce5ab 100644 --- a/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs +++ b/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs @@ -20,7 +20,7 @@ namespace Umbraco.Web.Scheduling private readonly IScopeProvider _scopeProvider; public LogScrubber(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, IOptionsSnapshot settings, IScopeProvider scopeProvider, IProfilingLogger logger) + IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, IOptions settings, IScopeProvider scopeProvider, IProfilingLogger logger) : this(runner, delayMilliseconds, periodMilliseconds, mainDom, serverRegistrar, auditService, settings.Value, scopeProvider, logger) { } diff --git a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs index 982f8470a7..6f014955b8 100644 --- a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs @@ -59,7 +59,7 @@ namespace Umbraco.Web.Scheduling IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger, IApplicationShutdownRegistry applicationShutdownRegistry, IHealthChecksSettings healthChecksSettingsConfig, IServerMessenger serverMessenger, IRequestAccessor requestAccessor, - IOptionsSnapshot loggingSettings, IOptionsSnapshot keepAliveSettings, + IOptions loggingSettings, IOptions keepAliveSettings, IHostingEnvironment hostingEnvironment) { _runtime = runtime; diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index 5205a95e8d..947d427995 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Scoping private readonly CoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; - public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptionsSnapshot coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) + public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptions coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) :this(databaseFactory, fileSystems, coreDebugSettings.Value, mediaFileSystem, logger, typeFinder, requestCache) { } diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index 7d6c0303ce..e82c71d1a5 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -40,7 +40,7 @@ namespace Umbraco.Core.Services.Implement public FileService(IScopeProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, ITemplateRepository templateRepository, IPartialViewRepository partialViewRepository, IPartialViewMacroRepository partialViewMacroRepository, - IAuditRepository auditRepository, IShortStringHelper shortStringHelper, IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment) + IAuditRepository auditRepository, IShortStringHelper shortStringHelper, IOptions globalSettings, IHostingEnvironment hostingEnvironment) : base(uowProvider, logger, eventMessagesFactory) { _stylesheetRepository = stylesheetRepository; diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 3ad1ea8446..0c1b390592 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -32,7 +32,7 @@ namespace Umbraco.Core.Services.Implement private readonly IIOHelper _ioHelper; public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, - ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IOptionsSnapshot globalSettings, IOptionsSnapshot contentSettings) + ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IOptions globalSettings, IOptions contentSettings) : this(provider, userService, contentService, localizationService, logger, ioHelper, notificationsRepository, globalSettings.Value, contentSettings.Value) { } diff --git a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs index 921da6f345..fdd79e7264 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Services.Implement private readonly bool _isUpgrading; public UserService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IRuntimeState runtimeState, - IUserRepository userRepository, IUserGroupRepository userGroupRepository, IOptionsSnapshot globalSettings) + IUserRepository userRepository, IUserGroupRepository userGroupRepository, IOptions globalSettings) : base(provider, logger, eventMessagesFactory) { _userRepository = userRepository; diff --git a/src/Umbraco.Infrastructure/Users/EmailSender.cs b/src/Umbraco.Infrastructure/Users/EmailSender.cs index 1ca30bb966..28bbf6471d 100644 --- a/src/Umbraco.Infrastructure/Users/EmailSender.cs +++ b/src/Umbraco.Infrastructure/Users/EmailSender.cs @@ -22,11 +22,11 @@ namespace Umbraco.Core private readonly GlobalSettings _globalSettings; private readonly bool _enableEvents; - public EmailSender(IOptionsSnapshot globalSettings) : this(globalSettings, false) + public EmailSender(IOptions globalSettings) : this(globalSettings, false) { } - public EmailSender(IOptionsSnapshot globalSettings, bool enableEvents) + public EmailSender(IOptions globalSettings, bool enableEvents) : this(globalSettings.Value, enableEvents) { } diff --git a/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs b/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs index b3d7d485f5..5e4a1e2c7a 100644 --- a/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs +++ b/src/Umbraco.Infrastructure/WebAssets/BackOfficeWebAssets.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.WebAssets IManifestParser parser, PropertyEditorCollection propertyEditorCollection, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot globalSettings) + IOptions globalSettings) { _runtimeMinifier = runtimeMinifier; _parser = parser; diff --git a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs index 1572fc9b92..c1e2f02031 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs @@ -14,7 +14,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building private readonly OutOfDateModelsStatus _outOfDateModels; private readonly IIOHelper _ioHelper; - public ModelsGenerator(UmbracoServices umbracoService, IOptionsSnapshot config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) + public ModelsGenerator(UmbracoServices umbracoService, IOptions config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper) { _umbracoService = umbracoService; _config = config.Value; diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs index 3873080605..952fcd453c 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs @@ -17,7 +17,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose { private readonly ModelsBuilderConfig _config; - public ModelsBuilderComposer(IOptionsSnapshot config) + public ModelsBuilderComposer(IOptions config) { _config = config.Value; } diff --git a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs index 92c73e2c6d..554e8eda29 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs @@ -13,7 +13,7 @@ namespace Umbraco.ModelsBuilder.Embedded private readonly ModelsBuilderConfig _config; private readonly IIOHelper _ioHelper; - public ModelsGenerationError(IOptionsSnapshot config, IIOHelper ioHelper) + public ModelsGenerationError(IOptions config, IIOHelper ioHelper) { _config = config.Value; _ioHelper = ioHelper; diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index da48621c7d..c355f651da 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -51,7 +51,7 @@ namespace Umbraco.ModelsBuilder.Embedded public PureLiveModelFactory( Lazy umbracoServices, IProfilingLogger logger, - IOptionsSnapshot config, + IOptions config, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IIOHelper ioHelper) diff --git a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs index 470a224dc8..f18018d9f0 100644 --- a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs +++ b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // it's too late for UmbracoContext which has captured previewDefault and stuff into these ctor vars // but, no, UmbracoContext returns snapshot.Content which comes from elements SO a resync should create a new cache - public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IOptionsSnapshot globalSettings, IVariationContextAccessor variationContextAccessor) + public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IOptions globalSettings, IVariationContextAccessor variationContextAccessor) : this(previewDefault, snapshot, snapshotCache, elementsCache, domainCache, globalSettings.Value, variationContextAccessor) { } diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index f603ee25ad..fabcb0c759 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -87,14 +87,14 @@ namespace Umbraco.Web.PublishedCache.NuCache IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, IDataSource dataSource, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IEntityXmlSerializer entitySerializer, IPublishedModelFactory publishedModelFactory, UrlSegmentProviderCollection urlSegmentProviders, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, IIOHelper ioHelper, - IOptionsSnapshot config) + IOptions config) : base(publishedSnapshotAccessor, variationContextAccessor) { //if (Interlocked.Increment(ref _singletonCheck) > 1) diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs index dc22d24f05..619994412b 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs @@ -64,11 +64,11 @@ namespace Umbraco.Web.BackOffice.Controllers IUserService userService, ILocalizedTextService textService, UmbracoMapper umbracoMapper, - IOptionsSnapshot globalSettings, - IOptionsSnapshot securitySettings, + IOptions globalSettings, + IOptions securitySettings, ILogger logger, IIpResolver ipResolver, - IOptionsSnapshot passwordConfiguration, + IOptions passwordConfiguration, IEmailSender emailSender, Core.Hosting.IHostingEnvironment hostingEnvironment, IRequestAccessor requestAccessor) diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs index 916b422b33..5ee7cf31cf 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly IFileSystem _jsLibFileSystem; - public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IOptionsSnapshot globalSettings) + public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IOptions globalSettings) { _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib"); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 4672d48d88..e3480984fd 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -50,7 +50,7 @@ namespace Umbraco.Web.BackOffice.Controllers public BackOfficeController( BackOfficeUserManager userManager, IRuntimeMinifier runtimeMinifier, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService textService, diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs index 3305a7bbb1..6976821622 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs @@ -46,14 +46,14 @@ namespace Umbraco.Web.BackOffice.Controllers LinkGenerator linkGenerator, IRuntimeState runtimeState, UmbracoFeatures features, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IUmbracoVersion umbracoVersion, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IHttpContextAccessor httpContextAccessor, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot runtimeSettings, - IOptionsSnapshot securitySettings, + IOptions runtimeSettings, + IOptions securitySettings, IRuntimeMinifier runtimeMinifier, IAuthenticationSchemeProvider authenticationSchemeProvider) { diff --git a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs index 7fdfc81cd1..4bf76a108a 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.BackOffice.Controllers ILocalizedTextService localizedTextService, UmbracoMapper umbracoMapper, IShortStringHelper shortStringHelper, - IOptionsSnapshot globalSettings) + IOptions globalSettings) { _ioHelper = ioHelper; _fileSystems = fileSystems; diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index 28a09942dd..659062f4f9 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -85,7 +85,7 @@ namespace Umbraco.Web.BackOffice.Controllers UmbracoMapper umbracoMapper, ILocalizedTextService localizedTextService, IEntityXmlSerializer serializer, - IOptionsSnapshot globalSettings, + IOptions globalSettings, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, IIOHelper ioHelper, diff --git a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs index ff0eacb9bb..eb7cbceef7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs @@ -50,7 +50,7 @@ namespace Umbraco.Web.BackOffice.Controllers public CurrentUserController( IMediaFileSystem mediaFileSystem, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, IWebSecurity webSecurity, diff --git a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs index d049dbebbb..3ffcd5cec3 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs @@ -47,7 +47,7 @@ namespace Umbraco.Web.BackOffice.Controllers public DataTypeController( PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, - IOptionsSnapshot contentSettings, + IOptions contentSettings, UmbracoMapper umbracoMapper, PropertyEditorCollection propertyEditorCollection, IContentTypeService contentTypeService, diff --git a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs index b0b18c8da3..6122c36a53 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.BackOffice.Controllers ILogger logger, ILocalizationService localizationService, IWebSecurity webSecurity, - IOptionsSnapshot globalSettings, + IOptions globalSettings, ILocalizedTextService localizedTextService, UmbracoMapper umbracoMapper ) diff --git a/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs index f909313dff..df834b019c 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly ContentSettings _contentSettings; private readonly IImageUrlGenerator _imageUrlGenerator; - public ImagesController(IMediaFileSystem mediaFileSystem, IOptionsSnapshot contentSettings, IImageUrlGenerator imageUrlGenerator) + public ImagesController(IMediaFileSystem mediaFileSystem, IOptions contentSettings, IImageUrlGenerator imageUrlGenerator) { _mediaFileSystem = mediaFileSystem; _contentSettings = contentSettings.Value; diff --git a/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs b/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs index 0a58c04443..66f8b6d7e0 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/LanguageController.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.BackOffice.Controllers public LanguageController(ILocalizationService localizationService, UmbracoMapper umbracoMapper, - IOptionsSnapshot globalSettings) + IOptions globalSettings) { _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); diff --git a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs index 9a339a18b8..d075f309c7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs @@ -68,7 +68,7 @@ namespace Umbraco.Web.BackOffice.Controllers IShortStringHelper shortStringHelper, IEventMessagesFactory eventMessages, ILocalizedTextService localizedTextService, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IMediaTypeService mediaTypeService, IMediaService mediaService, IEntityService entityService, diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs index 41aa693c0f..6a93bf6437 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs @@ -63,7 +63,7 @@ namespace Umbraco.Web.BackOffice.Controllers IShortStringHelper shortStringHelper, IEventMessagesFactory eventMessages, ILocalizedTextService localizedTextService, - IOptionsSnapshot passwordConfig, + IOptions passwordConfig, PropertyEditorCollection propertyEditors, LegacyPasswordSecurity passwordSecurity, UmbracoMapper umbracoMapper, diff --git a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs index eeb73d6d47..3878eb9b14 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.BackOffice.Controllers public PreviewController( UmbracoFeatures features, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IPublishedSnapshotService publishedSnapshotService, IWebSecurity webSecurity, ILocalizationService localizationService, diff --git a/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs b/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs index c5c5ca91ab..9e8358c4b1 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs @@ -28,7 +28,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IHostingEnvironment _hostingEnvironment; public RedirectUrlManagementController(ILogger logger, - IOptionsSnapshot webRoutingSettings, + IOptions webRoutingSettings, IWebSecurity webSecurity, IRedirectUrlService redirectUrlService, UmbracoMapper umbracoMapper, diff --git a/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs b/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs index 5a28a228f3..b62d6b6080 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/TinyMceController.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.BackOffice.Controllers public TinyMceController( IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IIOHelper ioHelper ) { diff --git a/src/Umbraco.Web.BackOffice/Controllers/TourController.cs b/src/Umbraco.Web.BackOffice/Controllers/TourController.cs index 106d520743..6e7af87a11 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/TourController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/TourController.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.BackOffice.Controllers public TourController( TourFilterCollection filters, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot tourSettings, + IOptions tourSettings, IWebSecurity webSecurity, IContentTypeService contentTypeService) { diff --git a/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs b/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs index 78ac2713c0..16fcb5b38c 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.BackOffice.Controllers IUmbracoVersion umbracoVersion, ICookieManager cookieManager, IWebSecurity webSecurity, - IOptionsSnapshot globalSettings) + IOptions globalSettings) { _upgradeService = upgradeService ?? throw new ArgumentNullException(nameof(upgradeService)); _umbracoVersion = umbracoVersion ?? throw new ArgumentNullException(nameof(umbracoVersion)); @@ -81,7 +81,7 @@ namespace Umbraco.Web.BackOffice.Controllers { private readonly GlobalSettings _globalSettings; - public UpdateCheckResponseFilter(IOptionsSnapshot globalSettings) + public UpdateCheckResponseFilter(IOptions globalSettings) { _globalSettings = globalSettings.Value; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs index ab3f48cdad..b3f752ee49 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs @@ -73,11 +73,11 @@ namespace Umbraco.Web.BackOffice.Controllers public UsersController( IMediaFileSystem mediaFileSystem, - IOptionsSnapshot contentSettings, + IOptions contentSettings, IHostingEnvironment hostingEnvironment, ISqlContext sqlContext, IImageUrlGenerator imageUrlGenerator, - IOptionsSnapshot securitySettings, + IOptions securitySettings, IRequestAccessor requestAccessor, IEmailSender emailSender, IWebSecurity webSecurity, @@ -89,7 +89,7 @@ namespace Umbraco.Web.BackOffice.Controllers IEntityService entityService, IMediaService mediaService, IContentService contentService, - IOptionsSnapshot globalSettings, + IOptions globalSettings, BackOfficeUserManager backOfficeUserManager, ILogger logger, LinkGenerator linkGenerator) diff --git a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs index c9e53b1b82..fbd69acd12 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -74,7 +74,7 @@ namespace Umbraco.Extensions services.TryAddScoped, PasswordValidator>(); services.TryAddScoped>( services => new BackOfficePasswordHasher( - new LegacyPasswordSecurity(services.GetRequiredService>().Value), + new LegacyPasswordSecurity(services.GetRequiredService>().Value), services.GetRequiredService())); services.TryAddScoped, DefaultUserConfirmation>(); services.TryAddScoped, UserClaimsPrincipalFactory>(); diff --git a/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs index 761c1110cb..c993766a6b 100644 --- a/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs @@ -23,7 +23,7 @@ namespace Umbraco.Extensions private readonly IBackOfficeAntiforgery _antiforgery; private readonly GlobalSettings _globalSettings; - public SetAngularAntiForgeryTokensFilter(IBackOfficeAntiforgery antiforgery, IOptionsSnapshot globalSettings) + public SetAngularAntiForgeryTokensFilter(IBackOfficeAntiforgery antiforgery, IOptions globalSettings) { _antiforgery = antiforgery; _globalSettings = globalSettings.Value; diff --git a/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs index f3fd82bdf6..e2a1d942d9 100644 --- a/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/UmbracoWebApiRequireHttpsAttribute.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.BackOffice.Filters { private readonly GlobalSettings _globalSettings; - public UmbracoWebApiRequireHttpsFilter(IOptionsSnapshot globalSettings) + public UmbracoWebApiRequireHttpsFilter(IOptions globalSettings) { _globalSettings = globalSettings.Value; } diff --git a/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs b/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs index b05a05c167..4076f01aab 100644 --- a/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs +++ b/src/Umbraco.Web.BackOffice/Mapping/MediaMapDefinition.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.Models.Mapping private readonly ContentSettings _contentSettings; public MediaMapDefinition(ICultureDictionary cultureDictionary, CommonMapper commonMapper, CommonTreeNodeMapper commonTreeNodeMapper, IMediaService mediaService, IMediaTypeService mediaTypeService, - ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators, IOptionsSnapshot contentSettings, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators, IOptions contentSettings, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { _commonMapper = commonMapper; _commonTreeNodeMapper = commonTreeNodeMapper; diff --git a/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs b/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs index 6d2fe9a9c8..dd3b3988c9 100644 --- a/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs +++ b/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.BackOffice.Routing private readonly string _umbracoPathSegment; public BackOfficeAreaRoutes( - IOptionsSnapshot globalSettings, + IOptions globalSettings, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, UmbracoApiControllerTypeCollection apiControllers) diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs index 2b70a1b083..e91a517496 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs @@ -39,7 +39,7 @@ namespace Umbraco.Web.BackOffice.Security private readonly IHostingEnvironment _hostingEnvironment; private readonly BackOfficeUserManager _userManager; - public BackOfficeSessionIdValidator(ISystemClock systemClock, IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, BackOfficeUserManager userManager) + public BackOfficeSessionIdValidator(ISystemClock systemClock, IOptions globalSettings, IHostingEnvironment hostingEnvironment, BackOfficeUserManager userManager) { _systemClock = systemClock; _globalSettings = globalSettings.Value; diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs index 69a5359d4e..3b8421ce6a 100644 --- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs @@ -42,8 +42,8 @@ namespace Umbraco.Web.BackOffice.Security public ConfigureBackOfficeCookieOptions( IUmbracoContextAccessor umbracoContextAccessor, - IOptionsSnapshot securitySettings, - IOptionsSnapshot globalSettings, + IOptions securitySettings, + IOptions globalSettings, IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, IDataProtectionProvider dataProtection, diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs index 5dd80411eb..31b5de2e43 100644 --- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.BackOffice.Security { private readonly UserPasswordConfigurationSettings _userPasswordConfiguration; - public ConfigureBackOfficeIdentityOptions(IOptionsSnapshot userPasswordConfiguration) + public ConfigureBackOfficeIdentityOptions(IOptions userPasswordConfiguration) { _userPasswordConfiguration = userPasswordConfiguration.Value; } diff --git a/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs b/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs index f48996332c..1854187a2a 100644 --- a/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs +++ b/src/Umbraco.Web.BackOffice/Security/PreviewAuthenticationMiddleware.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.BackOffice.Security private readonly IHostingEnvironment _hostingEnvironment; public PreviewAuthenticationMiddleware( - IOptionsSnapshot globalSettings, + IOptions globalSettings, IHostingEnvironment hostingEnvironment) { _globalSettings = globalSettings.Value; diff --git a/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs index 2f72e1f829..44c83e3009 100644 --- a/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs +++ b/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs @@ -63,7 +63,7 @@ namespace Umbraco.Web.Trees IDataTypeService dataTypeService, UmbracoTreeSearcher treeSearcher, ActionCollection actions, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IContentService contentService, IPublicAccessService publicAccessService, ILocalizationService localizationService) diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index 4dc72bfd95..6f40800307 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -6,7 +6,7 @@ namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreBackOfficeInfo : IBackOfficeInfo { - public AspNetCoreBackOfficeInfo(IOptionsSnapshot globalSettings) + public AspNetCoreBackOfficeInfo(IOptions globalSettings) : this(globalSettings.Value) { } diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index f35ced66f0..54502fbe29 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.Common.AspNetCore private string _localTempPath; - public AspNetCoreHostingEnvironment(IOptionsSnapshot hostingSettings, IWebHostEnvironment webHostEnvironment) + public AspNetCoreHostingEnvironment(IOptions hostingSettings, IWebHostEnvironment webHostEnvironment) : this(hostingSettings.Value, webHostEnvironment) { } diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs index 2b27e37887..985c568a08 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreRequestAccessor.cs @@ -22,7 +22,7 @@ namespace Umbraco.Web.Common.AspNetCore public AspNetCoreRequestAccessor(IHttpContextAccessor httpContextAccessor, IUmbracoRequestLifetime umbracoRequestLifetime, IUmbracoContextAccessor umbracoContextAccessor, - IOptionsSnapshot webRoutingSettings) + IOptions webRoutingSettings) { _httpContextAccessor = httpContextAccessor; _umbracoContextAccessor = umbracoContextAccessor; diff --git a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs index 28bb1dc41c..fde3d095fe 100644 --- a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs +++ b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs @@ -25,8 +25,8 @@ namespace Umbraco.Web.Common.AspNetCore private IUmbracoContext _umbracoContext; private IUmbracoContextAccessor UmbracoContextAccessor => Context.RequestServices.GetRequiredService(); - private GlobalSettings GlobalSettings => Context.RequestServices.GetRequiredService>().Value; - private ContentSettings ContentSettings => Context.RequestServices.GetRequiredService>().Value; + private GlobalSettings GlobalSettings => Context.RequestServices.GetRequiredService>().Value; + private ContentSettings ContentSettings => Context.RequestServices.GetRequiredService>().Value; private IProfilerHtml ProfilerHtml => Context.RequestServices.GetRequiredService(); private IIOHelper IOHelper => Context.RequestServices.GetRequiredService(); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 4653bc7bbd..d03fb183e7 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -124,6 +124,7 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine:")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigModelsBuilderPrefix)); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging:")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler:")); // TODO: HealthChecksSettings (+ one other?) @@ -225,10 +226,10 @@ namespace Umbraco.Extensions // `RegisterEssentials`. var serviceProvider = services.BuildServiceProvider(); - var globalSettings = serviceProvider.GetService>().Value; - var connectionStrings = serviceProvider.GetService>().Value; - var hostingSettings = serviceProvider.GetService>().Value; - var typeFinderSettings = serviceProvider.GetService>().Value; + var globalSettings = serviceProvider.GetService>().Value; + var connectionStrings = serviceProvider.GetService>().Value; + var hostingSettings = serviceProvider.GetService>().Value; + var typeFinderSettings = serviceProvider.GetService>().Value; var dbProviderFactoryCreator = serviceProvider.GetRequiredService(); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs index 61120c8ee9..0b9154b6cf 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs @@ -41,7 +41,7 @@ namespace Umbraco.Extensions // TODO: We need to avoid this, surely there's a way? See ContainerTests.BuildServiceProvider_Before_Host_Is_Configured var serviceProvider = services.BuildServiceProvider(); - var imagingSettings = serviceProvider.GetService>().Value; + var imagingSettings = serviceProvider.GetService>().Value; services.AddUmbracoImageSharp(imagingSettings); return services; diff --git a/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs b/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs index 76e462843e..3c1de1e138 100644 --- a/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs +++ b/src/Umbraco.Web.Common/Filters/ModelBindingExceptionFilter.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.Common.Filters private readonly ExceptionFilterSettings _exceptionFilterSettings; private readonly IPublishedModelFactory _publishedModelFactory; - public ModelBindingExceptionFilter(IOptionsSnapshot exceptionFilterSettings, IPublishedModelFactory publishedModelFactory) + public ModelBindingExceptionFilter(IOptions exceptionFilterSettings, IPublishedModelFactory publishedModelFactory) { _exceptionFilterSettings = exceptionFilterSettings.Value; _publishedModelFactory = publishedModelFactory ?? throw new ArgumentNullException(nameof(publishedModelFactory)); diff --git a/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs b/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs index a35628821b..fe941e89d5 100644 --- a/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/StatusCodeResultAttribute.cs @@ -28,7 +28,7 @@ namespace Umbraco.Web.Common.Filters httpContext.Response.StatusCode = (int)_statusCode; - var disableIisCustomErrors = httpContext.RequestServices.GetService>().Value.TrySkipIisCustomErrors; + var disableIisCustomErrors = httpContext.RequestServices.GetService>().Value.TrySkipIisCustomErrors; var statusCodePagesFeature = httpContext.Features.Get(); if (statusCodePagesFeature != null) diff --git a/src/Umbraco.Web.Common/Install/InstallController.cs b/src/Umbraco.Web.Common/Install/InstallController.cs index d97bb86fed..b5da8eabd4 100644 --- a/src/Umbraco.Web.Common/Install/InstallController.cs +++ b/src/Umbraco.Web.Common/Install/InstallController.cs @@ -39,7 +39,7 @@ namespace Umbraco.Web.Common.Install IWebSecurity webSecurity, InstallHelper installHelper, IRuntimeState runtime, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IRuntimeMinifier runtimeMinifier, IHostingEnvironment hostingEnvironment, IUmbracoVersion umbracoVersion, diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index eae771b930..c1fb033d20 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -37,7 +37,7 @@ namespace Umbraco.Web.Macros public MacroRenderer( IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, - IOptionsSnapshot contentSettings, + IOptions contentSettings, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs index 0cfacbbf13..67755da5ea 100644 --- a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs @@ -97,7 +97,7 @@ namespace Umbraco.Web.Common.Runtime composition.RegisterUnique(); composition.RegisterUnique(); - composition.RegisterUnique(factory => new LegacyPasswordSecurity(factory.GetInstance>().Value)); + composition.RegisterUnique(factory => new LegacyPasswordSecurity(factory.GetInstance>().Value)); } diff --git a/src/Umbraco.Web.Common/Security/WebSecurity.cs b/src/Umbraco.Web.Common/Security/WebSecurity.cs index 69f5850482..b822adf656 100644 --- a/src/Umbraco.Web.Common/Security/WebSecurity.cs +++ b/src/Umbraco.Web.Common/Security/WebSecurity.cs @@ -22,7 +22,7 @@ namespace Umbraco.Web.Common.Security public WebSecurity( IUserService userService, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IHostingEnvironment hostingEnvironment, IHttpContextAccessor httpContextAccessor) { diff --git a/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs b/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs index 81a635a20f..1bec3cf41c 100644 --- a/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs +++ b/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs @@ -45,7 +45,7 @@ namespace Umbraco.Web.Common.Templates IPublishedRouter publishedRouter, IFileService fileService, ILocalizationService textService, - IOptionsSnapshot webRoutingSettings, + IOptions webRoutingSettings, IShortStringHelper shortStringHelper, IHttpContextAccessor httpContextAccessor, ICompositeViewEngine viewEngine) diff --git a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs index a3849c532e..d9df11e4a9 100644 --- a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs +++ b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, - IOptionsSnapshot globalSettings, + IOptions globalSettings, IUserService userService, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, diff --git a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml index bce17553d6..b7c654a80d 100644 --- a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml +++ b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml @@ -13,7 +13,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IOptionsSnapshot globalSettings +@inject IOptions globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml diff --git a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml index dd34dab6f4..212d6bddee 100644 --- a/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml +++ b/src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Preview.cshtml @@ -12,7 +12,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IOptionsSnapshot globalSettings +@inject IOptions globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml From 7884e4ca178dbf00ffe8cea555030260183d7fc4 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Aug 2020 09:29:40 +0200 Subject: [PATCH 09/58] Resolved issues such that application boots and back-office is navigable. --- ...ngsSettings.cs => HealthChecksSettings.cs} | 0 .../ContentSettingsExtensions.cs | 2 +- .../Models/ActiveDirectorySettings.cs | 7 +- .../Configuration/Models/ConnectionStrings.cs | 12 +- .../Models/ContentImagingSettings.cs | 5 +- .../Configuration/Models/ContentSettings.cs | 3 - .../Configuration/Models/GlobalSettings.cs | 9 +- .../Models/HealthChecksSettings.cs | 108 ++++++++++++++++++ .../Configuration/Models/HostingSettings.cs | 6 +- .../Models/ImagingCacheSettings.cs | 5 +- .../Models/ImagingResizeSettings.cs | 11 +- .../FolderAndFilePermissionsCheck.cs | 8 +- .../HealthCheck/Checks/Security/HttpsCheck.cs | 8 +- .../HealthCheck/Checks/Services/SmtpCheck.cs | 14 +-- src/Umbraco.Core/Models/MediaExtensions.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 1 - .../EmailNotificationMethod.cs | 2 +- .../NotificationMethodBase.cs | 6 +- .../Runtime/CoreInitialComposer.cs | 2 +- .../Scheduling/HealthCheckNotifier.cs | 10 +- .../Scheduling/SchedulerComponent.cs | 12 +- .../Users/EmailSender.cs | 20 ++-- .../HealthCheck/HealthCheckController.cs | 6 +- .../UmbracoCoreServiceCollectionExtensions.cs | 39 +++---- .../UmbracoWebServiceCollectionExtensions.cs | 4 +- .../UmbracoBackOffice/AuthorizeUpgrade.cshtml | 2 +- .../Umbraco/UmbracoBackOffice/Default.cshtml | 2 +- .../Configuration/ConfigModelConversions.cs | 2 +- 28 files changed, 203 insertions(+), 105 deletions(-) rename src/Umbraco.Configuration/Models/{HealthChecksSettingsSettings.cs => HealthChecksSettings.cs} (100%) create mode 100644 src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs diff --git a/src/Umbraco.Configuration/Models/HealthChecksSettingsSettings.cs b/src/Umbraco.Configuration/Models/HealthChecksSettings.cs similarity index 100% rename from src/Umbraco.Configuration/Models/HealthChecksSettingsSettings.cs rename to src/Umbraco.Configuration/Models/HealthChecksSettings.cs diff --git a/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs index 1c24d0eb6c..21ebe55f2f 100644 --- a/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs @@ -41,7 +41,7 @@ namespace Umbraco.Core.Configuration /// The auto-fill configuration for the specified property alias, or null. public static IImagingAutoFillUploadField GetConfig(this ContentSettings contentSettings, string propertyTypeAlias) { - var autoFillConfigs = contentSettings.Imaging.ImageAutoFillProperties; + var autoFillConfigs = contentSettings.Imaging.AutoFillImageProperties; return autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias); } } diff --git a/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs index 4eb2c774bf..0fe541416a 100644 --- a/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs @@ -1,10 +1,7 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ActiveDirectorySettings { - [JsonPropertyName("Domain")] - public string ActiveDirectoryDomain { get; set; } + public string Domain { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index 027adedd09..056611a0ed 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -1,13 +1,21 @@ using System; using System.Collections.Generic; using System.Data.Common; -using System.Text.Json.Serialization; namespace Umbraco.Core.Configuration.Models { public class ConnectionStrings { - [JsonPropertyName(Constants.System.UmbracoConnectionName)] + // Backing field for UmbracoConnectionString to load from configuration value with key umbracoDbDSN. + // Attributes cannot be applied to map from keys that don't match, and have chosen to retain the key name + // used in configuration for older Umbraco versions. + // See: https://stackoverflow.com/a/54607296/489433 + private string umbracoDbDSN + { + get => string.Empty; + set => UmbracoConnectionString = value; + } + public string UmbracoConnectionString { get; set; } private Dictionary AsDictionary() => new Dictionary diff --git a/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs index 7ec8bf219f..018936896c 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Text.Json.Serialization; -using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Core.Configuration.Models @@ -21,8 +19,7 @@ namespace Umbraco.Core.Configuration.Models public IEnumerable ImageFileTypes { get; set; } = new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }; - [JsonPropertyName("AutoFillImageProperties")] - public IEnumerable ImageAutoFillProperties { get; set; } = DefaultImagingAutoFillUploadField; + public IEnumerable AutoFillImageProperties { get; set; } = DefaultImagingAutoFillUploadField; private class ImagingAutoFillUploadField : IImagingAutoFillUploadField { diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index 4cc74f709a..0a405d7db3 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text.Json.Serialization; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Macros; @@ -20,7 +19,6 @@ namespace Umbraco.Core.Configuration.Models // TODO: to retain previous configuration structure, this should come from a nested collection, // "Errors:Error404". Although we can use JsonPropertyName to map when the JSON field name differs // from the one in this class, not sure how we'd "flatten" a collection like this. - [JsonPropertyName("Error404")] public IEnumerable Error404Collection { get; set; } // public IEnumerable Error404Collection => _configuration @@ -30,7 +28,6 @@ namespace Umbraco.Core.Configuration.Models public string PreviewBadge { get; set; } = DefaultPreviewBadge; - [JsonPropertyName("MacroErrors")] public MacroErrorBehaviour MacroErrorBehaviour { get; set; } = MacroErrorBehaviour.Inline; public IEnumerable DisallowedUploadFiles { get; set; } = new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }; diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index 6a7411c733..8f5f64ffbc 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { /// /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information @@ -54,9 +52,8 @@ namespace Umbraco.Core.Configuration.Models public string NoNodesViewPath { get; set; } = "~/config/splashes/NoNodes.cshtml"; - public bool IsSmtpServerConfigured => !string.IsNullOrWhiteSpace(SmtpSettings?.Host); + public bool IsSmtpServerConfigured => !string.IsNullOrWhiteSpace(Smtp?.Host); - [JsonPropertyName("Smtp")] - public SmtpSettings SmtpSettings { get; set; } + public SmtpSettings Smtp { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs b/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs new file mode 100644 index 0000000000..37580195d6 --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Configuration.HealthChecks; + +namespace Umbraco.Core.Configuration.Models +{ + public class HealthChecksSettings + { + // TODO: implement + public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); + + public HealthCheckNotificationSettings NotificationSettings { get; set; } = new HealthCheckNotificationSettings(); + + /* + public IEnumerable DisabledChecks => _configuration + .GetSection(Prefix+"DisabledChecks") + .GetChildren() + .Select( + x => new DisabledHealthCheck + { + Id = x.GetValue("Id"), + DisabledOn = x.GetValue("DisabledOn"), + DisabledBy = x.GetValue("DisabledBy") + }); + + public IHealthCheckNotificationSettings NotificationSettings => + new HealthCheckNotificationSettings( + _configuration.GetSection(Prefix+"NotificationSettings")); + + + private class DisabledHealthCheck : IDisabledHealthCheck + { + public Guid Id { get; set; } + public DateTime DisabledOn { get; set; } + public int DisabledBy { get; set; } + } + */ + + // TODO: move to new file + public class HealthCheckNotificationSettings + { + public bool Enabled { get; set; } = false; + + public string FirstRunTime { get; set; } + + public int PeriodInHours { get; set; } = 24; + + // TODO: implement + + public IReadOnlyDictionary NotificationMethods { get; set; } = new Dictionary(); + + public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); + + /* + public IReadOnlyDictionary NotificationMethods => _configurationSection + .GetSection("NotificationMethods") + .GetChildren() + .ToDictionary(x => x.Key, x => (INotificationMethod) new NotificationMethod(x.Key, x), StringComparer.InvariantCultureIgnoreCase); + + public IEnumerable DisabledChecks => _configurationSection + .GetSection("DisabledChecks").GetChildren().Select( + x => new DisabledHealthCheck + { + Id = x.GetValue("Id"), + DisabledOn = x.GetValue("DisabledOn"), + DisabledBy = x.GetValue("DisabledBy") + }); + */ + } + + /* + private class NotificationMethod : INotificationMethod + { + private readonly IConfigurationSection _configurationSection; + + public NotificationMethod(string alias, IConfigurationSection configurationSection) + { + Alias = alias; + _configurationSection = configurationSection; + } + + public string Alias { get; } + public bool Enabled => _configurationSection.GetValue("Enabled", false); + + public HealthCheckNotificationVerbosity Verbosity => + _configurationSection.GetValue("Verbosity", HealthCheckNotificationVerbosity.Summary); + + public bool FailureOnly => _configurationSection.GetValue("FailureOnly", true); + + public IReadOnlyDictionary Settings => _configurationSection + .GetSection("Settings").GetChildren().ToDictionary(x => x.Key, + x => (INotificationMethodSettings) new NotificationMethodSettings(x.Key, x.Value), StringComparer.InvariantCultureIgnoreCase); + } + + private class NotificationMethodSettings : INotificationMethodSettings + { + public NotificationMethodSettings(string key, string value) + { + Key = key; + Value = value; + } + + public string Key { get; } + public string Value { get; } + } + */ + } +} diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index a774a948ea..c9adbebc23 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -1,13 +1,10 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class HostingSettings { /// /// Gets the configuration for the location of temporary files. /// - [JsonPropertyName("LocalTempStorage")] public LocalTempStorage LocalTempStorageLocation { get; set; } = LocalTempStorage.Default; public string ApplicationVirtualPath => null; @@ -16,7 +13,6 @@ namespace Umbraco.Core.Configuration.Models /// Gets a value indicating whether umbraco is running in [debug mode]. /// /// true if [debug mode]; otherwise, false. - [JsonPropertyName("Debug")] public bool DebugMode { get; set; } = false; } } diff --git a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs index 9c2fd4bf37..03efac0ffd 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingCacheSettings { @@ -10,7 +8,6 @@ namespace Umbraco.Core.Configuration.Models public uint CachedNameLength { get; set; } = 7; - [JsonPropertyName("Folder")] public string CacheFolder { get; set; } = "../App_Data/Cache"; } } diff --git a/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs index 6b445d8c40..f9db53d7dd 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs @@ -1,14 +1,9 @@ - -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingResizeSettings { - [JsonPropertyName("MaxWidth")] - public int MaxResizeWidth { get; set; } = 5000; + public int MaxWidth { get; set; } = 5000; - [JsonPropertyName("MaxHeight")] - public int MaxResizeHeight { get; set; } = 5000; + public int MaxHeight { get; set; } = 5000; } } diff --git a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs index 6aeb83d61c..d6fbfae813 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Install; using Umbraco.Core.IO; using Umbraco.Core.Services; @@ -29,14 +31,14 @@ namespace Umbraco.Web.HealthCheck.Checks.Permissions public class FolderAndFilePermissionsCheck : HealthCheck { private readonly ILocalizedTextService _textService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IFilePermissionHelper _filePermissionHelper; private readonly IIOHelper _ioHelper; - public FolderAndFilePermissionsCheck(ILocalizedTextService textService, IGlobalSettings globalSettings, IFilePermissionHelper filePermissionHelper, IIOHelper ioHelper) + public FolderAndFilePermissionsCheck(ILocalizedTextService textService, IOptions globalSettings, IFilePermissionHelper filePermissionHelper, IIOHelper ioHelper) { _textService = textService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _filePermissionHelper = filePermissionHelper; _ioHelper = ioHelper; } diff --git a/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs index 43776ad827..7f85d326df 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs @@ -8,6 +8,8 @@ using Umbraco.Core.IO; using Umbraco.Core.Services; using Umbraco.Core.Logging; using Umbraco.Web.HealthCheck.Checks.Config; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.HealthCheck.Checks.Security { @@ -19,17 +21,17 @@ namespace Umbraco.Web.HealthCheck.Checks.Security public class HttpsCheck : HealthCheck { private readonly ILocalizedTextService _textService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; private readonly IRequestAccessor _requestAccessor; private const string FixHttpsSettingAction = "fixHttpsSetting"; - public HttpsCheck(ILocalizedTextService textService, IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IRequestAccessor requestAccessor) + public HttpsCheck(ILocalizedTextService textService, IOptions globalSettings, IIOHelper ioHelper, ILogger logger, IRequestAccessor requestAccessor) { _textService = textService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _ioHelper = ioHelper; _logger = logger; _requestAccessor = requestAccessor; diff --git a/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs index 7b57c01223..77b1201ef6 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.IO; using System.Net.Sockets; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Services; namespace Umbraco.Web.HealthCheck.Checks.Services @@ -16,14 +18,12 @@ namespace Umbraco.Web.HealthCheck.Checks.Services public class SmtpCheck : HealthCheck { private readonly ILocalizedTextService _textService; - private readonly IRuntimeState _runtime; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public SmtpCheck(ILocalizedTextService textService, IRuntimeState runtime, IGlobalSettings globalSettings) + public SmtpCheck(ILocalizedTextService textService, IOptions globalSettings) { _textService = textService; - _runtime = runtime; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } /// @@ -48,11 +48,11 @@ namespace Umbraco.Web.HealthCheck.Checks.Services private HealthCheckStatus CheckSmtpSettings() { - var message = string.Empty; var success = false; - var smtpSettings = _globalSettings.SmtpSettings; + var smtpSettings = _globalSettings.Smtp; + string message; if (smtpSettings == null) { message = _textService.Localize("healthcheck/smtpMailSettingsNotFound"); diff --git a/src/Umbraco.Core/Models/MediaExtensions.cs b/src/Umbraco.Core/Models/MediaExtensions.cs index aa7a48d8f4..9615969c07 100644 --- a/src/Umbraco.Core/Models/MediaExtensions.cs +++ b/src/Umbraco.Core/Models/MediaExtensions.cs @@ -29,7 +29,7 @@ namespace Umbraco.Core.Models /// public static string[] GetUrls(this IMedia media, ContentSettings contentSettings, MediaUrlGeneratorCollection mediaUrlGenerators) { - return contentSettings.Imaging.ImageAutoFillProperties + return contentSettings.Imaging.AutoFillImageProperties .Select(field => media.GetUrl(field.Alias, mediaUrlGenerators)) .Where(link => string.IsNullOrWhiteSpace(link) == false) .ToArray(); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 067b26e0f0..4f1c421d97 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -20,7 +20,6 @@ - diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index 68d72f36fc..dd2f27320e 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods ILocalizedTextService textService, IRequestAccessor requestAccessor, IOptions globalSettings, - IHealthChecksSettings healthChecksSettings, + IOptions healthChecksSettings, IOptions contentSettings) : base(healthChecksSettings) { diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs index 3e6606e965..2c0c5bcc1f 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs @@ -2,13 +2,15 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.HealthCheck.NotificationMethods { public abstract class NotificationMethodBase : IHealthCheckNotificationMethod { - protected NotificationMethodBase(IHealthChecksSettings healthCheckSettingsConfig) + protected NotificationMethodBase(IOptions healthCheckSettings) { var type = GetType(); var attribute = type.GetCustomAttribute(); @@ -18,7 +20,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods return; } - var notificationMethods = healthCheckSettingsConfig.NotificationSettings.NotificationMethods; + var notificationMethods = healthCheckSettings.Value.NotificationSettings.NotificationMethods; if(!notificationMethods.TryGetValue(attribute.Alias, out var notificationMethod)) { Enabled = false; diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs index 1d8d8a8f79..1123ad0f9e 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs @@ -125,7 +125,7 @@ namespace Umbraco.Core.Runtime // register a server registrar, by default it's the db registrar composition.RegisterUnique(f => { - var globalSettings = f.GetInstance(); + var globalSettings = f.GetInstance>().Value; // TODO: we still register the full IServerMessenger because // even on 1 single server we can have 2 concurrent app domains diff --git a/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs b/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs index adae7b3828..e681538e12 100644 --- a/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs +++ b/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; using Umbraco.Core; -using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; using Umbraco.Core.Sync; @@ -17,7 +17,7 @@ namespace Umbraco.Web.Scheduling private readonly HealthCheckNotificationMethodCollection _notifications; private readonly IScopeProvider _scopeProvider; private readonly IProfilingLogger _logger; - private readonly IHealthChecksSettings _healthChecksSettingsConfig; + private readonly HealthChecksSettings _healthChecksSettings; private readonly IServerRegistrar _serverRegistrar; private readonly IRuntimeState _runtimeState; @@ -29,7 +29,7 @@ namespace Umbraco.Web.Scheduling HealthCheckNotificationMethodCollection notifications, IMainDom mainDom, IProfilingLogger logger, - IHealthChecksSettings healthChecksSettingsConfig, + HealthChecksSettings healthChecksSettings, IServerRegistrar serverRegistrar, IRuntimeState runtimeState, IScopeProvider scopeProvider) @@ -41,7 +41,7 @@ namespace Umbraco.Web.Scheduling _scopeProvider = scopeProvider; _runtimeState = runtimeState; _logger = logger; - _healthChecksSettingsConfig = healthChecksSettingsConfig; + _healthChecksSettings = healthChecksSettings; _serverRegistrar = serverRegistrar; _runtimeState = runtimeState; } @@ -74,7 +74,7 @@ namespace Umbraco.Web.Scheduling using (var scope = _scopeProvider.CreateScope()) using (_logger.DebugDuration("Health checks executing", "Health checks complete")) { - var healthCheckConfig = _healthChecksSettingsConfig; + var healthCheckConfig = _healthChecksSettings; // Don't notify for any checks that are disabled, nor for any disabled // just for notifications diff --git a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs index 6f014955b8..cfa9ced735 100644 --- a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.Scheduling private readonly HealthCheckCollection _healthChecks; private readonly HealthCheckNotificationMethodCollection _notifications; private readonly IUmbracoContextFactory _umbracoContextFactory; - private readonly IHealthChecksSettings _healthChecksSettingsConfig; + private readonly HealthChecksSettings _healthChecksSettings; private readonly IServerMessenger _serverMessenger; private readonly IRequestAccessor _requestAccessor; private readonly LoggingSettings _loggingSettings; @@ -57,7 +57,7 @@ namespace Umbraco.Web.Scheduling IContentService contentService, IAuditService auditService, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger, - IApplicationShutdownRegistry applicationShutdownRegistry, IHealthChecksSettings healthChecksSettingsConfig, + IApplicationShutdownRegistry applicationShutdownRegistry, IOptions healthChecksSettings, IServerMessenger serverMessenger, IRequestAccessor requestAccessor, IOptions loggingSettings, IOptions keepAliveSettings, IHostingEnvironment hostingEnvironment) @@ -74,7 +74,7 @@ namespace Umbraco.Web.Scheduling _healthChecks = healthChecks; _notifications = notifications; - _healthChecksSettingsConfig = healthChecksSettingsConfig ?? throw new ArgumentNullException(nameof(healthChecksSettingsConfig)); + _healthChecksSettings = healthChecksSettings.Value ?? throw new ArgumentNullException(nameof(healthChecksSettings)); _serverMessenger = serverMessenger; _requestAccessor = requestAccessor; _loggingSettings = loggingSettings.Value; @@ -129,7 +129,7 @@ namespace Umbraco.Web.Scheduling tasks.Add(RegisterLogScrubber(_loggingSettings)); tasks.Add(RegisterTempFileCleanup()); - var healthCheckConfig = _healthChecksSettingsConfig; + var healthCheckConfig = _healthChecksSettings; if (healthCheckConfig.NotificationSettings.Enabled) tasks.Add(RegisterHealthCheckNotifier(healthCheckConfig, _healthChecks, _notifications, _logger)); @@ -155,7 +155,7 @@ namespace Umbraco.Web.Scheduling return task; } - private IBackgroundTask RegisterHealthCheckNotifier(IHealthChecksSettings healthCheckSettingsConfig, + private IBackgroundTask RegisterHealthCheckNotifier(HealthChecksSettings healthCheckSettingsConfig, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IProfilingLogger logger) { @@ -176,7 +176,7 @@ namespace Umbraco.Web.Scheduling } var periodInMilliseconds = healthCheckSettingsConfig.NotificationSettings.PeriodInHours * 60 * 60 * 1000; - var task = new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, healthChecks, notifications, _mainDom, logger, _healthChecksSettingsConfig, _serverRegistrar, _runtime, _scopeProvider); + var task = new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, healthChecks, notifications, _mainDom, logger, _healthChecksSettings, _serverRegistrar, _runtime, _scopeProvider); _healthCheckRunner.TryAdd(task); return task; } diff --git a/src/Umbraco.Infrastructure/Users/EmailSender.cs b/src/Umbraco.Infrastructure/Users/EmailSender.cs index 28bbf6471d..d563a0c36f 100644 --- a/src/Umbraco.Infrastructure/Users/EmailSender.cs +++ b/src/Umbraco.Infrastructure/Users/EmailSender.cs @@ -60,12 +60,12 @@ namespace Umbraco.Core using (var client = new SmtpClient()) { - client.Connect(_globalSettings.SmtpSettings.Host, _globalSettings.SmtpSettings.Port); + client.Connect(_globalSettings.Smtp.Host, _globalSettings.Smtp.Port); - if (!(_globalSettings.SmtpSettings.Username is null && - _globalSettings.SmtpSettings.Password is null)) + if (!(_globalSettings.Smtp.Username is null && + _globalSettings.Smtp.Password is null)) { - client.Authenticate(_globalSettings.SmtpSettings.Username, _globalSettings.SmtpSettings.Password); + client.Authenticate(_globalSettings.Smtp.Username, _globalSettings.Smtp.Password); } client.Send(ConstructEmailMessage(message)); @@ -89,16 +89,16 @@ namespace Umbraco.Core { using (var client = new SmtpClient()) { - await client.ConnectAsync(_globalSettings.SmtpSettings.Host, _globalSettings.SmtpSettings.Port); + await client.ConnectAsync(_globalSettings.Smtp.Host, _globalSettings.Smtp.Port); - if (!(_globalSettings.SmtpSettings.Username is null && - _globalSettings.SmtpSettings.Password is null)) + if (!(_globalSettings.Smtp.Username is null && + _globalSettings.Smtp.Password is null)) { - await client.AuthenticateAsync(_globalSettings.SmtpSettings.Username, _globalSettings.SmtpSettings.Password); + await client.AuthenticateAsync(_globalSettings.Smtp.Username, _globalSettings.Smtp.Password); } var mailMessage = ConstructEmailMessage(message); - if (_globalSettings.SmtpSettings.DeliveryMethod == SmtpDeliveryMethod.Network) + if (_globalSettings.Smtp.DeliveryMethod == SmtpDeliveryMethod.Network) { await client.SendAsync(mailMessage); } @@ -143,7 +143,7 @@ namespace Umbraco.Core { var fromEmail = mailMessage.From?.Address; if(string.IsNullOrEmpty(fromEmail)) - fromEmail = _globalSettings.SmtpSettings.From; + fromEmail = _globalSettings.Smtp.From; var messageToSend = new MimeMessage { diff --git a/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs b/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs index 6b8eada506..fc5ea85dfa 100644 --- a/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs +++ b/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs @@ -8,6 +8,8 @@ using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.HealthCheck; using Umbraco.Web.Common.Attributes; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.BackOffice.Controllers { @@ -22,12 +24,12 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IList _disabledCheckIds; private readonly ILogger _logger; - public HealthCheckController(HealthCheckCollection checks, ILogger logger, IHealthChecksSettings healthChecksSettings) + public HealthCheckController(HealthCheckCollection checks, ILogger logger, IOptions healthChecksSettings) { _checks = checks ?? throw new ArgumentNullException(nameof(checks)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - var healthCheckConfig = healthChecksSettings ?? throw new ArgumentNullException(nameof(healthChecksSettings)); + var healthCheckConfig = healthChecksSettings.Value ?? throw new ArgumentNullException(nameof(healthChecksSettings)); _disabledCheckIds = healthCheckConfig.DisabledChecks .Select(x => x.Id) .ToList(); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index d03fb183e7..46d035d76b 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -104,29 +104,28 @@ namespace Umbraco.Extensions { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ConnectionStrings")); + services.Configure(configuration.GetSection("ConnectionStrings"), o => o.BindNonPublicProperties = true); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Core:Debug")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigModelsBuilderPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler:")); - - // TODO: HealthChecksSettings (+ one other?) + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Global")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "ModelsBuilder")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "HealthChecks")); // TODO: remove this var configsFactory = new AspNetCoreConfigsFactory(configuration); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs index 0b9154b6cf..394a15e1d4 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs @@ -64,8 +64,8 @@ namespace Umbraco.Extensions options.CachedNameLength = imagingSettings.Cache.CachedNameLength; options.OnParseCommands = context => { - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.Resize.MaxResizeWidth); - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.Resize.MaxResizeHeight); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.Resize.MaxWidth); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.Resize.MaxHeight); }; options.OnBeforeSave = _ => { }; options.OnProcessed = _ => { }; diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml index 0a7c95e7fe..dc47195a18 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml @@ -12,7 +12,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IOptionsSnapshot globalSettings +@inject IOptions globalSettings @inject IRuntimeMinifier runtimeMinifier @{ diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml index bce17553d6..b7c654a80d 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml @@ -13,7 +13,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IOptionsSnapshot globalSettings +@inject IOptions globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs index 752983c7c9..c6ded26ce2 100644 --- a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs +++ b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Configuration RegisterType = globalSettings.RegisterType, ReservedPaths = globalSettings.ReservedPaths, ReservedUrls = globalSettings.ReservedUrls, - SmtpSettings = new SmtpSettings + Smtp = new SmtpSettings { DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, From = globalSettings.SmtpSettings.From, From 7774878c261437d8f53d84ae32ba8d92e482cce2 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Aug 2020 09:56:27 +0200 Subject: [PATCH 10/58] Restored Umbraco.Tests.Common --- .../Builders/GlobalSettingsBuilder.cs | 40 +++---------------- .../Builders/LanguageBuilder.cs | 6 +-- .../Builders/SmtpSettingsBuilder.cs | 20 ++-------- src/Umbraco.Tests.Common/TestHelperBase.cs | 10 +++-- 4 files changed, 18 insertions(+), 58 deletions(-) diff --git a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs index 4a88d4a571..72cc6de9a1 100644 --- a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs @@ -1,4 +1,4 @@ -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.Common.Builders { @@ -9,7 +9,7 @@ namespace Umbraco.Tests.Common.Builders } } - public class GlobalSettingsBuilder : ChildBuilderBase + public class GlobalSettingsBuilder : ChildBuilderBase { private string _configurationStatus; private string _databaseFactoryServerVersion; @@ -166,7 +166,7 @@ namespace Umbraco.Tests.Common.Builders return this; } - public override IGlobalSettings Build() + public override GlobalSettings Build() { var configurationStatus = _configurationStatus ?? "9.0.0"; var databaseFactoryServerVersion = _databaseFactoryServerVersion ?? null; @@ -175,8 +175,6 @@ namespace Umbraco.Tests.Common.Builders var hideTopLevelNodeFromPath = _hideTopLevelNodeFromPath ?? false; var installEmptyDatabase = _installEmptyDatabase ?? false; var installMissingDatabase = _installMissingDatabase ?? false; - var isSmtpServerConfigured = _isSmtpServerConfigured ?? false; - var path = _path ?? "/umbraco"; var registerType = _registerType ?? null; var reservedPaths = _reservedPaths ?? "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; var reservedUrls = _reservedUrls ?? "~/config/splashes/noNodes.aspx,~/.well-known,"; @@ -191,7 +189,7 @@ namespace Umbraco.Tests.Common.Builders var mainDomLock = _mainDomLock ?? string.Empty; var noNodesViewPath = _noNodesViewPath ?? "~/config/splashes/NoNodes.cshtml"; - return new TestGlobalSettings + return new GlobalSettings { ConfigurationStatus = configurationStatus, DatabaseFactoryServerVersion = databaseFactoryServerVersion, @@ -200,8 +198,6 @@ namespace Umbraco.Tests.Common.Builders HideTopLevelNodeFromPath = hideTopLevelNodeFromPath, InstallEmptyDatabase = installEmptyDatabase, InstallMissingDatabase = installMissingDatabase, - IsSmtpServerConfigured = isSmtpServerConfigured, - Path = path, RegisterType = registerType, ReservedPaths = reservedPaths, ReservedUrls = reservedUrls, @@ -212,36 +208,10 @@ namespace Umbraco.Tests.Common.Builders UmbracoScriptsPath = umbracoScriptsPath, VersionCheckPeriod = versionCheckPeriod, TimeOutInMinutes = timeOutInMinutes, - SmtpSettings = smtpSettings, + Smtp = smtpSettings, MainDomLock = mainDomLock, NoNodesViewPath = noNodesViewPath, }; } - - private class TestGlobalSettings : IGlobalSettings - { - public string ReservedUrls { get; set; } - public string ReservedPaths { get; set; } - public string Path { get; set; } - public string ConfigurationStatus { get; set; } - public int TimeOutInMinutes { get; set; } - public string DefaultUILanguage { get; set; } - public bool HideTopLevelNodeFromPath { get; set; } - public bool UseHttps { get; set; } - public int VersionCheckPeriod { get; set; } - public string UmbracoPath { get; set; } - public string UmbracoCssPath { get; set; } - public string UmbracoScriptsPath { get; set; } - public string UmbracoMediaPath { get; set; } - public bool IsSmtpServerConfigured { get; set; } - public ISmtpSettings SmtpSettings { get; set; } - public bool InstallMissingDatabase { get; set; } - public bool InstallEmptyDatabase { get; set; } - public bool DisableElectionForSingleServer { get; set; } - public string RegisterType { get; set; } - public string DatabaseFactoryServerVersion { get; set; } - public string MainDomLock { get; set; } - public string NoNodesViewPath { get; set; } - } } } diff --git a/src/Umbraco.Tests.Common/Builders/LanguageBuilder.cs b/src/Umbraco.Tests.Common/Builders/LanguageBuilder.cs index 88c8fa4639..7174baaba1 100644 --- a/src/Umbraco.Tests.Common/Builders/LanguageBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/LanguageBuilder.cs @@ -1,7 +1,6 @@ using System; using System.Globalization; -using Moq; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Tests.Common.Builders.Interfaces; @@ -58,6 +57,7 @@ namespace Umbraco.Tests.Common.Builders public override ILanguage Build() { var cultureInfo = _cultureInfo ?? CultureInfo.GetCultureInfo("en-US"); + var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage(cultureInfo.Name).Build(); var key = _key ?? Guid.NewGuid(); var createDate = _createDate ?? DateTime.Now; var updateDate = _updateDate ?? DateTime.Now; @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Common.Builders var isDefault = _isDefault ?? false; var isMandatory = _isMandatory ?? false; - return new Language(Mock.Of(), cultureInfo.Name) + return new Language(globalSettings, cultureInfo.Name) { Id = _id ?? 0, CultureName = cultureInfo.EnglishName, diff --git a/src/Umbraco.Tests.Common/Builders/SmtpSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/SmtpSettingsBuilder.cs index bd85807203..f979197e4c 100644 --- a/src/Umbraco.Tests.Common/Builders/SmtpSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/SmtpSettingsBuilder.cs @@ -1,6 +1,5 @@ using System.Net.Mail; -using Umbraco.Core.Configuration; -using Umbraco.Core.Models.Membership; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.Common.Builders { @@ -12,7 +11,7 @@ namespace Umbraco.Tests.Common.Builders } public class SmtpSettingsBuilder - : ChildBuilderBase + : ChildBuilderBase { private string _from; private string _host; @@ -68,7 +67,7 @@ namespace Umbraco.Tests.Common.Builders return this; } - public override ISmtpSettings Build() + public override SmtpSettings Build() { var from = _from ?? null; var host = _host ?? null; @@ -78,7 +77,7 @@ namespace Umbraco.Tests.Common.Builders var username = _username ?? null; var password = _password ?? null; - return new TestSmtpSettings() + return new SmtpSettings() { From = from, Host = host, @@ -89,16 +88,5 @@ namespace Umbraco.Tests.Common.Builders Password = password, }; } - - private class TestSmtpSettings : ISmtpSettings - { - public string From { get; set; } - public string Host { get; set; } - public int Port { get; set; } - public string PickupDirectoryLocation { get; set; } - public SmtpDeliveryMethod DeliveryMethod { get; set; } - public string Username { get; set; } - public string Password { get; set; } - } } } diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 85a463ddfa..3e50cf2a53 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -18,6 +18,7 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Strings; using Umbraco.Web; using Umbraco.Web.Routing; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Common { @@ -49,8 +50,9 @@ namespace Umbraco.Tests.Common public IRuntimeState GetRuntimeState() { + var globalSettings = new GlobalSettingsBuilder().Build(); return new RuntimeState( - Mock.Of(), + globalSettings, GetUmbracoVersion()); } @@ -89,7 +91,7 @@ namespace Umbraco.Tests.Common get { if (_ioHelper == null) - _ioHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateMockGlobalSettings()); + _ioHelper = new IOHelper(GetHostingEnvironment()); return _ioHelper; } } @@ -126,11 +128,11 @@ namespace Umbraco.Tests.Common return relativePath.Replace("~/", bin + "/"); } - public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(GetConfigs().Global()); + public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(new GlobalSettingsBuilder().Build()); public IRegister GetRegister() { - return RegisterFactory.Create(GetConfigs().Global()); + return RegisterFactory.Create(new GlobalSettingsBuilder().Build()); } public abstract IHostingEnvironment GetHostingEnvironment(); From 9bd8b894b88115980800938d620b5fc39be58fec Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Aug 2020 10:52:48 +0200 Subject: [PATCH 11/58] Restored Umbraco.Tests.UnitTests --- .../Configuration/Models/HostingSettings.cs | 6 +-- .../Models/RequestHandlerSettings.cs | 1 - .../Builders/HostingSettingsBuilder.cs | 44 +++++++++++++++++++ .../Builders/RequestHandlerSettingsBuilder.cs | 26 +++++++++++ .../AutoFixture/AutoMoqDataAttribute.cs | 4 +- .../BackOfficeClaimsPrincipalFactoryTests.cs | 6 +-- .../Extensions/UriExtensionsTests.cs | 18 ++++---- .../Umbraco.Core/Routing/UriUtilityTests.cs | 4 +- .../Builders/HostingSettingsBuilderTests.cs | 30 +++++++++++++ .../RequestHandlerSettingsBuilderTestsy.cs | 26 +++++++++++ .../Routing/BackOfficeAreaRoutesTests.cs | 5 ++- .../Controllers/SurfaceControllerTests.cs | 9 ++-- 12 files changed, 154 insertions(+), 25 deletions(-) create mode 100644 src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index c9adbebc23..ea389efde4 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -2,15 +2,15 @@ { public class HostingSettings { + public string ApplicationVirtualPath { get; set; } + /// /// Gets the configuration for the location of temporary files. /// public LocalTempStorage LocalTempStorageLocation { get; set; } = LocalTempStorage.Default; - public string ApplicationVirtualPath => null; - /// - /// Gets a value indicating whether umbraco is running in [debug mode]. + /// Gets a value indicating whether umbraco is running in [debug mode]. /// /// true if [debug mode]; otherwise, false. public bool DebugMode { get; set; } = false; diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs index f00658a0be..b52285c42c 100644 --- a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -5,7 +5,6 @@ namespace Umbraco.Core.Configuration.Models { public class RequestHandlerSettings { - private const string Prefix = Constants.Configuration.ConfigPrefix + "RequestHandler:"; private static readonly CharItem[] DefaultCharCollection = { new CharItem { Char = " ", Replacement = "-" }, diff --git a/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs new file mode 100644 index 0000000000..11e622d4d4 --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs @@ -0,0 +1,44 @@ +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class HostingSettingsBuilder : BuilderBase + { + private string _applicationVirtualPath; + private bool? _debugMode; + private LocalTempStorage? _localTempStorageLocation; + + public HostingSettingsBuilder WithApplicationVirtualPath(string applicationVirtualPath) + { + _applicationVirtualPath = applicationVirtualPath; + return this; + } + + public HostingSettingsBuilder WithDebugMode(bool debugMode) + { + _debugMode = debugMode; + return this; + } + + public HostingSettingsBuilder WithLocalTempStorageLocation(LocalTempStorage localTempStorageLocation) + { + _localTempStorageLocation = localTempStorageLocation; + return this; + } + + public override HostingSettings Build() + { + var debugMode = _debugMode ?? false; + var localTempStorageLocation = _localTempStorageLocation ?? LocalTempStorage.Default; + var applicationVirtualPath = _applicationVirtualPath ?? null; + + return new HostingSettings + { + ApplicationVirtualPath = applicationVirtualPath, + DebugMode = debugMode, + LocalTempStorageLocation = localTempStorageLocation, + }; + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs new file mode 100644 index 0000000000..8c90678705 --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs @@ -0,0 +1,26 @@ +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class RequestHandlerSettingsBuilder : BuilderBase + { + private bool? _addTrailingSlash; + + public RequestHandlerSettingsBuilder WithAddTrailingSlash(bool addTrailingSlash) + { + _addTrailingSlash = addTrailingSlash; + return this; + } + + public override RequestHandlerSettings Build() + { + var addTrailingSlash = _addTrailingSlash ?? false; + + return new RequestHandlerSettings + { + AddTrailingSlash = addTrailingSlash, + }; + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index 568704583d..d7645ec434 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -6,7 +6,7 @@ using AutoFixture.NUnit3; using Microsoft.AspNetCore.Identity; using Moq; using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration; +using Umbraco.Tests.Common.Builders; using Umbraco.Web.BackOffice.Controllers; namespace Umbraco.Tests.UnitTests.AutoFixture @@ -33,7 +33,7 @@ namespace Umbraco.Tests.UnitTests.AutoFixture { fixture.Customize( u => u.FromFactory( - (a,b,c) => BackOfficeIdentityUser.CreateNew(Mock.Of(),a,b,c))); + (a,b,c) => BackOfficeIdentityUser.CreateNew(new GlobalSettingsBuilder().Build(),a,b,c))); fixture .Customize(new ConstructorCustomization(typeof(UsersController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery())) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs index 87cff07475..7d977fe686 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs @@ -11,6 +11,7 @@ using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.Models.Membership; using Umbraco.Extensions; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice { @@ -137,10 +138,9 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice [SetUp] public void Setup() { - var mockGlobalSettings = new Mock(); - mockGlobalSettings.Setup(x => x.DefaultUILanguage).Returns("test"); + var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage("test").Build(); - _testUser = new BackOfficeIdentityUser(mockGlobalSettings.Object, _testUserId, new List()) + _testUser = new BackOfficeIdentityUser(globalSettings, _testUserId, new List()) { UserName = _testUserName, Name = _testUserGivenName, diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs index 71ef0e1bdb..9a7b7f63ed 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs @@ -1,11 +1,11 @@ using System; -using System.Reflection; using Microsoft.AspNetCore.Hosting; using Moq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Web.Common.AspNetCore; namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions @@ -18,12 +18,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions { _settingsForTests = new SettingsForTests(); _hostEnvironment = Mock.Of(); - _globalSettings = _settingsForTests.GenerateStubGlobalSettings(); + _globalSettings = new GlobalSettingsBuilder().Build(); } private SettingsForTests _settingsForTests; private IWebHostEnvironment _hostEnvironment; - private IGlobalSettings _globalSettings; + private GlobalSettings _globalSettings; [TestCase("http://www.domain.com/umbraco/preview/frame?id=1234", "", true)] [TestCase("http://www.domain.com/umbraco", "", true)] @@ -47,10 +47,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions [TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)] public void Is_Back_Office_Request(string input, string virtualPath, bool expected) { - - var mockHostingSettings = Mock.Get(_settingsForTests.GenerateMockHostingSettings()); - mockHostingSettings.Setup(x => x.ApplicationVirtualPath).Returns(virtualPath); - var hostingEnvironment = new AspNetCoreHostingEnvironment(mockHostingSettings.Object, _hostEnvironment); + var hostingSettings = new HostingSettingsBuilder().WithApplicationVirtualPath(virtualPath).Build(); + var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, _hostEnvironment); var source = new Uri(input); Assert.AreEqual(expected, source.IsBackOfficeRequest(_globalSettings, hostingEnvironment)); @@ -68,8 +66,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions public void Is_Installer_Request(string input, bool expected) { var source = new Uri(input); - var mockHostingSettings = Mock.Get(_settingsForTests.GenerateMockHostingSettings()); - var hostingEnvironment = new AspNetCoreHostingEnvironment(mockHostingSettings.Object, _hostEnvironment); + var hostingSettings = new HostingSettingsBuilder().Build(); + var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, _hostEnvironment); Assert.AreEqual(expected, source.IsInstallerRequest(hostingEnvironment)); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs index 15a9599674..4ac125e598 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; +using Umbraco.Tests.Common.Builders; using Umbraco.Web; namespace Umbraco.Tests.UnitTests.Umbraco.Core.Routing @@ -70,12 +71,13 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Routing { // Arrange var sourceUri = new Uri(sourceUrl, UriKind.Relative); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(trailingSlash).Build(); var mockRequestHandlerSettings = new Mock(); mockRequestHandlerSettings.Setup(x => x.AddTrailingSlash).Returns(trailingSlash); var uriUtility = BuildUriUtility("/"); // Act - var resultUri = uriUtility.UriFromUmbraco(sourceUri, Mock.Of(), mockRequestHandlerSettings.Object); + var resultUri = uriUtility.UriFromUmbraco(sourceUri, requestHandlerSettings); // Assert var expectedUri = new Uri(expectedUrl, UriKind.Relative); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs new file mode 100644 index 0000000000..81ab0a7183 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs @@ -0,0 +1,30 @@ +using NUnit.Framework; +using Umbraco.Core.Configuration; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class HostingSettingsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const bool debugMode = true; + const LocalTempStorage localTempStorageLocation = LocalTempStorage.AspNetTemp; + + var builder = new HostingSettingsBuilder(); + + // Act + var hostingSettings = builder + .WithDebugMode(debugMode) + .WithLocalTempStorageLocation(localTempStorageLocation) + .Build(); + + // Assert + Assert.AreEqual(debugMode, hostingSettings.DebugMode); + Assert.AreEqual(localTempStorageLocation, hostingSettings.LocalTempStorageLocation); + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs new file mode 100644 index 0000000000..a6dd7f98a4 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class RequestHandlerSettingsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const bool addTrailingSlash = true; + + var builder = new RequestHandlerSettingsBuilder(); + + // Act + var requestHandlerSettings = builder + .WithAddTrailingSlash(addTrailingSlash) + .Build(); + + // Assert + Assert.AreEqual(addTrailingSlash, requestHandlerSettings.AddTrailingSlash); + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs index 7d0c3c8e04..2a096bbd47 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using System.Linq; @@ -7,6 +8,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Extensions; +using Umbraco.Tests.Common.Builders; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Routing; using Umbraco.Web.Common.Attributes; @@ -94,8 +96,9 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing private BackOfficeAreaRoutes GetBackOfficeAreaRoutes(RuntimeLevel level) { + var globalSettings = new GlobalSettingsBuilder().Build(); var routes = new BackOfficeAreaRoutes( - Mock.Of(x => x.UmbracoPath == "~/umbraco"), + Options.Create(globalSettings), Mock.Of(x => x.ToAbsolute(It.IsAny()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty), Mock.Of(x => x.Level == level), new UmbracoApiControllerTypeCollection(new[] { typeof(Testing1Controller) })); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/SurfaceControllerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/SurfaceControllerTests.cs index 7a202d7902..0d288b6310 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/SurfaceControllerTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core.Cache; @@ -45,7 +46,7 @@ namespace Umbraco.Tests.Integration Mock.Of(), new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), - globalSettings, + Options.Create(globalSettings), Mock.Of(), hostingEnvironment, new UriUtility(hostingEnvironment), @@ -78,7 +79,7 @@ namespace Umbraco.Tests.Integration Mock.Of(), new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), - globalSettings, + Options.Create(globalSettings), Mock.Of(), hostingEnvironment, new UriUtility(hostingEnvironment), @@ -115,7 +116,7 @@ namespace Umbraco.Tests.Integration publishedSnapshotService.Object, new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), - globalSettings, + Options.Create(globalSettings), Mock.Of(), hostingEnvironment, new UriUtility(hostingEnvironment), @@ -152,7 +153,7 @@ namespace Umbraco.Tests.Integration Mock.Of(), new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), - globalSettings, + Options.Create(globalSettings), Mock.Of(), hostingEnvironment, new UriUtility(hostingEnvironment), From adf687579c3f10afa062a850bdcba0030b5630a8 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Aug 2020 12:34:37 +0200 Subject: [PATCH 12/58] Restored Umbraco.Tests.IntegrationTests (some failures remaining) --- .../Builders/ConnectionStringsBuilder.cs | 25 ++++++ .../Builders/ContentSettingsBuilder.cs | 12 +++ .../Builders/CoreDebugSettingsBuilder.cs | 34 +++++++ .../Builders/NuCacheSettingsBuilder.cs | 12 +++ .../Builders/RequestHandlerSettingsBuilder.cs | 1 - ...serPasswordConfigurationSettingsBuilder.cs | 12 +++ .../Builders/WebRoutingSettingsBuilder.cs | 89 +++++++++++++++++++ .../ContainerTests.cs | 2 +- .../ApplicationBuilderExtensions.cs | 4 +- .../Implementations/TestHelper.cs | 10 ++- .../Implementations/TestHostingEnvironment.cs | 9 +- .../Repositories/UserRepositoryTest.cs | 3 +- src/Umbraco.Tests.Integration/RuntimeTests.cs | 24 ++++- .../Testing/LocalDbTestDatabase.cs | 5 +- .../Testing/UmbracoIntegrationTest.cs | 6 +- .../BackOfficeCookieManagerTests.cs | 13 +-- .../Builders/ConnectionStringsBuilderTests.cs | 26 ++++++ .../Builders/CoreDebugSettingsBuilderTests.cs | 29 ++++++ ... => RequestHandlerSettingsBuilderTests.cs} | 0 .../WebRoutingSettingsBuilderTests.cs | 47 ++++++++++ 20 files changed, 340 insertions(+), 23 deletions(-) create mode 100644 src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs create mode 100644 src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs rename src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/{RequestHandlerSettingsBuilderTestsy.cs => RequestHandlerSettingsBuilderTests.cs} (100%) create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs diff --git a/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs b/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs new file mode 100644 index 0000000000..a252a7996c --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs @@ -0,0 +1,25 @@ +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; + +namespace Umbraco.Tests.Common.Builders +{ + public class ConnectionStringsBuilder : BuilderBase + { + private string _umbracoConnectionString; + + public ConnectionStringsBuilder WithUmbracoConnectionString(string umbracoConnectionString) + { + _umbracoConnectionString = umbracoConnectionString; + return this; + } + + public override ConnectionStrings Build() + { + var umbracoConnectionString = _umbracoConnectionString ?? string.Empty; + + return new ConnectionStrings + { + UmbracoConnectionString = umbracoConnectionString, + }; + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs new file mode 100644 index 0000000000..f5fb1fc08f --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class ContentSettingsBuilder : BuilderBase + { + public override ContentSettings Build() + { + return new ContentSettings(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs new file mode 100644 index 0000000000..e14fb0ade5 --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs @@ -0,0 +1,34 @@ +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; + +namespace Umbraco.Tests.Common.Builders +{ + public class CoreDebugSettingsBuilder : BuilderBase + { + private bool? _dumpOnTimeoutThreadAbort; + private bool? _logUncompletedScopes; + + public CoreDebugSettingsBuilder WithDumpOnTimeoutThreadAbort(bool dumpOnTimeoutThreadAbort) + { + _dumpOnTimeoutThreadAbort = dumpOnTimeoutThreadAbort; + return this; + } + + public CoreDebugSettingsBuilder WithLogUncompletedScopes(bool logUncompletedScopes) + { + _logUncompletedScopes = logUncompletedScopes; + return this; + } + + public override CoreDebugSettings Build() + { + var dumpOnTimeoutThreadAbort = _dumpOnTimeoutThreadAbort ?? false; + var logUncompletedScopes = _logUncompletedScopes ?? false; + + return new CoreDebugSettings + { + DumpOnTimeoutThreadAbort = dumpOnTimeoutThreadAbort, + LogUncompletedScopes = logUncompletedScopes, + }; + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs new file mode 100644 index 0000000000..35d5c66e4a --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class NuCacheSettingsBuilder : BuilderBase + { + public override NuCacheSettings Build() + { + return new NuCacheSettings(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs index 8c90678705..43cdacbb9b 100644 --- a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs @@ -1,4 +1,3 @@ -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.Common.Builders diff --git a/src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs new file mode 100644 index 0000000000..3a0dfc3e9a --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class UserPasswordConfigurationSettingsBuilder : BuilderBase + { + public override UserPasswordConfigurationSettings Build() + { + return new UserPasswordConfigurationSettings(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs new file mode 100644 index 0000000000..e32fff31fa --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs @@ -0,0 +1,89 @@ +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Tests.Common.Builders +{ + public class WebRoutingSettingsBuilder : BuilderBase + { + private bool? _trySkipIisCustomErrors; + private bool? _internalRedirectPreservesTemplate; + private bool? _disableAlternativeTemplates; + private bool? _validateAlternativeTemplates; + private bool? _disableFindContentByIdPath; + private bool? _disableRedirectUrlTracking; + private string _urlProviderMode; + private string _umbracoApplicationUrl; + + public WebRoutingSettingsBuilder WithTrySkipIisCustomErrors(bool trySkipIisCustomErrors) + { + _trySkipIisCustomErrors = trySkipIisCustomErrors; + return this; + } + + public WebRoutingSettingsBuilder WithInternalRedirectPreservesTemplate(bool internalRedirectPreservesTemplate) + { + _internalRedirectPreservesTemplate = internalRedirectPreservesTemplate; + return this; + } + + public WebRoutingSettingsBuilder WithDisableAlternativeTemplates(bool disableAlternativeTemplates) + { + _disableAlternativeTemplates = disableAlternativeTemplates; + return this; + } + + public WebRoutingSettingsBuilder WithValidateAlternativeTemplates(bool validateAlternativeTemplates) + { + _validateAlternativeTemplates = validateAlternativeTemplates; + return this; + } + + public WebRoutingSettingsBuilder WithDisableFindContentByIdPath(bool disableFindContentByIdPath) + { + _disableFindContentByIdPath = disableFindContentByIdPath; + return this; + } + + public WebRoutingSettingsBuilder WithDisableRedirectUrlTracking(bool disableRedirectUrlTracking) + { + _disableRedirectUrlTracking = disableRedirectUrlTracking; + return this; + } + + public WebRoutingSettingsBuilder WithUrlProviderMode(string urlProviderMode) + { + _urlProviderMode = urlProviderMode; + return this; + } + + public WebRoutingSettingsBuilder WithUmbracoApplicationUrl(string umbracoApplicationUrl) + { + _umbracoApplicationUrl = umbracoApplicationUrl; + return this; + } + + public override WebRoutingSettings Build() + { + var trySkipIisCustomErrors = _trySkipIisCustomErrors ?? false; + var internalRedirectPreservesTemplate = _internalRedirectPreservesTemplate ?? false; + var disableAlternativeTemplates = _disableAlternativeTemplates ?? false; + var validateAlternativeTemplates = _validateAlternativeTemplates ?? false; + var disableFindContentByIdPath = _disableFindContentByIdPath ?? false; + var disableRedirectUrlTracking = _disableRedirectUrlTracking ?? false; + var urlProviderMode = _urlProviderMode ?? UrlMode.Auto.ToString(); + var umbracoApplicationUrl = _umbracoApplicationUrl ?? string.Empty; + + return new WebRoutingSettings + { + TrySkipIisCustomErrors = trySkipIisCustomErrors, + InternalRedirectPreservesTemplate = internalRedirectPreservesTemplate, + DisableAlternativeTemplates = disableAlternativeTemplates, + ValidateAlternativeTemplates = validateAlternativeTemplates, + DisableFindContentByIdPath = disableFindContentByIdPath, + DisableRedirectUrlTracking = disableRedirectUrlTracking, + UrlProviderMode = urlProviderMode, + UmbracoApplicationUrl = umbracoApplicationUrl, + }; + } + } +} diff --git a/src/Umbraco.Tests.Integration/ContainerTests.cs b/src/Umbraco.Tests.Integration/ContainerTests.cs index 2098b7241e..a50a24e780 100644 --- a/src/Umbraco.Tests.Integration/ContainerTests.cs +++ b/src/Umbraco.Tests.Integration/ContainerTests.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.Integration // Register in the container var composition = new Composition(umbracoContainer, typeLoader, - testHelper.Logger, runtimeState, testHelper.GetConfigs(), testHelper.IOHelper, testHelper.AppCaches); + testHelper.Logger, runtimeState, testHelper.IOHelper, testHelper.AppCaches); composition.RegisterEssentials(testHelper.Logger, testHelper.Profiler, testHelper.Logger, testHelper.MainDom, testHelper.AppCaches, umbracoDatabaseFactory, typeLoader, runtimeState, testHelper.GetTypeFinder(), testHelper.IOHelper, testHelper.GetUmbracoVersion(), dbProviderFactoryCreator, diff --git a/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs b/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs index 3961657afe..0d1d373262 100644 --- a/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs +++ b/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs @@ -5,9 +5,11 @@ using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Tests.Integration.Testing; @@ -46,7 +48,7 @@ namespace Umbraco.Tests.Integration.Extensions var db = UmbracoIntegrationTest.GetOrCreate(dbFilePath, app.ApplicationServices.GetRequiredService(), - app.ApplicationServices.GetRequiredService(), + app.ApplicationServices.GetRequiredService>().Value, app.ApplicationServices.GetRequiredService()); diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs index a6cd372411..affb274662 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Runtime; using Umbraco.Tests.Common; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Integration.Implementations { @@ -102,14 +103,17 @@ namespace Umbraco.Tests.Integration.Implementations public override IBackOfficeInfo GetBackOfficeInfo() { if (_backOfficeInfo == null) - _backOfficeInfo = - new AspNetCoreBackOfficeInfo(SettingsForTests.GetDefaultGlobalSettings(GetUmbracoVersion())); + { + var globalSettings = new GlobalSettingsBuilder().Build(); + _backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); + } + return _backOfficeInfo; } public override IHostingEnvironment GetHostingEnvironment() => _hostingEnvironment ??= new TestHostingEnvironment( - SettingsForTests.DefaultHostingSettings, + new HostingSettingsBuilder().Build(), _hostEnvironment); public override IApplicationShutdownRegistry GetHostingEnvironmentLifetime() => _hostingLifetime; diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs index 076cecef4a..c03a1a1699 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs @@ -1,16 +1,15 @@ using Microsoft.AspNetCore.Hosting; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; namespace Umbraco.Tests.Integration.Implementations { - public class TestHostingEnvironment : AspNetCoreHostingEnvironment, IHostingEnvironment { - public TestHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) - : base(hostingSettings, webHostEnvironment) + public TestHostingEnvironment(HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) + : base(Options.Create(hostingSettings), webHostEnvironment) { } diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs index dec3b55c76..cf8f091dbc 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -118,7 +119,7 @@ namespace Umbraco.Tests.Persistence.Repositories var id = user.Id; - var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(),GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); + var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(), GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); repository2.Delete(user); diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index bd7684fcae..11bda500b2 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -17,6 +17,8 @@ using Umbraco.Tests.Integration.Implementations; using Umbraco.Tests.Integration.Testing; using Umbraco.Web.Common.AspNetCore; using Umbraco.Extensions; +using Umbraco.Tests.Common.Builders; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.Integration { @@ -54,8 +56,11 @@ namespace Umbraco.Tests.Integration var testHelper = new TestHelper(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); + // Create the core runtime - var coreRuntime = new CoreRuntime(testHelper.GetConfigs(), testHelper.GetUmbracoVersion(), + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, testHelper.GetUmbracoVersion(), testHelper.IOHelper, testHelper.Logger, testHelper.Profiler, testHelper.UmbracoBootPermissionChecker, testHelper.GetHostingEnvironment(), testHelper.GetBackOfficeInfo(), testHelper.DbProviderFactoryCreator, testHelper.MainDom, testHelper.GetTypeFinder(), NoAppCache.Instance); @@ -70,6 +75,23 @@ namespace Umbraco.Tests.Integration Assert.IsFalse(MyComponent.IsInit); Assert.IsFalse(MyComponent.IsTerminated); + // TODO: found these registration were necessary here (as we haven't called the HostBuilder?), and dependencies for ComponentCollection + // are not resolved. Need to check this if these explicit registrations are the best way to handle this. + var contentSettings = new ContentSettingsBuilder().Build(); + var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var userPasswordConfigurationSettings = new UserPasswordConfigurationSettingsBuilder().Build(); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + + umbracoContainer.Register(x => Options.Create(globalSettings)); + umbracoContainer.Register(x => Options.Create(contentSettings)); + umbracoContainer.Register(x => Options.Create(coreDebugSettings)); + umbracoContainer.Register(x => Options.Create(nuCacheSettings)); + umbracoContainer.Register(x => Options.Create(requestHandlerSettings)); + umbracoContainer.Register(x => Options.Create(userPasswordConfigurationSettings)); + umbracoContainer.Register(x => Options.Create(webRoutingSettings)); + coreRuntime.Start(); Assert.IsTrue(MyComponent.IsInit); diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 9988362d3b..f628437507 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Threading; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence; @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Integration.Testing public const string DatabaseName = "UmbracoTests"; private readonly ILogger _logger; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly LocalDb _localDb; private readonly IUmbracoVersion _umbracoVersion; private static LocalDb.Instance _instance; @@ -38,7 +39,7 @@ namespace Umbraco.Tests.Integration.Testing private DatabasePool _currentPool; //It's internal because `Umbraco.Core.Persistence.LocalDb` is internal - internal LocalDbTestDatabase(ILogger logger, IGlobalSettings globalSettings, LocalDb localDb, string filesPath, IUmbracoDatabaseFactory dbFactory) + internal LocalDbTestDatabase(ILogger logger, GlobalSettings globalSettings, LocalDb localDb, string filesPath, IUmbracoDatabaseFactory dbFactory) { _umbracoVersion = new UmbracoVersion(); _logger = logger; diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 89cbfa992d..562480df83 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -22,6 +22,8 @@ using Umbraco.Extensions; using Umbraco.Tests.Testing; using Umbraco.Web; using ILogger = Umbraco.Core.Logging.ILogger; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.Integration.Testing { @@ -54,7 +56,7 @@ namespace Umbraco.Tests.Integration.Testing /// /// There must only be ONE instance shared between all tests in a session /// - public static LocalDbTestDatabase GetOrCreate(string filesPath, ILogger logger, IGlobalSettings globalSettings, IUmbracoDatabaseFactory dbFactory) + public static LocalDbTestDatabase GetOrCreate(string filesPath, ILogger logger, GlobalSettings globalSettings, IUmbracoDatabaseFactory dbFactory) { lock (_dbLocker) { @@ -175,7 +177,7 @@ namespace Umbraco.Tests.Integration.Testing protected AppCaches AppCaches => Services.GetRequiredService(); protected IIOHelper IOHelper => Services.GetRequiredService(); protected IShortStringHelper ShortStringHelper => Services.GetRequiredService(); - protected IGlobalSettings GlobalSettings => Services.GetRequiredService(); + protected GlobalSettings GlobalSettings => Services.GetRequiredService>().Value; protected IMapperCollection Mappers => Services.GetRequiredService(); #endregion diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs index 3464259052..6fd5672085 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Hosting; using Umbraco.Extensions; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Implementations; using Umbraco.Web; using Umbraco.Web.BackOffice.Controllers; @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( @@ -50,8 +51,8 @@ namespace Umbraco.Tests.Security //hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); - + var globalSettings = new GlobalSettingsBuilder().Build(); + var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); var mgr = new BackOfficeCookieManager( Mock.Of(), @@ -72,7 +73,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -97,7 +98,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -119,7 +120,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs new file mode 100644 index 0000000000..c8ba34be60 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class ConnectionStringsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const string umbracoConnectionString = "connection string"; + + var builder = new ConnectionStringsBuilder(); + + // Act + var connectionStrings = builder + .WithUmbracoConnectionString(umbracoConnectionString) + .Build(); + + // Assert + Assert.AreEqual(umbracoConnectionString, connectionStrings.UmbracoConnectionString); + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs new file mode 100644 index 0000000000..d576f44072 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs @@ -0,0 +1,29 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class CoreDebugSettingsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const bool dumpOnTimeoutThreadAbort = true; + const bool logUncompletedScopes = true; + + var builder = new CoreDebugSettingsBuilder(); + + // Act + var coreDebugSettings = builder + .WithDumpOnTimeoutThreadAbort(dumpOnTimeoutThreadAbort) + .WithLogUncompletedScopes(logUncompletedScopes) + .Build(); + + // Assert + Assert.AreEqual(dumpOnTimeoutThreadAbort, coreDebugSettings.DumpOnTimeoutThreadAbort); + Assert.AreEqual(logUncompletedScopes, coreDebugSettings.LogUncompletedScopes); + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs similarity index 100% rename from src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs new file mode 100644 index 0000000000..e3f4bcf04e --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs @@ -0,0 +1,47 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class WebRoutingSettingsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const bool disableAlternativeTemplates = true; + const bool disableFindContentByIdPath = true; + const bool disableRedirectUrlTracking = true; + const bool internalRedirectPreservesTemplate = true; + const bool trySkipIisCustomErrors = true; + const string umbracoApplicationUrl = "/test/"; + const string urlProviderMode = "test"; + const bool validateAlternativeTemplates = true; + + var builder = new WebRoutingSettingsBuilder(); + + // Act + var webRoutingSettings = builder + .WithDisableAlternativeTemplates(disableAlternativeTemplates) + .WithDisableFindContentByIdPath(disableFindContentByIdPath) + .WithDisableRedirectUrlTracking(disableRedirectUrlTracking) + .WithInternalRedirectPreservesTemplate(internalRedirectPreservesTemplate) + .WithTrySkipIisCustomErrors(trySkipIisCustomErrors) + .WithUmbracoApplicationUrl(umbracoApplicationUrl) + .WithUrlProviderMode(urlProviderMode) + .WithValidateAlternativeTemplates(validateAlternativeTemplates) + .Build(); + + // Assert + Assert.AreEqual(disableAlternativeTemplates, webRoutingSettings.DisableAlternativeTemplates); + Assert.AreEqual(disableFindContentByIdPath, webRoutingSettings.DisableFindContentByIdPath); + Assert.AreEqual(disableRedirectUrlTracking, webRoutingSettings.DisableRedirectUrlTracking); + Assert.AreEqual(internalRedirectPreservesTemplate, webRoutingSettings.InternalRedirectPreservesTemplate); + Assert.AreEqual(trySkipIisCustomErrors, webRoutingSettings.TrySkipIisCustomErrors); + Assert.AreEqual(umbracoApplicationUrl, webRoutingSettings.UmbracoApplicationUrl); + Assert.AreEqual(urlProviderMode, webRoutingSettings.UrlProviderMode); + Assert.AreEqual(validateAlternativeTemplates, webRoutingSettings.ValidateAlternativeTemplates); + } + } +} From 863a7195b2d13ac3d110558cc55f833510d5af67 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Aug 2020 16:06:09 +0200 Subject: [PATCH 13/58] Restored Umbraco.Tests (partially) --- .../Models/RequestHandlerSettings.cs | 36 ++++----- .../Packaging/CompiledPackageXmlParser.cs | 6 +- .../ModelToSqlExpressionHelperBenchmarks.cs | 1 - .../Builders/ModelsBuilderConfigBuilder.cs | 12 +++ .../Builders/RequestHandlerSettingsBuilder.cs | 23 +++++- .../RequestHandlerSettingsBuilderTests.cs | 11 ++- .../Components/ComponentTests.cs | 38 +++++----- .../Composing/CollectionBuildersTests.cs | 2 +- .../Composing/CompositionTests.cs | 2 +- .../Composing/LazyCollectionBuilderTests.cs | 10 +-- .../Composing/PackageActionCollectionTests.cs | 2 +- .../Configurations/GlobalSettingsTests.cs | 9 +-- .../CoreThings/TryConvertToTests.cs | 4 +- src/Umbraco.Tests/IO/FileSystemsTests.cs | 2 +- src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 11 ++- .../Migrations/AdvancedMigrationTests.cs | 5 +- .../Migrations/MigrationPlanTests.cs | 5 +- src/Umbraco.Tests/Models/MediaXmlTest.cs | 5 +- .../ModelsBuilder/BuilderTests.cs | 10 ++- .../CreatedPackagesRepositoryTests.cs | 7 +- .../Packaging/PackageDataInstallationTests.cs | 6 +- .../Packaging/PackageInstallationTest.cs | 3 +- .../Persistence/DatabaseContextTests.cs | 7 +- .../Repositories/ContentTypeRepositoryTest.cs | 15 +++- .../Repositories/DictionaryRepositoryTest.cs | 7 +- .../Repositories/DocumentRepositoryTest.cs | 5 +- .../Repositories/DomainRepositoryTest.cs | 11 ++- .../Repositories/LanguageRepositoryTest.cs | 31 ++++---- .../Repositories/UserRepositoryTest.cs | 10 ++- .../Persistence/SchemaValidationTest.cs | 4 +- .../Persistence/SqlCeTableByTableTest.cs | 4 +- .../PropertyEditorValueEditorTests.cs | 6 +- .../Published/ConvertersTests.cs | 2 +- .../PublishedContent/NuCacheChildrenTests.cs | 14 ++-- .../PublishedContent/NuCacheTests.cs | 13 ++-- .../PublishedContentLanguageVariantTests.cs | 3 +- .../ContentFinderByUrlAndTemplateTests.cs | 4 +- .../Routing/GetContentUrlsTests.cs | 50 ++++++++----- .../Routing/RenderRouteHandlerTests.cs | 30 ++++---- .../Routing/UmbracoModuleTests.cs | 3 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 19 +++-- .../Scoping/ScopeEventDispatcherTests.cs | 2 +- .../Scoping/ScopedNuCacheTests.cs | 9 ++- .../Scoping/ScopedRepositoryTests.cs | 31 +++++--- .../BackOfficeOwinUserManagerTests.cs | 4 +- .../OwinDataProtectorTokenProviderTests.cs | 4 +- .../Services/ContentServiceEventTests.cs | 11 ++- .../ContentServicePublishBranchTests.cs | 9 ++- .../Services/ContentServiceTagsTests.cs | 15 ++-- .../Services/ContentServiceTests.cs | 74 ++++++++++--------- .../ContentTypeServiceVariantsTests.cs | 24 ++++-- .../Services/EntityServiceTests.cs | 6 +- .../Services/EntityXmlSerializerTests.cs | 18 +++-- .../Services/LocalizationServiceTests.cs | 28 ++++--- .../Services/SectionServiceTests.cs | 4 +- .../Services/UserServiceTests.cs | 5 +- .../Strings/DefaultShortStringHelperTests.cs | 73 +++++++++--------- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- .../TestHelpers/Entities/MockedUser.cs | 7 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 30 +++++--- .../TestHelpers/TestWithDatabaseBase.cs | 4 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 18 +++-- 62 files changed, 507 insertions(+), 319 deletions(-) create mode 100644 src/Umbraco.Tests.Common/Builders/ModelsBuilderConfigBuilder.cs diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs index b52285c42c..e168122738 100644 --- a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Configuration.Models { public class RequestHandlerSettings { - private static readonly CharItem[] DefaultCharCollection = + internal static readonly CharItem[] DefaultCharCollection = { new CharItem { Char = " ", Replacement = "-" }, new CharItem { Char = "\"", Replacement = "" }, @@ -40,33 +40,29 @@ namespace Umbraco.Core.Configuration.Models public bool TryConvertUrlsToAscii { get; set; } = false; //We need to special handle ":", as this character is special in keys - public IEnumerable CharCollection - { - get - { - // TODO: implement from configuration - //var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren() - // .Select(x => new CharItem() - // { - // Char = x.GetValue("Char"), - // Replacement = x.GetValue("Replacement"), - // }).ToArray(); + // TODO: implement from configuration - //if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x => - // x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase))) - //{ - // return collection; - //} + //var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren() + // .Select(x => new CharItem() + // { + // Char = x.GetValue("Char"), + // Replacement = x.GetValue("Replacement"), + // }).ToArray(); - return DefaultCharCollection; - } - } + //if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x => + // x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase))) + //{ + // return collection; + //} + // return DefaultCharCollection; + public IEnumerable CharCollection { get; set; } public class CharItem : IChar { public string Char { get; set; } + public string Replacement { get; set; } } } diff --git a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs index 510a4122e9..010e6469bf 100644 --- a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs +++ b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Packaging; using File = System.IO.File; @@ -15,9 +15,9 @@ namespace Umbraco.Core.Packaging public class CompiledPackageXmlParser { private readonly ConflictingPackageData _conflictingPackageData; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public CompiledPackageXmlParser(ConflictingPackageData conflictingPackageData, IGlobalSettings globalSettings) + public CompiledPackageXmlParser(ConflictingPackageData conflictingPackageData, GlobalSettings globalSettings) { _conflictingPackageData = conflictingPackageData; _globalSettings = globalSettings; diff --git a/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs index 6eb955ea8f..d200b3e295 100644 --- a/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.Linq.Expressions; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Diagnosers; -using Moq; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; diff --git a/src/Umbraco.Tests.Common/Builders/ModelsBuilderConfigBuilder.cs b/src/Umbraco.Tests.Common/Builders/ModelsBuilderConfigBuilder.cs new file mode 100644 index 0000000000..4b94339dc0 --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/ModelsBuilderConfigBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class ModelsBuilderConfigBuilder : BuilderBase + { + public override ModelsBuilderConfig Build() + { + return new ModelsBuilderConfig(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs index 43cdacbb9b..33f63c9d16 100644 --- a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs @@ -1,10 +1,14 @@ +using System.Collections.Generic; using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Tests.Common.Builders { public class RequestHandlerSettingsBuilder : BuilderBase { private bool? _addTrailingSlash; + private bool? _convertUrlsToAscii; + private IEnumerable _charCollection; public RequestHandlerSettingsBuilder WithAddTrailingSlash(bool addTrailingSlash) { @@ -12,13 +16,30 @@ namespace Umbraco.Tests.Common.Builders return this; } + public RequestHandlerSettingsBuilder WithConvertUrlsToAscii(bool convertUrlsToAscii) + { + _convertUrlsToAscii = convertUrlsToAscii; + return this; + } + + public RequestHandlerSettingsBuilder WithCharCollection(IEnumerable charCollection) + { + _charCollection = charCollection; + return this; + } + + public override RequestHandlerSettings Build() { var addTrailingSlash = _addTrailingSlash ?? false; + var convertUrlsToAscii = _convertUrlsToAscii ?? false; + var charCollection = _charCollection ?? RequestHandlerSettings.DefaultCharCollection; return new RequestHandlerSettings { - AddTrailingSlash = addTrailingSlash, + AddTrailingSlash = addTrailingSlash, + ConvertUrlsToAscii = convertUrlsToAscii, + CharCollection = charCollection, }; } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs index a6dd7f98a4..af6bc0ed6f 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs @@ -1,5 +1,9 @@ -using NUnit.Framework; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.Common.Builders; +using static Umbraco.Core.Configuration.Models.RequestHandlerSettings; namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders { @@ -11,16 +15,21 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders { // Arrange const bool addTrailingSlash = true; + const bool convertUrlsToAscii = true; + var charCollection = new List { new CharItem { Char = "a", Replacement = "b" } }; var builder = new RequestHandlerSettingsBuilder(); // Act var requestHandlerSettings = builder .WithAddTrailingSlash(addTrailingSlash) + .WithConvertUrlsToAscii(convertUrlsToAscii) .Build(); // Assert Assert.AreEqual(addTrailingSlash, requestHandlerSettings.AddTrailingSlash); + Assert.AreEqual(convertUrlsToAscii, requestHandlerSettings.ConvertUrlsToAscii); + Assert.AreEqual("a-b", string.Join(",", requestHandlerSettings.CharCollection.Select(x => $"{x.Char}-{x.Replacement}"))); } } } diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index a20b220940..6f86108edb 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -13,6 +14,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Components @@ -33,9 +35,11 @@ namespace Umbraco.Tests.Components var logger = Mock.Of(); var typeFinder = TestHelper.GetTypeFinder(); - var f = new UmbracoDatabaseFactory(logger, SettingsForTests.DefaultGlobalSettings, Mock.Of(), new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); - var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); - var coreDebug = Mock.Of(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); + var f = new UmbracoDatabaseFactory(logger, globalSettings, connectionStrings, new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); + var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, Options.Create(globalSettings), TestHelper.GetHostingEnvironment()); + var coreDebug = new CoreDebugSettingsBuilder().Build(); var mediaFileSystem = Mock.Of(); var p = new ScopeProvider(f, fs, coreDebug, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); @@ -71,7 +75,7 @@ namespace Umbraco.Tests.Components { var register = MockRegister(); var typeLoader = MockTypeLoader(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -110,7 +114,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -126,7 +130,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -141,7 +145,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -158,7 +162,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -181,7 +185,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -217,7 +221,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -243,7 +247,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -258,7 +262,7 @@ namespace Umbraco.Tests.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -276,7 +280,7 @@ namespace Umbraco.Tests.Components var register = MockRegister(); var typeLoader = MockTypeLoader(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs, TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -295,7 +299,7 @@ namespace Umbraco.Tests.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -334,7 +338,7 @@ namespace Umbraco.Tests.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -349,7 +353,7 @@ namespace Umbraco.Tests.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer26) }; var enableDisableAttributes = new[] { new DisableComposerAttribute(typeof(Composer26)) }; @@ -376,7 +380,7 @@ namespace Umbraco.Tests.Components var register = MockRegister(); var composition = new Composition(register, typeLoader, Mock.Of(), - MockRuntimeState(RuntimeLevel.Run), Configs, TestHelper.IOHelper, AppCaches.NoCache); + MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var allComposers = typeLoader.GetTypes().ToList(); var types = allComposers.Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")).ToList(); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 2d977e89c7..4416723a55 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.Composing Current.Reset(); var register = TestHelper.GetRegister(); - _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); } [TearDown] diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 380511eaaa..229ba1102b 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing var typeFinder = TestHelper.GetTypeFinder(); var ioHelper = TestHelper.IOHelper; var typeLoader = new TypeLoader(typeFinder, Mock.Of(), new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), logger); - var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); // create the factory, ensure it is the mocked factory var factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index 4d0135d6c4..c17e80a34a 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -67,7 +67,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -118,7 +118,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -140,7 +140,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 390997173b..118eaab41a 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Composing { var container = TestHelper.GetRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var expectedPackageActions = TypeLoader.GetPackageActions(); composition.WithCollectionBuilder() diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index 56237f562c..fa6949cd09 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -2,7 +2,9 @@ using NUnit.Framework; using Umbraco.Core.Configuration; using Umbraco.Core.IO; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; +using Umbraco.Web.Configuration; using Umbraco.Web.Hosting; namespace Umbraco.Tests.Configurations @@ -18,17 +20,14 @@ namespace Umbraco.Tests.Configurations [TestCase("~/some-wacky/nestedPath", "/MyVirtualDir/NestedVDir/", "some-wacky-nestedpath")] public void Umbraco_Mvc_Area(string path, string rootPath, string outcome) { - - var globalSettings = SettingsForTests.GenerateMockGlobalSettings(); var mockHostingSettings = Mock.Get(SettingsForTests.GenerateMockHostingSettings()); mockHostingSettings.Setup(x => x.ApplicationVirtualPath).Returns(rootPath); var hostingEnvironment = new AspNetHostingEnvironment(mockHostingSettings.Object); - var globalSettingsMock = Mock.Get(globalSettings); - globalSettingsMock.Setup(x => x.UmbracoPath).Returns(() => path); + var globalSettings = new GlobalSettingsBuilder().WithUmbracoPath(path).Build(); - Assert.AreEqual(outcome, globalSettingsMock.Object.GetUmbracoMvcAreaNoCache(hostingEnvironment)); + Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment)); } } } diff --git a/src/Umbraco.Tests/CoreThings/TryConvertToTests.cs b/src/Umbraco.Tests/CoreThings/TryConvertToTests.cs index fbb89b1c5d..cd26bf914f 100644 --- a/src/Umbraco.Tests/CoreThings/TryConvertToTests.cs +++ b/src/Umbraco.Tests/CoreThings/TryConvertToTests.cs @@ -1,6 +1,8 @@ using System; +using Microsoft.Extensions.Options; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Strings; using Umbraco.Tests.Testing; @@ -14,7 +16,7 @@ namespace Umbraco.Tests.CoreThings { base.Compose(); - Composition.RegisterUnique(f => new DefaultShortStringHelper(f.GetInstance())); + Composition.RegisterUnique(f => new DefaultShortStringHelper(f.GetInstance>())); } [Test] diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index c1d3fbb331..71dd954052 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.IO { _register = TestHelper.GetRegister(); - var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 07a04479a4..50ba5a3223 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -10,6 +11,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.IO @@ -436,7 +438,8 @@ namespace Umbraco.Tests.IO var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var globalSettings = Options.Create(new GlobalSettingsBuilder().Build()); + var fileSystems = new FileSystems(container, logger, ioHelper, globalSettings, TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem(phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -532,7 +535,8 @@ namespace Umbraco.Tests.IO var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var globalSettings = Options.Create(new GlobalSettingsBuilder().Build()); + var fileSystems = new FileSystems(container, logger, ioHelper, globalSettings, TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -587,7 +591,8 @@ namespace Umbraco.Tests.IO var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger, ioHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var globalSettings = Options.Create(new GlobalSettingsBuilder().Build()); + var fileSystems = new FileSystems(container, logger, ioHelper, globalSettings, TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper)fs.InnerFileSystem; diff --git a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs index 966c4109c6..dd5fd32971 100644 --- a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs @@ -9,8 +9,10 @@ using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; +using Umbraco.Web.Configuration; namespace Umbraco.Tests.Migrations { @@ -42,7 +44,8 @@ namespace Umbraco.Tests.Migrations upgrader.Execute(ScopeProvider, builder, Mock.Of(), logger); - var helper = new DatabaseSchemaCreator(scope.Database, logger, UmbracoVersion, TestObjects.GetGlobalSettings()); + var globalSettings = new GlobalSettingsBuilder().Build(); + var helper = new DatabaseSchemaCreator(scope.Database, logger, UmbracoVersion, globalSettings); var exists = helper.TableExists("umbracoUser"); Assert.IsTrue(exists); diff --git a/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs b/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs index a9785697f4..273255f987 100644 --- a/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs +++ b/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs @@ -13,8 +13,10 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Scoping; using Umbraco.Core.Services; using Umbraco.Persistance.SqlCe; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; +using Umbraco.Web.Configuration; namespace Umbraco.Tests.Migrations { @@ -139,7 +141,8 @@ namespace Umbraco.Tests.Migrations [Test] public void ValidateUmbracoPlan() { - var plan = new UmbracoPlan(TestHelper.GetUmbracoVersion(), SettingsForTests.GenerateMockGlobalSettings()); + var globalSettings = new GlobalSettingsBuilder().Build(); + var plan = new UmbracoPlan(TestHelper.GetUmbracoVersion(), globalSettings); plan.Validate(); Console.WriteLine(plan.FinalState); Assert.IsFalse(plan.FinalState.IsNullOrWhiteSpace()); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index 632f433c5b..b40e56c252 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -8,6 +8,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Strings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; @@ -31,10 +32,10 @@ namespace Umbraco.Tests.Models // and then, this will reset the width, height... because the file does not exist, of course ;-( var logger = Mock.Of(); var scheme = Mock.Of(); - var config = Mock.Of(); + var contentSettings = new ContentSettingsBuilder().Build(); var mediaFileSystem = new MediaFileSystem(Mock.Of(), scheme, logger, ShortStringHelper); - var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, config, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper); + var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, contentSettings, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper); var media = MockedMedia.CreateMediaImage(mediaType, -1); media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests diff --git a/src/Umbraco.Tests/ModelsBuilder/BuilderTests.cs b/src/Umbraco.Tests/ModelsBuilder/BuilderTests.cs index 6065570b13..91bf7406f3 100644 --- a/src/Umbraco.Tests/ModelsBuilder/BuilderTests.cs +++ b/src/Umbraco.Tests/ModelsBuilder/BuilderTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded; using Umbraco.ModelsBuilder.Embedded.Building; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.ModelsBuilder { @@ -42,7 +43,8 @@ namespace Umbraco.Tests.ModelsBuilder { }; - var builder = new TextBuilder(Mock.Of(), types); + var modelsBuilderConfig = new ModelsBuilderConfigBuilder().Build(); + var builder = new TextBuilder(modelsBuilderConfig, types); var btypes = builder.TypeModels; var sb = new StringBuilder(); @@ -150,7 +152,8 @@ namespace Umbraco.Web.PublishedModels " } }; - var builder = new TextBuilder(Mock.Of(), types); + var modelsBuilderConfig = new ModelsBuilderConfigBuilder().Build(); + var builder = new TextBuilder(modelsBuilderConfig, types); var btypes = builder.TypeModels; builder.ModelsNamespace = "Umbraco.Web.PublishedModels"; @@ -259,7 +262,8 @@ namespace Umbraco.Web.PublishedModels { }; - var builder = new TextBuilder(Mock.Of(), types); + var modelsBuilderConfig = new ModelsBuilderConfigBuilder().Build(); + var builder = new TextBuilder(modelsBuilderConfig, types); builder.ModelsNamespace = "Umbraco.ModelsBuilder.Models"; // forces conflict with Umbraco.ModelsBuilder.Umbraco var btypes = builder.TypeModels; diff --git a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs index 6533dd6113..90a352ad39 100644 --- a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs @@ -6,13 +6,10 @@ using System.Linq; using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.IO; using Umbraco.Core.Models.Packaging; using Umbraco.Core.Packaging; using Umbraco.Core.Services; -using Umbraco.Tests.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -44,7 +41,7 @@ namespace Umbraco.Tests.Packaging HostingEnvironment, Factory.GetInstance(), Logger, UmbracoVersion, - Factory.GetInstance(), + Microsoft.Extensions.Options.Options.Create(new GlobalSettingsBuilder().Build()), "createdPackages.config", //temp paths tempFolderPath: "~/" + _testBaseFolder + "/temp", diff --git a/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs b/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs index d089c4aaa2..ed1cd5424d 100644 --- a/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs +++ b/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs @@ -18,6 +18,7 @@ using Umbraco.Tests.Services.Importing; using Umbraco.Tests.Testing; using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Packaging { @@ -712,8 +713,9 @@ namespace Umbraco.Tests.Packaging private void AddLanguages() { - var norwegian = new Core.Models.Language(TestObjects.GetGlobalSettings(), "nb-NO"); - var english = new Core.Models.Language(TestObjects.GetGlobalSettings(), "en-GB"); + var globalSettings = new GlobalSettingsBuilder().Build(); + var norwegian = new Core.Models.Language(globalSettings, "nb-NO"); + var english = new Core.Models.Language(globalSettings, "en-GB"); ServiceContext.LocalizationService.Save(norwegian, 0); ServiceContext.LocalizationService.Save(english, 0); } diff --git a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs index 90db389002..1cfb9167ce 100644 --- a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs +++ b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs @@ -16,6 +16,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; using Umbraco.Core.Services; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using File = System.IO.File; @@ -55,7 +56,7 @@ namespace Umbraco.Tests.Packaging Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), - Factory.GetInstance(), + new GlobalSettingsBuilder().Build(), Factory.GetInstance() ); diff --git a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs index ba9bd19db5..8f4947952f 100644 --- a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs +++ b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Services; using Umbraco.Persistance.SqlCe; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Security; @@ -38,8 +39,8 @@ namespace Umbraco.Tests.Persistence _sqlSyntaxProviders = new[] { (ISqlSyntaxProvider) _sqlCeSyntaxProvider }; _logger = Mock.Of(); _umbracoVersion = TestHelper.GetUmbracoVersion(); - var globalSettings = TestHelper.GetConfigs().Global(); - var connectionStrings = TestHelper.GetConfigs().ConnectionStrings(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); _databaseFactory = new UmbracoDatabaseFactory(_logger, globalSettings, connectionStrings, new Lazy(() => Mock.Of()), TestHelper.DbProviderFactoryCreator); } @@ -94,7 +95,7 @@ namespace Umbraco.Tests.Persistence using (var database = _databaseFactory.CreateDatabase()) using (var transaction = database.GetTransaction()) { - schemaHelper = new DatabaseSchemaCreator(database, _logger, _umbracoVersion, SettingsForTests.GenerateMockGlobalSettings()); + schemaHelper = new DatabaseSchemaCreator(database, _logger, _umbracoVersion, new GlobalSettingsBuilder().Build()); schemaHelper.InitializeDatabaseSchema(); transaction.Complete(); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs index 53a632132d..0d6797bd9c 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs @@ -1,15 +1,18 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -21,21 +24,25 @@ namespace Umbraco.Tests.Persistence.Repositories [UmbracoTest(Mapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class ContentTypeRepositoryTest : TestWithDatabaseBase { + private IOptions _globalSettings; + public override void SetUp() { base.SetUp(); CreateTestData(); + + _globalSettings = Microsoft.Extensions.Options.Options.Create(new GlobalSettingsBuilder().Build()); } private DocumentRepository CreateRepository(IScopeAccessor scopeAccessor, out ContentTypeRepository contentTypeRepository) { - var langRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger,TestObjects.GetGlobalSettings()); + var langRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, _globalSettings); var templateRepository = new TemplateRepository(scopeAccessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(scopeAccessor, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(scopeAccessor, templateRepository, AppCaches.Disabled, ShortStringHelper); contentTypeRepository = new ContentTypeRepository(scopeAccessor, AppCaches.Disabled, Logger, commonRepository, langRepository, ShortStringHelper); - var languageRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, _globalSettings); var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(scopeAccessor); var relationRepository = new RelationRepository(scopeAccessor, Logger, relationTypeRepository, entityRepository); @@ -47,7 +54,7 @@ namespace Umbraco.Tests.Persistence.Repositories private ContentTypeRepository CreateRepository(IScopeAccessor scopeAccessor) { - var langRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var langRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, _globalSettings); var templateRepository = new TemplateRepository(scopeAccessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var commonRepository = new ContentTypeCommonRepository(scopeAccessor, templateRepository, AppCaches.Disabled, ShortStringHelper); var contentTypeRepository = new ContentTypeRepository(scopeAccessor, AppCaches.Disabled, Logger, commonRepository, langRepository, ShortStringHelper); @@ -58,7 +65,7 @@ namespace Umbraco.Tests.Persistence.Repositories { var templateRepository = new TemplateRepository(scopeAccessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var commonRepository = new ContentTypeCommonRepository(scopeAccessor, templateRepository, AppCaches.Disabled, ShortStringHelper); - var langRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var langRepository = new LanguageRepository(scopeAccessor, AppCaches.Disabled, Logger, _globalSettings); var contentTypeRepository = new MediaTypeRepository(scopeAccessor, AppCaches.Disabled, Logger, commonRepository, langRepository, ShortStringHelper); return contentTypeRepository; } diff --git a/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs index e23734acc3..fb9a4d2772 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs @@ -8,6 +8,7 @@ using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Persistence.Repositories { @@ -288,7 +289,8 @@ namespace Umbraco.Tests.Persistence.Repositories { var repository = CreateRepository(); - var languageNo = new Language(TestObjects.GetGlobalSettings(), "nb-NO") { CultureName = "nb-NO" }; + var globalSettings = new GlobalSettingsBuilder().Build(); + var languageNo = new Language(globalSettings, "nb-NO") { CultureName = "nb-NO" }; ServiceContext.LocalizationService.Save(languageNo); // Act @@ -373,7 +375,8 @@ namespace Umbraco.Tests.Persistence.Repositories { var language = ServiceContext.LocalizationService.GetLanguageByIsoCode("en-US"); - var languageDK = new Language(TestObjects.GetGlobalSettings(), "da-DK") { CultureName = "da-DK" }; + var globalSettings = new GlobalSettingsBuilder().Build(); + var languageDK = new Language(globalSettings, "da-DK") { CultureName = "da-DK" }; ServiceContext.LocalizationService.Save(languageDK);//Id 2 var readMore = new DictionaryItem("Read More"); diff --git a/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs index fe59e431ec..03cfe1af53 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs @@ -20,6 +20,7 @@ using Umbraco.Core.Scoping; using Umbraco.Core.Services; using Umbraco.Tests.Testing; using Umbraco.Web.PropertyEditors; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Persistence.Repositories { @@ -62,12 +63,14 @@ namespace Umbraco.Tests.Persistence.Repositories private DocumentRepository CreateRepository(IScopeAccessor scopeAccessor, out ContentTypeRepository contentTypeRepository, out TemplateRepository templateRepository, AppCaches appCaches = null) { + var globalSettings = Microsoft.Extensions.Options.Options.Create(new GlobalSettingsBuilder().Build()); + appCaches = appCaches ?? AppCaches; templateRepository = new TemplateRepository(scopeAccessor, appCaches, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(scopeAccessor, appCaches, Logger); var commonRepository = new ContentTypeCommonRepository(scopeAccessor, templateRepository, appCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(scopeAccessor, appCaches, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(scopeAccessor, appCaches, Logger, globalSettings); contentTypeRepository = new ContentTypeRepository(scopeAccessor, appCaches, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(scopeAccessor); diff --git a/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs index 91d129aeeb..c3bf9db5de 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -21,11 +22,13 @@ namespace Umbraco.Tests.Persistence.Repositories { private DomainRepository CreateRepository(IScopeProvider provider, out ContentTypeRepository contentTypeRepository, out DocumentRepository documentRepository, out LanguageRepository languageRepository) { + var globalSettings = Microsoft.Extensions.Options.Options.Create(new GlobalSettingsBuilder().Build()); + var accessor = (IScopeAccessor) provider; var templateRepository = new TemplateRepository(accessor, Core.Cache.AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(accessor, Core.Cache.AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches, ShortStringHelper); - languageRepository = new LanguageRepository(accessor, Core.Cache.AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + languageRepository = new LanguageRepository(accessor, Core.Cache.AppCaches.Disabled, Logger, globalSettings); contentTypeRepository = new ContentTypeRepository(accessor, Core.Cache.AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, Core.Cache.AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(accessor); @@ -48,7 +51,8 @@ namespace Umbraco.Tests.Persistence.Repositories var repo = CreateRepository(provider, out contentTypeRepo, out documentRepo, out langRepo); - var lang = new Language(TestObjects.GetGlobalSettings(), isoName); + var globalSettings = new GlobalSettingsBuilder().Build(); + var lang = new Language(globalSettings, isoName); langRepo.Save(lang); ct = MockedContentTypes.CreateBasicContentType("test", "Test"); @@ -203,7 +207,8 @@ namespace Umbraco.Tests.Persistence.Repositories //more test data var lang1 = langRepo.GetByIsoCode("en-AU"); - var lang2 = new Language(TestObjects.GetGlobalSettings(), "es"); + var globalSettings = new GlobalSettingsBuilder().Build(); + var lang2 = new Language(globalSettings, "es"); langRepo.Save(lang2); var content2 = new Content("test", -1, ct) { CreatorId = 0, WriterId = 0 }; documentRepo.Save(content2); diff --git a/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs index b1dbe7b6e0..dae0200550 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/LanguageRepositoryTest.cs @@ -4,12 +4,13 @@ using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -19,16 +20,20 @@ namespace Umbraco.Tests.Persistence.Repositories [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class LanguageRepositoryTest : TestWithDatabaseBase { + private GlobalSettings _globalSettings; + public override void SetUp() { base.SetUp(); CreateTestData(); + + _globalSettings = new GlobalSettingsBuilder().Build(); } private LanguageRepository CreateRepository(IScopeProvider provider) { - return new LanguageRepository((IScopeAccessor) provider, AppCaches.Disabled, Mock.Of(), TestObjects.GetGlobalSettings()); + return new LanguageRepository((IScopeAccessor) provider, AppCaches.Disabled, Mock.Of(), Microsoft.Extensions.Options.Options.Create(_globalSettings)); } [Test] @@ -62,7 +67,7 @@ namespace Umbraco.Tests.Persistence.Repositories var repository = CreateRepository(provider); var au = CultureInfo.GetCultureInfo("en-AU"); - var language = (ILanguage)new Language(TestObjects.GetGlobalSettings(), au.Name) + var language = (ILanguage)new Language(_globalSettings, au.Name) { CultureName = au.DisplayName, FallbackLanguageId = 1 @@ -186,7 +191,7 @@ namespace Umbraco.Tests.Persistence.Repositories var repository = CreateRepository(provider); // Act - var languageBR = new Language(TestObjects.GetGlobalSettings(), "pt-BR") { CultureName = "pt-BR" }; + var languageBR = new Language(_globalSettings, "pt-BR") { CultureName = "pt-BR" }; repository.Save(languageBR); // Assert @@ -208,7 +213,7 @@ namespace Umbraco.Tests.Persistence.Repositories var repository = CreateRepository(provider); // Act - var languageBR = new Language(TestObjects.GetGlobalSettings(), "pt-BR") { CultureName = "pt-BR", IsDefault = true, IsMandatory = true }; + var languageBR = new Language(_globalSettings, "pt-BR") { CultureName = "pt-BR", IsDefault = true, IsMandatory = true }; repository.Save(languageBR); // Assert @@ -230,7 +235,7 @@ namespace Umbraco.Tests.Persistence.Repositories var repository = CreateRepository(provider); // Act - var languageBR = new Language(TestObjects.GetGlobalSettings(), "pt-BR") + var languageBR = new Language(_globalSettings, "pt-BR") { CultureName = "pt-BR", FallbackLanguageId = 1 @@ -253,16 +258,16 @@ namespace Umbraco.Tests.Persistence.Repositories { var repository = CreateRepository(provider); - var languageBR = (ILanguage)new Language(TestObjects.GetGlobalSettings(), "pt-BR") { CultureName = "pt-BR", IsDefault = true, IsMandatory = true }; + var languageBR = (ILanguage)new Language(_globalSettings, "pt-BR") { CultureName = "pt-BR", IsDefault = true, IsMandatory = true }; repository.Save(languageBR); - var languageEN = new Language(TestObjects.GetGlobalSettings(), "en-AU") { CultureName = "en-AU" }; + var languageEN = new Language(_globalSettings, "en-AU") { CultureName = "en-AU" }; repository.Save(languageEN); Assert.IsTrue(languageBR.IsDefault); Assert.IsTrue(languageBR.IsMandatory); // Act - var languageNZ = new Language(TestObjects.GetGlobalSettings(), "en-NZ") { CultureName = "en-NZ", IsDefault = true, IsMandatory = true }; + var languageNZ = new Language(_globalSettings, "en-NZ") { CultureName = "en-NZ", IsDefault = true, IsMandatory = true }; repository.Save(languageNZ); languageBR = repository.Get(languageBR.Id); @@ -390,16 +395,16 @@ namespace Umbraco.Tests.Persistence.Repositories { //Id 1 is en-US - when Umbraco is installed - var languageDK = new Language(TestObjects.GetGlobalSettings(), "da-DK") { CultureName = "da-DK" }; + var languageDK = new Language(_globalSettings, "da-DK") { CultureName = "da-DK" }; ServiceContext.LocalizationService.Save(languageDK);//Id 2 - var languageSE = new Language(TestObjects.GetGlobalSettings(), "sv-SE") { CultureName = "sv-SE" }; + var languageSE = new Language(_globalSettings, "sv-SE") { CultureName = "sv-SE" }; ServiceContext.LocalizationService.Save(languageSE);//Id 3 - var languageDE = new Language(TestObjects.GetGlobalSettings(), "de-DE") { CultureName = "de-DE" }; + var languageDE = new Language(_globalSettings, "de-DE") { CultureName = "de-DE" }; ServiceContext.LocalizationService.Save(languageDE);//Id 4 - var languagePT = new Language(TestObjects.GetGlobalSettings(), "pt-PT") { CultureName = "pt-PT" }; + var languagePT = new Language(_globalSettings, "pt-PT") { CultureName = "pt-PT" }; ServiceContext.LocalizationService.Save(languagePT);//Id 5 } } diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs index 03fc77572a..e49d6854d2 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs @@ -16,6 +16,7 @@ using System; using Umbraco.Core.Configuration; using Umbraco.Core.Serialization; using Umbraco.Core.Configuration.Models; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Persistence.Repositories { @@ -28,9 +29,10 @@ namespace Umbraco.Tests.Persistence.Repositories private MediaRepository CreateMediaRepository(IScopeProvider provider, out IMediaTypeRepository mediaTypeRepository) { var accessor = (IScopeAccessor) provider; + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = new TemplateRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); mediaTypeRepository = new MediaTypeRepository(accessor, AppCaches, Mock.Of(), commonRepository, languageRepository, ShortStringHelper); var tagRepository = new TagRepository(accessor, AppCaches, Mock.Of()); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Logger); @@ -52,10 +54,11 @@ namespace Umbraco.Tests.Persistence.Repositories private DocumentRepository CreateContentRepository(IScopeProvider provider, out IContentTypeRepository contentTypeRepository, out ITemplateRepository templateRepository) { var accessor = (IScopeAccessor) provider; + var globalSettings = new GlobalSettingsBuilder().Build(); templateRepository = new TemplateRepository(accessor, AppCaches, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(accessor, AppCaches, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); contentTypeRepository = new ContentTypeRepository(accessor, AppCaches, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(accessor); @@ -69,7 +72,8 @@ namespace Umbraco.Tests.Persistence.Repositories private UserRepository CreateRepository(IScopeProvider provider) { var accessor = (IScopeAccessor) provider; - var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, TestObjects.GetGlobalSettings(), new UserPasswordConfigurationSettings(), new JsonNetSerializer()); + var globalSettings = new GlobalSettingsBuilder().Build(); + var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, globalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); return repository; } diff --git a/src/Umbraco.Tests/Persistence/SchemaValidationTest.cs b/src/Umbraco.Tests/Persistence/SchemaValidationTest.cs index 0648e3bc21..27bab47968 100644 --- a/src/Umbraco.Tests/Persistence/SchemaValidationTest.cs +++ b/src/Umbraco.Tests/Persistence/SchemaValidationTest.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence.SqlSyntax; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -22,7 +23,8 @@ namespace Umbraco.Tests.Persistence using (var scope = ScopeProvider.CreateScope()) { - var schema = new DatabaseSchemaCreator(scope.Database, Logger, UmbracoVersion, TestObjects.GetGlobalSettings()); + var globalSettings = new GlobalSettingsBuilder().Build(); + var schema = new DatabaseSchemaCreator(scope.Database, Logger, UmbracoVersion, globalSettings); result = schema.ValidateSchema( //TODO: When we remove the xml cache from tests we can remove this too DatabaseSchemaCreator.OrderedTables.Concat(new []{typeof(ContentXmlDto), typeof(PreviewXmlDto)})); diff --git a/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs b/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs index 207e595598..337f1a7289 100644 --- a/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs @@ -2,10 +2,12 @@ using NPoco; using NUnit.Framework; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -16,7 +18,7 @@ namespace Umbraco.Tests.Persistence [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class SqlCeTableByTableTest : TestWithDatabaseBase { - public IGlobalSettings GlobalSettings => SettingsForTests.GenerateMockGlobalSettings(); + public GlobalSettings GlobalSettings => new GlobalSettingsBuilder().Build(); [Test] public void Can_Create_umbracoNode_Table() diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 6301be051d..439036fa16 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Components; using Umbraco.Tests.TestHelpers; using Current = Umbraco.Web.Composing.Current; @@ -25,10 +26,11 @@ namespace Umbraco.Tests.PropertyEditors Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); register.Register(_ - => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()))); + => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings))); Current.Factory = composition.CreateFactory(); } diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 3ecae51ea8..2ae4c238cc 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -182,7 +182,7 @@ namespace Umbraco.Tests.Published // Current.Reset(); var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index f0aa39fcf8..d224d97467 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -22,6 +23,7 @@ using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Core.Strings; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Strings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing.Objects; @@ -60,12 +62,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = TestHelper.GetConfigs(); - Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(); var hostingEnvironment = Mock.Of(); - configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); - configs.Add(() => globalSettings); Mock.Get(factory).Setup(x => x.GetInstance(typeof(IPublishedModelFactory))).Returns(PublishedModelFactory); @@ -145,8 +142,9 @@ namespace Umbraco.Tests.PublishedContent _source = new TestDataSource(kits()); var typeFinder = TestHelper.GetTypeFinder(); - var settings = Mock.Of(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; @@ -164,14 +162,14 @@ namespace Umbraco.Tests.PublishedContent Mock.Of(), new TestDefaultCultureAccessor(), _source, - globalSettings, + Options.Create(globalSettings), Mock.Of(), PublishedModelFactory, new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(TestHelper.ShortStringHelper) }), hostingEnvironment, new MockShortStringHelper(), TestHelper.IOHelper, - settings); + Options.Create(nuCacheSettings)); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 8003bdf236..da67a76eb9 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -20,6 +20,7 @@ using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Core.Strings; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Strings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing.Objects; @@ -53,12 +54,6 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = TestHelper.GetConfigs(); - Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(); - configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); - configs.Add(() => globalSettings); - var publishedModelFactory = new NoopPublishedModelFactory(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(IPublishedModelFactory))).Returns(publishedModelFactory); @@ -186,7 +181,9 @@ namespace Umbraco.Tests.PublishedContent _variationAccesor = new TestVariationContextAccessor(); var typeFinder = TestHelper.GetTypeFinder(); - var settings = Mock.Of(); + + var globalSettings = new GlobalSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; @@ -211,7 +208,7 @@ namespace Umbraco.Tests.PublishedContent TestHelper.GetHostingEnvironment(), new MockShortStringHelper(), TestHelper.IOHelper, - settings); + nuCacheSettings); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs index 8c1024351b..50e82998f9 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Web; @@ -34,11 +35,11 @@ namespace Umbraco.Tests.PublishedContent private static void MockLocalizationService(ServiceContext serviceContext) { - var globalSettings = SettingsForTests.GenerateMockGlobalSettings(); // Set up languages. // Spanish falls back to English and Italian to Spanish (and then to English). // French has no fall back. // Danish, Swedish and Norweigan create an invalid loop. + var globalSettings = new GlobalSettingsBuilder().Build(); var languages = new List { new Language(globalSettings, "en-US") { Id = 1, CultureName = "English", IsDefault = true }, diff --git a/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs index e8b8bab22b..07f0e587e3 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs @@ -8,6 +8,7 @@ using Umbraco.Web.Routing; using Umbraco.Core.Models; using Umbraco.Tests.Testing; using Current = Umbraco.Web.Composing.Current; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -38,7 +39,8 @@ namespace Umbraco.Tests.Routing var umbracoContext = GetUmbracoContext(urlAsString, template1.Id, globalSettings:globalSettings.Object); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); - var lookup = new ContentFinderByUrlAndTemplate(Logger, ServiceContext.FileService, ServiceContext.ContentTypeService, SettingsForTests.GenerateMockWebRoutingSettings()); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + var lookup = new ContentFinderByUrlAndTemplate(Logger, ServiceContext.FileService, ServiceContext.ContentTypeService, webRoutingSettings); var result = lookup.TryFindContent(frequest); diff --git a/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs b/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs index 4f11802b43..7456d32aa4 100644 --- a/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs +++ b/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs @@ -1,26 +1,35 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Globalization; using System.Linq; using Moq; using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Web.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.TestHelpers.Entities; -using Umbraco.Web; -using Umbraco.Web.Routing; using Umbraco.Tests.Common; -using SettingsForTests = Umbraco.Tests.TestHelpers.SettingsForTests; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.TestHelpers.Entities; +using Umbraco.Web.Routing; namespace Umbraco.Tests.Routing { [TestFixture] public class GetContentUrlsTests : UrlRoutingTestBase { + private GlobalSettings _globalSettings; + private WebRoutingSettings _webRoutingSettings; + private RequestHandlerSettings _requestHandlerSettings; + + public override void SetUp() + { + base.SetUp(); + + _globalSettings = new GlobalSettingsBuilder().Build(); + _webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + _requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + } + private ILocalizedTextService GetTextService() { var textService = Mock.Of( @@ -34,7 +43,7 @@ namespace Umbraco.Tests.Routing { var allLangs = isoCodes .Select(CultureInfo.GetCultureInfo) - .Select(culture => new Language(TestObjects.GetGlobalSettings(), culture.Name) + .Select(culture => new Language(_globalSettings, culture.Name) { CultureName = culture.DisplayName, IsDefault = true, @@ -78,15 +87,17 @@ namespace Umbraco.Tests.Routing content.Path = "-1,1046"; content.Published = true; - var umbracoSettings = SettingsForTests.GenerateMockRequestHandlerSettings(); - var umbContext = GetUmbracoContext("http://localhost:8000"); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext); - var urlProvider = new DefaultUrlProvider(umbracoSettings, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(_requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(_globalSettings), + new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = new UrlProvider( umbracoContextAccessor, - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(_webRoutingSettings), new UrlProviderCollection(new []{urlProvider}), new MediaUrlProviderCollection(Enumerable.Empty()), Mock.Of() @@ -123,15 +134,16 @@ namespace Umbraco.Tests.Routing child.Path = "-1,1046,1173"; child.Published = true; - var umbracoSettings = SettingsForTests.GenerateMockRequestHandlerSettings(); - - var umbContext = GetUmbracoContext("http://localhost:8000"); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext); - var urlProvider = new DefaultUrlProvider(umbracoSettings, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(_requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(_globalSettings), + new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = new UrlProvider( umbracoContextAccessor, - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(_webRoutingSettings), new UrlProviderCollection(new []{urlProvider}), new MediaUrlProviderCollection(Enumerable.Empty()), Mock.Of() diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 358a47f09b..dc6caa3ce0 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -6,27 +6,30 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.TestHelpers.Stubs; -using Umbraco.Web; -using Umbraco.Web.Models; -using Umbraco.Web.Mvc; -using Umbraco.Web.WebApi; -using Umbraco.Core.Strings; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Runtime; using Umbraco.Core.Services; +using Umbraco.Core.Strings; +using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.PublishedContent; +using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Tests.Testing; +using Umbraco.Web; +using Umbraco.Web.Models; +using Umbraco.Web.Mvc; using Umbraco.Web.Runtime; +using Umbraco.Web.WebApi; +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; using Current = Umbraco.Web.Composing.Current; using ILogger = Umbraco.Core.Logging.ILogger; -using Umbraco.Tests.Common; namespace Umbraco.Tests.Routing { @@ -49,8 +52,8 @@ namespace Umbraco.Tests.Routing public class TestRuntime : CoreRuntime { - public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - : base(configs, umbracoVersion, ioHelper, Mock.Of(), Mock.Of(), new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) + public TestRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + : base(globalSettings, connectionStrings, umbracoVersion, ioHelper, Mock.Of(), Mock.Of(), new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) { } @@ -69,7 +72,8 @@ namespace Umbraco.Tests.Routing var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(Composition.TypeLoader.GetUmbracoApiControllers()); Composition.RegisterUnique(umbracoApiControllerTypes); - Composition.RegisterUnique(_ => new DefaultShortStringHelper(TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings())); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + Composition.RegisterUnique(_ => new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings))); } public override void TearDown() diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 0165e7714f..4dfcd46788 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; +using Umbraco.Web.Configuration; namespace Umbraco.Tests.Routing { @@ -32,7 +33,7 @@ namespace Umbraco.Tests.Routing //create the module var logger = Mock.Of(); var globalSettings = TestObjects.GetGlobalSettings(); - var runtime = new RuntimeState(globalSettings, UmbracoVersion); + var runtime = new RuntimeState(ConfigModelConversions.ConvertGlobalSettings(globalSettings), UmbracoVersion); _module = new UmbracoInjectedModule ( diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index ac0ff3f9f9..5984164497 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -37,6 +37,7 @@ using Current = Umbraco.Web.Composing.Current; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Composing; using Umbraco.Core.Media; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Runtimes { @@ -63,10 +64,10 @@ namespace Umbraco.Tests.Runtimes var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = AppCaches.Disabled; - var globalSettings = TestHelper.GetConfigs().Global(); - var connectionStrings = TestHelper.GetConfigs().ConnectionStrings(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); var typeFinder = TestHelper.GetTypeFinder(); - var databaseFactory = new UmbracoDatabaseFactory(logger,globalSettings, connectionStrings, new Lazy(() => factory.GetInstance()), TestHelper.DbProviderFactoryCreator); + var databaseFactory = new UmbracoDatabaseFactory(logger, globalSettings, connectionStrings, new Lazy(() => factory.GetInstance()), TestHelper.DbProviderFactoryCreator); var ioHelper = TestHelper.IOHelper; var hostingEnvironment = Mock.Of(); var typeLoader = new TypeLoader(typeFinder, appCaches.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), profilingLogger); @@ -77,14 +78,13 @@ namespace Umbraco.Tests.Runtimes var configs = TestHelper.GetConfigs(); var variationContextAccessor = TestHelper.VariationContextAccessor; - // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, ioHelper, appCaches); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); // create the core runtime and have it compose itself - var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); // determine actual runtime level runtimeState.DetermineRuntimeLevel(databaseFactory, logger); @@ -124,8 +124,6 @@ namespace Umbraco.Tests.Runtimes .Append(); // configure - composition.Configs.Add(() => TestHelpers.SettingsForTests.DefaultGlobalSettings); - composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); // create and register the factory Current.Factory = factory = composition.CreateFactory(); @@ -163,7 +161,8 @@ namespace Umbraco.Tests.Runtimes var scopeProvider = factory.GetInstance(); using (var scope = scopeProvider.CreateScope()) { - var creator = new DatabaseSchemaCreator(scope.Database, logger, umbracoVersion, TestHelpers.SettingsForTests.DefaultGlobalSettings); + var globalSettings = new GlobalSettingsBuilder().Build(); + var creator = new DatabaseSchemaCreator(scope.Database, logger, umbracoVersion, globalSettings); creator.InitializeDatabaseSchema(); scope.Complete(); } @@ -273,7 +272,7 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, ioHelper, appCaches); var umbracoVersion = TestHelper.GetUmbracoVersion(); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index be609f9a83..c646bdcf79 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Scoping var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); _testObjects = new TestObjects(register); diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 49bca378c7..35f4f421bd 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -20,6 +20,7 @@ using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; using Umbraco.Core.Sync; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Strings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -87,7 +88,9 @@ namespace Umbraco.Tests.Scoping var hostingEnvironment = TestHelper.GetHostingEnvironment(); var typeFinder = TestHelper.GetTypeFinder(); - var settings = Mock.Of(); + + var globalSettings = new GlobalSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); return new PublishedSnapshotService( options, @@ -102,14 +105,14 @@ namespace Umbraco.Tests.Scoping documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, new DatabaseDataSource(Mock.Of()), - Factory.GetInstance(), + Microsoft.Extensions.Options.Options.Create(globalSettings), Factory.GetInstance(), new NoopPublishedModelFactory(), new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(ShortStringHelper) }), hostingEnvironment, new MockShortStringHelper(), IOHelper, - settings); + Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); } protected IUmbracoContext GetUmbracoContextNu(string url, RouteData routeData = null, bool setSingleton = false) diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs index 4c3bb288e4..da90d7fefa 100644 --- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs @@ -1,21 +1,23 @@ using System; using System.Collections.Generic; using System.Linq; +using Moq; using NUnit.Framework; +using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Web.Composing; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Events; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Scoping; +using Umbraco.Core.Sync; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; -using Umbraco.Web.Cache; -using Moq; -using Umbraco.Core; -using Umbraco.Core.Events; -using Umbraco.Core.Logging; -using Umbraco.Core.Sync; using Umbraco.Web; +using Umbraco.Web.Cache; +using Umbraco.Web.Composing; namespace Umbraco.Tests.Scoping { @@ -25,6 +27,15 @@ namespace Umbraco.Tests.Scoping { private DistributedCacheBinder _distributedCacheBinder; + private GlobalSettings _globalSettings; + + public override void SetUp() + { + base.SetUp(); + + _globalSettings = new GlobalSettingsBuilder().Build(); + } + protected override void Compose() { base.Compose(); @@ -63,7 +74,7 @@ namespace Umbraco.Tests.Scoping var service = ServiceContext.UserService; var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof(IUser)); - var user = (IUser)new User(TestObjects.GetGlobalSettings(), "name", "email", "username", "rawPassword"); + var user = (IUser)new User(_globalSettings, "name", "email", "username", "rawPassword"); service.Save(user); // global cache contains the entity @@ -140,7 +151,7 @@ namespace Umbraco.Tests.Scoping var service = ServiceContext.LocalizationService; var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof (ILanguage)); - var lang = (ILanguage) new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var lang = (ILanguage) new Language(_globalSettings, "fr-FR"); service.Save(lang); // global cache has been flushed, reload @@ -232,7 +243,7 @@ namespace Umbraco.Tests.Scoping var service = ServiceContext.LocalizationService; var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof (IDictionaryItem)); - var lang = (ILanguage)new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var lang = (ILanguage)new Language(_globalSettings, "fr-FR"); service.Save(lang); var item = (IDictionaryItem) new DictionaryItem("item-key"); diff --git a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs index 8958eabd42..b6a8c225e0 100644 --- a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs @@ -11,6 +11,7 @@ using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.Models.Membership; using Umbraco.Net; +using Umbraco.Tests.Common.Builders; using Umbraco.Web.Security; namespace Umbraco.Tests.Security @@ -44,7 +45,8 @@ namespace Umbraco.Tests.Security var mockGlobalSettings = new Mock(); mockGlobalSettings.Setup(x => x.DefaultUILanguage).Returns("test"); - var user = new BackOfficeIdentityUser(mockGlobalSettings.Object, 2, new List()) + var globalSettings = new GlobalSettingsBuilder().Build(); + var user = new BackOfficeIdentityUser(globalSettings, 2, new List()) { UserName = "alice", Name = "Alice", diff --git a/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs b/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs index 7b1ca53104..65efdfeb0d 100644 --- a/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs +++ b/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.Models.Membership; +using Umbraco.Tests.Common.Builders; using Umbraco.Web.Security; namespace Umbraco.Tests.Security @@ -227,6 +228,7 @@ namespace Umbraco.Tests.Security _mockDataProtector.Setup(x => x.Protect(It.IsAny())).Returns((byte[] originalBytes) => originalBytes); _mockDataProtector.Setup(x => x.Unprotect(It.IsAny())).Returns((byte[] originalBytes) => originalBytes); + var globalSettings = new GlobalSettingsBuilder().Build(); var mockGlobalSettings = new Mock(); mockGlobalSettings.Setup(x => x.DefaultUILanguage).Returns("test"); @@ -234,7 +236,7 @@ namespace Umbraco.Tests.Security null, null, null, null, null, null, null, null); _mockUserManager.Setup(x => x.SupportsUserSecurityStamp).Returns(false); - _testUser = new BackOfficeIdentityUser(mockGlobalSettings.Object, 2, new List()) + _testUser = new BackOfficeIdentityUser(globalSettings, 2, new List()) { UserName = "alice", Name = "Alice", diff --git a/src/Umbraco.Tests/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests/Services/ContentServiceEventTests.cs index 26f6d37456..208afe5b4b 100644 --- a/src/Umbraco.Tests/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceEventTests.cs @@ -1,11 +1,13 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -18,10 +20,13 @@ namespace Umbraco.Tests.Services Logger = UmbracoTestOptions.Logger.Console)] public class ContentServiceEventTests : TestWithSomeContentBase { + private GlobalSettings _globalSettings; + public override void SetUp() { base.SetUp(); ContentRepositoryBase.ThrowOnWarning = true; + _globalSettings = new GlobalSettingsBuilder().Build(); } public override void TearDown() @@ -35,7 +40,7 @@ namespace Umbraco.Tests.Services { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); + languageService.Save(new Language(_globalSettings, "fr-FR")); var contentTypeService = ServiceContext.ContentTypeService; @@ -146,7 +151,7 @@ namespace Umbraco.Tests.Services { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); + languageService.Save(new Language(_globalSettings, "fr-FR")); var contentTypeService = ServiceContext.ContentTypeService; @@ -312,7 +317,7 @@ namespace Umbraco.Tests.Services { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); + languageService.Save(new Language(_globalSettings, "fr-FR")); var contentTypeService = ServiceContext.ContentTypeService; diff --git a/src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs b/src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs index d856f3bd82..35bbaa5f68 100644 --- a/src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs +++ b/src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -425,11 +426,13 @@ namespace Umbraco.Tests.Services private void CreateTypes(out IContentType iContentType, out IContentType vContentType) { - var langDe = new Language(TestObjects.GetGlobalSettings(), "de") { IsDefault = true }; + var globalSettings = new GlobalSettingsBuilder().Build(); + + var langDe = new Language(globalSettings, "de") { IsDefault = true }; ServiceContext.LocalizationService.Save(langDe); - var langRu = new Language(TestObjects.GetGlobalSettings(), "ru"); + var langRu = new Language(globalSettings, "ru"); ServiceContext.LocalizationService.Save(langRu); - var langEs = new Language(TestObjects.GetGlobalSettings(), "es"); + var langEs = new Language(globalSettings, "es"); ServiceContext.LocalizationService.Save(langEs); iContentType = new ContentType(ShortStringHelper, -1) diff --git a/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs b/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs index 5e2c3823af..10bd82cbde 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs @@ -9,6 +9,8 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; +using Umbraco.Core.Configuration.Models; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Services { @@ -19,12 +21,15 @@ namespace Umbraco.Tests.Services Logger = UmbracoTestOptions.Logger.Console)] public class ContentServiceTagsTests : TestWithSomeContentBase { + private GlobalSettings _globalSettings; + public PropertyEditorCollection PropertyEditorCollection => Factory.GetInstance(); public override void SetUp() { base.SetUp(); ContentRepositoryBase.ThrowOnWarning = true; + _globalSettings = new GlobalSettingsBuilder().Build(); } public override void TearDown() @@ -81,7 +86,7 @@ namespace Umbraco.Tests.Services public void TagsCanBeVariant() { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); // en-US is already there + languageService.Save(new Language(_globalSettings, "fr-FR")); // en-US is already there var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; @@ -205,7 +210,7 @@ namespace Umbraco.Tests.Services public void TagsCanBecomeInvariant() { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); // en-US is already there + languageService.Save(new Language(_globalSettings, "fr-FR")); // en-US is already there var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; @@ -262,7 +267,7 @@ namespace Umbraco.Tests.Services public void TagsCanBecomeInvariant2() { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); // en-US is already there + languageService.Save(new Language(_globalSettings, "fr-FR")); // en-US is already there var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; @@ -309,7 +314,7 @@ namespace Umbraco.Tests.Services public void TagsCanBecomeInvariantByPropertyType() { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); // en-US is already there + languageService.Save(new Language(_globalSettings, "fr-FR")); // en-US is already there var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; @@ -366,7 +371,7 @@ namespace Umbraco.Tests.Services public void TagsCanBecomeInvariantByPropertyTypeAndBackToVariant() { var languageService = ServiceContext.LocalizationService; - languageService.Save(new Language(TestObjects.GetGlobalSettings(), "fr-FR")); // en-US is already there + languageService.Save(new Language(_globalSettings, "fr-FR")); // en-US is already there var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index c8467b057f..82d7235388 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -6,20 +6,21 @@ using System.Threading; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Services; -using Umbraco.Tests.TestHelpers.Entities; -using Umbraco.Core.Events; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Repositories.Implement; -using Umbraco.Core.Scoping; -using Umbraco.Core.Services.Implement; -using Umbraco.Tests.Testing; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; -using Umbraco.Core.Cache; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Scoping; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; +using Umbraco.Tests.TestHelpers.Entities; +using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services { @@ -39,10 +40,13 @@ namespace Umbraco.Tests.Services // TODO: Add test to verify there is only ONE newest document/content in {Constants.DatabaseSchema.Tables.Document} table after updating. // TODO: Add test to delete specific version (with and without deleting prior versions) and versions by date. + private GlobalSettings _globalSettings; + public override void SetUp() { base.SetUp(); ContentRepositoryBase.ThrowOnWarning = true; + _globalSettings = new GlobalSettingsBuilder().Build(); } public override void TearDown() @@ -172,8 +176,8 @@ namespace Umbraco.Tests.Services [Test] public void Perform_Scheduled_Publishing() { - var langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var langUk = new Language(_globalSettings, "en-GB") { IsDefault = true }; + var langFr = new Language(_globalSettings, "fr-FR"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langUk); @@ -507,7 +511,7 @@ namespace Umbraco.Tests.Services [Test] public void Can_Save_New_Content_With_Explicit_User() { - var user = new User(TestObjects.GetGlobalSettings()) + var user = new User(_globalSettings) { Name = "Test", Email = "test@test.com", @@ -876,8 +880,8 @@ namespace Umbraco.Tests.Services [Test] public void Unpublishing_Mandatory_Language_Unpublishes_Document() { - var langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true, IsMandatory = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var langUk = new Language(_globalSettings, "en-GB") { IsDefault = true, IsMandatory = true }; + var langFr = new Language(_globalSettings, "fr-FR"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langUk); @@ -973,8 +977,8 @@ namespace Umbraco.Tests.Services { // Arrange - var langGB = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var langGB = new Language(_globalSettings, "en-GB") { IsDefault = true }; + var langFr = new Language(_globalSettings, "fr-FR"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langGB); @@ -1041,8 +1045,8 @@ namespace Umbraco.Tests.Services { // Arrange - var langGB = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true, IsMandatory = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var langGB = new Language(_globalSettings, "en-GB") { IsDefault = true, IsMandatory = true }; + var langFr = new Language(_globalSettings, "fr-FR"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langGB); @@ -1220,8 +1224,8 @@ namespace Umbraco.Tests.Services { //TODO: This is using an internal API - we aren't exposing this publicly (at least for now) but we'll keep the test around - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr"); - var langDa = new Language(TestObjects.GetGlobalSettings(), "da"); + var langFr = new Language(_globalSettings, "fr"); + var langDa = new Language(_globalSettings, "da"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langDa); @@ -2156,8 +2160,8 @@ namespace Umbraco.Tests.Services [Test] public void Can_Rollback_Version_On_Multilingual() { - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr"); - var langDa = new Language(TestObjects.GetGlobalSettings(), "da"); + var langFr = new Language(_globalSettings, "fr"); + var langDa = new Language(_globalSettings, "da"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langDa); @@ -2683,8 +2687,8 @@ namespace Umbraco.Tests.Services { var languageService = ServiceContext.LocalizationService; - var langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var langUk = new Language(_globalSettings, "en-GB") { IsDefault = true }; + var langFr = new Language(_globalSettings, "fr-FR"); languageService.Save(langFr); languageService.Save(langUk); @@ -2718,8 +2722,8 @@ namespace Umbraco.Tests.Services { var languageService = ServiceContext.LocalizationService; - var langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + var langUk = new Language(_globalSettings, "en-GB") { IsDefault = true }; + var langFr = new Language(_globalSettings, "fr-FR"); languageService.Save(langFr); languageService.Save(langUk); @@ -2755,9 +2759,9 @@ namespace Umbraco.Tests.Services { var languageService = ServiceContext.LocalizationService; - var langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); - var langDa = new Language(TestObjects.GetGlobalSettings(), "da-DK"); + var langUk = new Language(_globalSettings, "en-GB") { IsDefault = true }; + var langFr = new Language(_globalSettings, "fr-FR"); + var langDa = new Language(_globalSettings, "da-DK"); languageService.Save(langFr); languageService.Save(langUk); @@ -2857,10 +2861,10 @@ namespace Umbraco.Tests.Services var languageService = ServiceContext.LocalizationService; //var langFr = new Language("fr-FR") { IsDefaultVariantLanguage = true }; - var langXx = new Language(TestObjects.GetGlobalSettings(), "pt-PT") { IsDefault = true }; - var langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); - var langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB"); - var langDe = new Language(TestObjects.GetGlobalSettings(), "de-DE"); + var langXx = new Language(_globalSettings, "pt-PT") { IsDefault = true }; + var langFr = new Language(_globalSettings, "fr-FR"); + var langUk = new Language(_globalSettings, "en-GB"); + var langDe = new Language(_globalSettings, "de-DE"); languageService.Save(langFr); languageService.Save(langUk); @@ -3246,7 +3250,7 @@ namespace Umbraco.Tests.Services var templateRepository = new TemplateRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(accessor, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, Microsoft.Extensions.Options.Options.Create(_globalSettings)); contentTypeRepository = new ContentTypeRepository(accessor, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(accessor); @@ -3259,8 +3263,8 @@ namespace Umbraco.Tests.Services private void CreateEnglishAndFrenchDocumentType(out Language langUk, out Language langFr, out ContentType contentType) { - langUk = new Language(TestObjects.GetGlobalSettings(), "en-GB") { IsDefault = true }; - langFr = new Language(TestObjects.GetGlobalSettings(), "fr-FR"); + langUk = new Language(_globalSettings, "en-GB") { IsDefault = true }; + langFr = new Language(_globalSettings, "fr-FR"); ServiceContext.LocalizationService.Save(langFr); ServiceContext.LocalizationService.Save(langUk); diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index ab9f85aa3c..5830513fbd 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Core.Sync; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Strings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; @@ -59,7 +60,9 @@ namespace Umbraco.Tests.Services var hostingEnvironment = Mock.Of(); var typeFinder = TestHelper.GetTypeFinder(); - var settings = Mock.Of(); + + var globalSettings = new GlobalSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); return new PublishedSnapshotService( options, @@ -74,14 +77,14 @@ namespace Umbraco.Tests.Services documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, new DatabaseDataSource(Mock.Of()), - Factory.GetInstance(), + Microsoft.Extensions.Options.Options.Create(globalSettings), Factory.GetInstance(), Mock.Of(), new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(ShortStringHelper) }), hostingEnvironment, new MockShortStringHelper(), IOHelper, - settings); + Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); } public class LocalServerMessenger : ServerMessengerBase @@ -310,7 +313,9 @@ namespace Umbraco.Tests.Services var nlContentName = "Content nl-NL"; var nlCulture = "nl-NL"; - ServiceContext.LocalizationService.Save(new Language(TestObjects.GetGlobalSettings(), nlCulture)); + var globalSettings = new GlobalSettingsBuilder().Build(); + + ServiceContext.LocalizationService.Save(new Language(globalSettings, nlCulture)); var includeCultureNames = contentType.Variations.HasFlag(ContentVariation.Culture); @@ -666,9 +671,11 @@ namespace Umbraco.Tests.Services // can change it to variant and back // can then switch one property to variant - var languageEn = new Language(TestObjects.GetGlobalSettings(), "en") { IsDefault = true }; + var globalSettings = new GlobalSettingsBuilder().Build(); + + var languageEn = new Language(globalSettings, "en") { IsDefault = true }; ServiceContext.LocalizationService.Save(languageEn); - var languageFr = new Language(TestObjects.GetGlobalSettings(), "fr"); + var languageFr = new Language(globalSettings, "fr"); ServiceContext.LocalizationService.Save(languageFr); var contentType = CreateContentType(ContentVariation.Nothing); @@ -1259,9 +1266,10 @@ namespace Umbraco.Tests.Services private void CreateFrenchAndEnglishLangs() { - var languageEn = new Language(TestObjects.GetGlobalSettings(), "en") { IsDefault = true }; + var globalSettings = new GlobalSettingsBuilder().Build(); + var languageEn = new Language(globalSettings, "en") { IsDefault = true }; ServiceContext.LocalizationService.Save(languageEn); - var languageFr = new Language(TestObjects.GetGlobalSettings(), "fr"); + var languageFr = new Language(globalSettings, "fr"); ServiceContext.LocalizationService.Save(languageFr); } diff --git a/src/Umbraco.Tests/Services/EntityServiceTests.cs b/src/Umbraco.Tests/Services/EntityServiceTests.cs index fb802420d5..8be2dcc962 100644 --- a/src/Umbraco.Tests/Services/EntityServiceTests.cs +++ b/src/Umbraco.Tests/Services/EntityServiceTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -31,8 +32,9 @@ namespace Umbraco.Tests.Services if (_langFr == null && _langEs == null) { - _langFr = new Language(SettingsForTests.GenerateMockGlobalSettings(), "fr-FR"); - _langEs = new Language(SettingsForTests.GenerateMockGlobalSettings(), "es-ES"); + var globalSettings = new GlobalSettingsBuilder().Build(); + _langFr = new Language(globalSettings, "fr-FR"); + _langEs = new Language(globalSettings, "es-ES"); ServiceContext.LocalizationService.Save(_langFr); ServiceContext.LocalizationService.Save(_langEs); } diff --git a/src/Umbraco.Tests/Services/EntityXmlSerializerTests.cs b/src/Umbraco.Tests/Services/EntityXmlSerializerTests.cs index e10dd99482..8497208d93 100644 --- a/src/Umbraco.Tests/Services/EntityXmlSerializerTests.cs +++ b/src/Umbraco.Tests/Services/EntityXmlSerializerTests.cs @@ -4,9 +4,10 @@ using System.Linq; using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Services.Importing; using Umbraco.Tests.Testing; @@ -17,6 +18,13 @@ namespace Umbraco.Tests.Services public class EntityXmlSerializerTests : TestWithSomeContentBase { private IEntityXmlSerializer Serializer => Factory.GetInstance(); + private GlobalSettings _globalSettings; + + public override void SetUp() + { + base.SetUp(); + _globalSettings = new GlobalSettingsBuilder().Build(); + } [Test] public void Can_Export_Macro() @@ -56,10 +64,10 @@ namespace Umbraco.Tests.Services public void Can_Export_Languages() { // Arrange - var languageNbNo = new Language(TestObjects.GetGlobalSettings(), "nb-NO") { CultureName = "Norwegian" }; + var languageNbNo = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian" }; ServiceContext.LocalizationService.Save(languageNbNo); - var languageEnGb = new Language(TestObjects.GetGlobalSettings(), "en-GB") { CultureName = "English (United Kingdom)" }; + var languageEnGb = new Language(_globalSettings, "en-GB") { CultureName = "English (United Kingdom)" }; ServiceContext.LocalizationService.Save(languageEnGb); var newPackageXml = XElement.Parse(ImportResources.Dictionary_Package); @@ -74,10 +82,10 @@ namespace Umbraco.Tests.Services private void CreateDictionaryData() { - var languageNbNo = new Language(TestObjects.GetGlobalSettings(), "nb-NO") { CultureName = "nb-NO" }; + var languageNbNo = new Language(_globalSettings, "nb-NO") { CultureName = "nb-NO" }; ServiceContext.LocalizationService.Save(languageNbNo); - var languageEnGb = new Language(TestObjects.GetGlobalSettings(), "en-GB") { CultureName = "en-GB" }; + var languageEnGb = new Language(_globalSettings, "en-GB") { CultureName = "en-GB" }; ServiceContext.LocalizationService.Save(languageEnGb); var parentItem = new DictionaryItem("Parent"); diff --git a/src/Umbraco.Tests/Services/LocalizationServiceTests.cs b/src/Umbraco.Tests/Services/LocalizationServiceTests.cs index c5ff549ee3..2785cdea27 100644 --- a/src/Umbraco.Tests/Services/LocalizationServiceTests.cs +++ b/src/Umbraco.Tests/Services/LocalizationServiceTests.cs @@ -9,6 +9,8 @@ using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Core.Persistence; +using Umbraco.Core.Configuration.Models; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Services { @@ -29,6 +31,14 @@ namespace Umbraco.Tests.Services private int _danishLangId; private int _englishLangId; + private GlobalSettings _globalSettings; + + public override void SetUp() + { + base.SetUp(); + _globalSettings = new GlobalSettingsBuilder().Build(); + } + [Test] public void Can_Get_Root_Dictionary_Items() { @@ -181,7 +191,7 @@ namespace Umbraco.Tests.Services [Test] public void Can_Delete_Language() { - var norwegian = new Language(TestObjects.GetGlobalSettings(), "nb-NO") { CultureName = "Norwegian" }; + var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian" }; ServiceContext.LocalizationService.Save(norwegian, 0); Assert.That(norwegian.HasIdentity, Is.True); var languageId = norwegian.Id; @@ -196,7 +206,7 @@ namespace Umbraco.Tests.Services public void Can_Delete_Language_Used_As_Fallback() { var danish = ServiceContext.LocalizationService.GetLanguageByIsoCode("da-DK"); - var norwegian = new Language(TestObjects.GetGlobalSettings(), "nb-NO") { CultureName = "Norwegian", FallbackLanguageId = danish.Id }; + var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian", FallbackLanguageId = danish.Id }; ServiceContext.LocalizationService.Save(norwegian, 0); var languageId = danish.Id; @@ -346,7 +356,7 @@ namespace Umbraco.Tests.Services // Arrange var localizationService = ServiceContext.LocalizationService; var isoCode = "en-AU"; - var language = new Core.Models.Language(TestObjects.GetGlobalSettings(), isoCode); + var language = new Core.Models.Language(_globalSettings, isoCode); // Act localizationService.Save(language); @@ -361,7 +371,7 @@ namespace Umbraco.Tests.Services { var localizationService = ServiceContext.LocalizationService; var isoCode = "en-AU"; - var language = new Core.Models.Language(TestObjects.GetGlobalSettings(), isoCode); + var language = new Core.Models.Language(_globalSettings, isoCode); // Act localizationService.Save(language); @@ -375,14 +385,14 @@ namespace Umbraco.Tests.Services public void Set_Default_Language() { var localizationService = ServiceContext.LocalizationService; - var language = new Core.Models.Language(TestObjects.GetGlobalSettings(), "en-AU"); + var language = new Core.Models.Language(_globalSettings, "en-AU"); language.IsDefault = true; localizationService.Save(language); var result = localizationService.GetLanguageById(language.Id); Assert.IsTrue(result.IsDefault); - var language2 = new Core.Models.Language(TestObjects.GetGlobalSettings(), "en-NZ"); + var language2 = new Core.Models.Language(_globalSettings, "en-NZ"); language2.IsDefault = true; localizationService.Save(language2); var result2 = localizationService.GetLanguageById(language2.Id); @@ -398,7 +408,7 @@ namespace Umbraco.Tests.Services { var localizationService = ServiceContext.LocalizationService; var isoCode = "en-AU"; - var language = new Core.Models.Language(TestObjects.GetGlobalSettings(), isoCode); + var language = new Core.Models.Language(_globalSettings, isoCode); localizationService.Save(language); // Act @@ -411,8 +421,8 @@ namespace Umbraco.Tests.Services public override void CreateTestData() { - var danish = new Language(TestObjects.GetGlobalSettings(), "da-DK") { CultureName = "Danish" }; - var english = new Language(TestObjects.GetGlobalSettings(), "en-GB") { CultureName = "English" }; + var danish = new Language(_globalSettings, "da-DK") { CultureName = "Danish" }; + var english = new Language(_globalSettings, "en-GB") { CultureName = "English" }; ServiceContext.LocalizationService.Save(danish, 0); ServiceContext.LocalizationService.Save(english, 0); _danishLangId = danish.Id; diff --git a/src/Umbraco.Tests/Services/SectionServiceTests.cs b/src/Umbraco.Tests/Services/SectionServiceTests.cs index 80a4de4bfe..82fda67003 100644 --- a/src/Umbraco.Tests/Services/SectionServiceTests.cs +++ b/src/Umbraco.Tests/Services/SectionServiceTests.cs @@ -4,6 +4,7 @@ using System.Threading; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Models.Membership; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Testing; using Umbraco.Web.Services; @@ -34,7 +35,8 @@ namespace Umbraco.Tests.Services private IUser CreateTestUser() { - var user = new User(TestObjects.GetGlobalSettings()) + var globalSettings = new GlobalSettingsBuilder().Build(); + var user = new User(globalSettings) { Name = "Test user", Username = "testUser", diff --git a/src/Umbraco.Tests/Services/UserServiceTests.cs b/src/Umbraco.Tests/Services/UserServiceTests.cs index dbd71870d4..a8a611d524 100644 --- a/src/Umbraco.Tests/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests/Services/UserServiceTests.cs @@ -15,7 +15,7 @@ using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Tests.Testing; using Umbraco.Web.Actions; - +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Services { @@ -721,7 +721,8 @@ namespace Umbraco.Tests.Services var hash = new HMACSHA1(); hash.Key = Encoding.Unicode.GetBytes(password); var encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password))); - var membershipUser = new User(TestObjects.GetGlobalSettings(), "JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword); + var globalSettings = new GlobalSettingsBuilder().Build(); + var membershipUser = new User(globalSettings, "JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword); userService.Save(membershipUser); // Assert diff --git a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs index 109142f51b..0def86e8d2 100644 --- a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs +++ b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs @@ -7,8 +7,10 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -17,6 +19,7 @@ namespace Umbraco.Tests.Strings [TestFixture] public class DefaultShortStringHelperTests : UmbracoTestBase { + private RequestHandlerSettings _requestHandlerSettings; private DefaultShortStringHelper _helper; public override void SetUp() @@ -25,8 +28,8 @@ namespace Umbraco.Tests.Strings // NOTE pre-filters runs _before_ Recode takes place // so there still may be utf8 chars even though you want ascii - - _helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + _requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + _helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.FileName, new DefaultShortStringHelperConfig.Config { //PreFilter = ClearFileChars, // done in IsTerm @@ -94,18 +97,18 @@ namespace Umbraco.Tests.Strings [Test] public void U4_4056() { - var settings = SettingsForTests.GenerateMockRequestHandlerSettings(); - var contentMock = Mock.Get(settings); - contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); - contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); + var requestHandlerSettings = new RequestHandlerSettingsBuilder() + .WithConvertUrlsToAscii(false) + .WithCharCollection(Enumerable.Empty()) + .Build(); const string input = "ÆØÅ and æøå and 中文测试 and אודות האתר and größer БбДдЖж page"; - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings)); // unicode + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings)); // unicode var output = helper.CleanStringForUrlSegment(input); Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", output); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.UrlSegment, new DefaultShortStringHelperConfig.Config { IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', @@ -119,19 +122,19 @@ namespace Umbraco.Tests.Strings [Test] public void U4_4056_TryAscii() { - var settings = SettingsForTests.GenerateMockRequestHandlerSettings(); - var contentMock = Mock.Get(settings); - contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); - contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); + var requestHandlerSettings = new RequestHandlerSettingsBuilder() + .WithConvertUrlsToAscii(false) + .WithCharCollection(Enumerable.Empty()) + .Build(); const string input1 = "ÆØÅ and æøå and 中文测试 and אודות האתר and größer БбДдЖж page"; const string input2 = "ÆØÅ and æøå and größer БбДдЖж page"; - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings)); // unicode + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings)); // unicode Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input1)); Assert.AreEqual("æøå-and-æøå-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input2)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.UrlSegment, new DefaultShortStringHelperConfig.Config { IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', @@ -145,7 +148,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringUnderscoreInTerm() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // underscore is accepted within terms @@ -155,7 +158,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo_bar*nil", helper.CleanString("foo_bar nil", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // underscore is not accepted within terms @@ -169,7 +172,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringLeadingChars() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // letters and digits are valid leading chars @@ -179,7 +182,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("0123foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // only letters are valid leading chars @@ -190,14 +193,14 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias)); Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123 foo_bar 543 nil 321", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings())); + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings)); Assert.AreEqual("child2", helper.CleanStringForSafeAlias("1child2")); } [Test] public void CleanStringTermOnUpper() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -207,7 +210,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo*Bar", helper.CleanString("fooBar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -221,7 +224,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringAcronymOnNonUpper() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -234,7 +237,7 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("foo*BAnil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -251,7 +254,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringGreedyAcronyms() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -264,7 +267,7 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("foo*BA*nil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -281,7 +284,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringWhiteSpace() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -294,7 +297,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringSeparator() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -302,7 +305,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo*bar", helper.CleanString("foo bar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -310,14 +313,14 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo bar", helper.CleanString("foo bar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged })); Assert.AreEqual("foobar", helper.CleanString("foo bar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -329,7 +332,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringSymbols() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -383,7 +386,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringEncoding() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -392,7 +395,7 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("中文测试", helper.CleanString("中文测试", CleanStringType.Alias)); Assert.AreEqual("léger*中文测试*ZÔRG", helper.CleanString("léger 中文测试 ZÔRG", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Ascii | CleanStringType.Unchanged, @@ -405,7 +408,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringDefaultConfig() { - var settings = SettingsForTests.GenerateMockRequestHandlerSettings(); + var settings = _requestHandlerSettings; var contentMock = Mock.Get(settings); contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); @@ -431,7 +434,7 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringCasing() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GenerateMockRequestHandlerSettings()) + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 6bc228bf83..3faea42f01 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), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs index 531d87f76f..4977b5d81a 100644 --- a/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs +++ b/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Umbraco.Core.Models.Membership; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.TestHelpers.Entities { @@ -23,7 +24,8 @@ namespace Umbraco.Tests.TestHelpers.Entities internal static User CreateUser(string suffix = "") { - var user = new User(SettingsForTests.GenerateMockGlobalSettings()) + var globalSettings = new GlobalSettingsBuilder().Build(); + var user = new User(globalSettings) { Language = "en", IsApproved = true, @@ -41,10 +43,11 @@ namespace Umbraco.Tests.TestHelpers.Entities { var list = new List(); + var globalSettings = new GlobalSettingsBuilder().Build(); for (int i = 0; i < amount; i++) { var name = "Member No-" + i; - var user = new User(SettingsForTests.GenerateMockGlobalSettings(), name, "test" + i + "@test.com", "test" + i, "test" + i); + var user = new User(globalSettings, name, "test" + i + "@test.com", "test" + i, "test" + i); onCreating?.Invoke(i, user); diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 7e8914f78e..e1c1213e01 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -1,12 +1,14 @@ using System; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Moq; using NPoco; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.Hosting; @@ -23,6 +25,7 @@ using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; using Umbraco.Persistance.SqlCe; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers.Stubs; using Current = Umbraco.Web.Composing.Current; @@ -94,8 +97,8 @@ namespace Umbraco.Tests.TestHelpers AppCaches cache, ILogger logger, IIOHelper ioHelper, - IGlobalSettings globalSettings, - IContentSettings contentSettings, + GlobalSettings globalSettings, + ContentSettings contentSettings, IEventMessagesFactory eventMessagesFactory, UrlSegmentProviderCollection urlSegmentProviders, IUmbracoVersion umbracoVersion, @@ -157,7 +160,7 @@ namespace Umbraco.Tests.TestHelpers var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty())); var localizationService = GetLazyService(factory, c => new LocalizationService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c))); - var userService = GetLazyService(factory, c => new UserService(scopeProvider, logger, eventMessagesFactory, runtimeState, GetRepo(c), GetRepo(c),globalSettings)); + var userService = GetLazyService(factory, c => new UserService(scopeProvider, logger, eventMessagesFactory, runtimeState, GetRepo(c), GetRepo(c), Options.Create(globalSettings))); var dataTypeService = GetLazyService(factory, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), ioHelper, localizedTextService.Value, localizationService.Value, TestHelper.ShortStringHelper)); var propertyValidationService = new Lazy(() => new PropertyValidationService(propertyEditorCollection, dataTypeService.Value, localizedTextService.Value)); var contentService = GetLazyService(factory, c => new ContentService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), propertyValidationService, TestHelper.ShortStringHelper)); @@ -168,7 +171,7 @@ namespace Umbraco.Tests.TestHelpers var mediaService = GetLazyService(factory, c => new MediaService(scopeProvider, mediaFileSystem, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), TestHelper.ShortStringHelper)); var contentTypeService = GetLazyService(factory, c => new ContentTypeService(scopeProvider, logger, eventMessagesFactory, contentService.Value, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c))); var mediaTypeService = GetLazyService(factory, c => new MediaTypeService(scopeProvider, logger, eventMessagesFactory, mediaService.Value, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c))); - var fileService = GetLazyService(factory, c => new FileService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), TestHelper.ShortStringHelper, globalSettings, hostingEnvironment)); + var fileService = GetLazyService(factory, c => new FileService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), TestHelper.ShortStringHelper, Options.Create(globalSettings), hostingEnvironment)); var memberTypeService = GetLazyService(factory, c => new MemberTypeService(scopeProvider, logger, eventMessagesFactory, memberService.Value, GetRepo(c), GetRepo(c), GetRepo(c))); var entityService = GetLazyService(factory, c => new EntityService(scopeProvider, logger, eventMessagesFactory, idkMap, GetRepo(c))); @@ -180,11 +183,11 @@ namespace Umbraco.Tests.TestHelpers return new PackagingService( auditService.Value, new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, hostingEnvironment, - new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, globalSettings, "createdPackages.config"), + new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, Options.Create(globalSettings), "createdPackages.config"), new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, hostingEnvironment, - new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, globalSettings, "installedPackages.config"), + new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, Options.Create(globalSettings), "installedPackages.config"), new PackageInstallation( - new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider, shortStringHelper, GetGlobalSettings(), localizedTextService.Value), + new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider, shortStringHelper, globalSettings, localizedTextService.Value), new PackageFileInstallation(compiledPackageXmlParser, ioHelper, new ProfilingLogger(logger, new TestProfiler())), compiledPackageXmlParser, Mock.Of(), Mock.Of(x => x.ApplicationPhysicalPath == ioHelper.MapPath("~"))), @@ -241,6 +244,10 @@ namespace Umbraco.Tests.TestHelpers public IScopeProvider GetScopeProvider(ILogger logger, ITypeFinder typeFinder = null, FileSystems fileSystems = null, IUmbracoDatabaseFactory databaseFactory = null) { + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); + var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); + if (databaseFactory == null) { // var mappersBuilder = new MapperCollectionBuilder(Current.Container); // FIXME: @@ -248,19 +255,18 @@ namespace Umbraco.Tests.TestHelpers // var mappers = mappersBuilder.CreateCollection(); var mappers = Current.Factory.GetInstance(); databaseFactory = new UmbracoDatabaseFactory(logger, - SettingsForTests.DefaultGlobalSettings, - new ConnectionStrings(), + globalSettings, + connectionStrings, Constants.System.UmbracoConnectionName, new Lazy(() => mappers), TestHelper.DbProviderFactoryCreator); } typeFinder ??= new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); - fileSystems ??= new FileSystems(Current.Factory, logger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment()); + fileSystems ??= new FileSystems(Current.Factory, logger, TestHelper.IOHelper, Options.Create(globalSettings), TestHelper.GetHostingEnvironment()); var coreDebug = TestHelper.CoreDebugSettings; var mediaFileSystem = Mock.Of(); - var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, coreDebug, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); - return scopeProvider; + return new ScopeProvider(databaseFactory, fileSystems, coreDebugSettings, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); } } diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index cfcdacdadf..ea53d36498 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -33,6 +33,7 @@ using Umbraco.Persistance.SqlCe; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Web.WebApi; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.TestHelpers { @@ -301,7 +302,8 @@ namespace Umbraco.Tests.TestHelpers { using (var scope = ScopeProvider.CreateScope()) { - var schemaHelper = new DatabaseSchemaCreator(scope.Database, Logger, UmbracoVersion, TestObjects.GetGlobalSettings()); + var globalSettings = new GlobalSettingsBuilder().Build(); + var schemaHelper = new DatabaseSchemaCreator(scope.Database, Logger, UmbracoVersion, globalSettings); //Create the umbraco database and its base data schemaHelper.InitializeDatabaseSchema(); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 94c52e8d96..5d8e047161 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -60,6 +60,8 @@ using Umbraco.Web.Trees; using Current = Umbraco.Web.Composing.Current; using Umbraco.Tests.Common; using Umbraco.Core.Media; +using Umbraco.Tests.Common.Builders; +using Umbraco.Web.Configuration; namespace Umbraco.Tests.Testing { @@ -177,7 +179,7 @@ namespace Umbraco.Tests.Testing IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, logger, settings); IIpResolver ipResolver = new AspNetIpResolver(); - UmbracoVersion = new UmbracoVersion(globalSettings); + UmbracoVersion = new UmbracoVersion(ConfigModelConversions.ConvertGlobalSettings(globalSettings)); LocalizedTextService = new LocalizedTextService(new Dictionary>(), logger); @@ -187,7 +189,7 @@ namespace Umbraco.Tests.Testing - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); @@ -319,15 +321,15 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(); Composition.RegisterUnique(); Composition.RegisterUnique(); + + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); Composition.RegisterUnique(factory => new UrlProvider( factory.GetInstance(), - TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings(), + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - factory.GetInstance() - - )); + factory.GetInstance())); @@ -457,8 +459,8 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(_ => new TransientEventMessagesFactory()); - var globalSettings = TestHelper.GetConfigs().Global(); - var connectionStrings = TestHelper.GetConfigs().ConnectionStrings(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); Composition.RegisterUnique(f => new UmbracoDatabaseFactory(Logger, globalSettings, From aedd7563a4acf05884c8bb19468a9e9261cc1ac4 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Aug 2020 22:58:23 +0200 Subject: [PATCH 14/58] Restored Umbraco.Tests (further) --- .../Packaging/PackageInstallationTest.cs | 9 +- .../Repositories/MediaRepositoryTest.cs | 5 +- .../Repositories/MediaTypeRepositoryTest.cs | 4 +- .../Repositories/MemberRepositoryTest.cs | 4 +- .../Repositories/MemberTypeRepositoryTest.cs | 4 +- .../PublicAccessRepositoryTest.cs | 4 +- .../Repositories/ScriptRepositoryTest.cs | 4 +- .../Repositories/StylesheetRepositoryTest.cs | 4 +- .../Repositories/TagRepositoryTest.cs | 7 +- .../Repositories/TemplateRepositoryTest.cs | 5 +- .../PublishedContent/NuCacheTests.cs | 4 +- .../Routing/ContentFinderByIdTests.cs | 4 +- .../ContentFinderByUrlAndTemplateTests.cs | 2 +- .../Routing/MediaUrlProviderTests.cs | 10 +- .../Routing/UmbracoModuleTests.cs | 10 +- src/Umbraco.Tests/Routing/UrlProviderTests.cs | 107 +++++++++-------- .../Routing/UrlsProviderWithDomainsTests.cs | 86 ++++++++------ .../Routing/UrlsWithNestedDomains.cs | 17 +-- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 5 +- .../Scoping/ScopeEventDispatcherTests.cs | 4 +- .../Services/ContentServicePerformanceTest.cs | 4 +- .../Strings/CmsHelperCasingTests.cs | 4 +- .../Templates/HtmlImageSourceParserTests.cs | 5 +- .../Templates/HtmlLocalLinkParserTests.cs | 4 +- src/Umbraco.Tests/TestHelpers/BaseWebTest.cs | 9 +- .../TestHelpers/ConfigModelConversions.cs | 109 ++++++++++++++++++ .../Testing/TestingTests/MockTests.cs | 4 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 45 ++++---- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 +- .../UmbracoExamine/ExamineBaseTest.cs | 5 +- .../Web/Mvc/SurfaceControllerTests.cs | 5 +- .../Web/Mvc/UmbracoViewPageTests.cs | 4 +- .../Configuration/ConfigModelConversions.cs | 2 +- 33 files changed, 341 insertions(+), 162 deletions(-) create mode 100644 src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs diff --git a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs index 1cfb9167ce..04c51029c7 100644 --- a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs +++ b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs @@ -47,7 +47,11 @@ namespace Umbraco.Tests.Packaging _testBaseFolder.Delete(true); } - private CompiledPackageXmlParser Parser => new CompiledPackageXmlParser(new ConflictingPackageData(ServiceContext.MacroService, ServiceContext.FileService),Factory.GetInstance()); + private CompiledPackageXmlParser Parser => new CompiledPackageXmlParser( + new ConflictingPackageData( + ServiceContext.MacroService, + ServiceContext.FileService), + new GlobalSettingsBuilder().Build()); private PackageDataInstallation PackageDataInstallation => new PackageDataInstallation( Logger, ServiceContext.FileService, ServiceContext.MacroService, ServiceContext.LocalizationService, @@ -57,8 +61,7 @@ namespace Umbraco.Tests.Packaging Factory.GetInstance(), Factory.GetInstance(), new GlobalSettingsBuilder().Build(), - Factory.GetInstance() - ); + Factory.GetInstance() ); private IPackageInstallation PackageInstallation => new PackageInstallation( PackageDataInstallation, diff --git a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs index 83572180af..119a207cb9 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs @@ -16,6 +16,7 @@ using Umbraco.Tests.Testing; using Umbraco.Core.Services; using Umbraco.Core; using Umbraco.Core.PropertyEditors; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Persistence.Repositories { @@ -34,10 +35,10 @@ namespace Umbraco.Tests.Persistence.Repositories { appCaches = appCaches ?? AppCaches; var scopeAccessor = (IScopeAccessor) provider; - + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = new TemplateRepository(scopeAccessor, appCaches, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var commonRepository = new ContentTypeCommonRepository(scopeAccessor, templateRepository, appCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(scopeAccessor, appCaches, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(scopeAccessor, appCaches, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); mediaTypeRepository = new MediaTypeRepository(scopeAccessor, appCaches, Logger, commonRepository, languageRepository, ShortStringHelper); var tagRepository = new TagRepository(scopeAccessor, appCaches, Logger); var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, Logger); diff --git a/src/Umbraco.Tests/Persistence/Repositories/MediaTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MediaTypeRepositoryTest.cs index 6ffbdaca10..fac2a6665a 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MediaTypeRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MediaTypeRepositoryTest.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -21,9 +22,10 @@ namespace Umbraco.Tests.Persistence.Repositories private MediaTypeRepository CreateRepository(IScopeProvider provider) { var cacheHelper = AppCaches.Disabled; + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = new TemplateRepository((IScopeAccessor)provider, cacheHelper, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var commonRepository = new ContentTypeCommonRepository((IScopeAccessor)provider, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); return new MediaTypeRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs index b8c823f59e..37d5260dc0 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MemberRepositoryTest.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -30,9 +31,10 @@ namespace Umbraco.Tests.Persistence.Repositories private MemberRepository CreateRepository(IScopeProvider provider, out MemberTypeRepository memberTypeRepository, out MemberGroupRepository memberGroupRepository) { var accessor = (IScopeAccessor) provider; + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = Mock.Of(); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); memberTypeRepository = new MemberTypeRepository(accessor, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); memberGroupRepository = new MemberGroupRepository(accessor, AppCaches.Disabled, Logger); var tagRepo = new TagRepository(accessor, AppCaches.Disabled, Logger); diff --git a/src/Umbraco.Tests/Persistence/Repositories/MemberTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MemberTypeRepositoryTest.cs index b8c60f97fe..be32305cfc 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MemberTypeRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MemberTypeRepositoryTest.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -23,8 +24,9 @@ namespace Umbraco.Tests.Persistence.Repositories private MemberTypeRepository CreateRepository(IScopeProvider provider) { var templateRepository = Mock.Of(); + var globalSettings = new GlobalSettingsBuilder().Build(); var commonRepository = new ContentTypeCommonRepository((IScopeAccessor)provider, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches.Disabled, Mock.Of(), TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches.Disabled, Mock.Of(), Microsoft.Extensions.Options.Options.Create(globalSettings)); return new MemberTypeRepository((IScopeAccessor) provider, AppCaches.Disabled, Mock.Of(), commonRepository, languageRepository, ShortStringHelper); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs index 4ba2c3eab6..b31d490578 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/PublicAccessRepositoryTest.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -306,10 +307,11 @@ namespace Umbraco.Tests.Persistence.Repositories private DocumentRepository CreateRepository(IScopeProvider provider, out ContentTypeRepository contentTypeRepository) { var accessor = (IScopeAccessor) provider; + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = new TemplateRepository(accessor, AppCaches, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(accessor, AppCaches, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); contentTypeRepository = new ContentTypeRepository(accessor, AppCaches, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches, Logger); var entityRepository = new EntityRepository(accessor); diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 7922af99b0..2ef8d2d30f 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -40,7 +41,8 @@ namespace Umbraco.Tests.Persistence.Repositories private IScriptRepository CreateRepository() { - return new ScriptRepository(_fileSystems, IOHelper, TestObjects.GetGlobalSettings()); + var globalSettings = new GlobalSettingsBuilder().Build(); + return new ScriptRepository(_fileSystems, IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings)); } protected override void Compose() diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index f4558dca2d..5b6f77ac7e 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -12,6 +12,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -37,7 +38,8 @@ namespace Umbraco.Tests.Persistence.Repositories private IStylesheetRepository CreateRepository() { - return new StylesheetRepository(_fileSystems, IOHelper, TestObjects.GetGlobalSettings()); + var globalSettings = new GlobalSettingsBuilder().Build(); + return new StylesheetRepository(_fileSystems, IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings)); } [Test] diff --git a/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs index d4341cd128..913fc876fe 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TagRepositoryTest.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -955,10 +956,11 @@ namespace Umbraco.Tests.Persistence.Repositories private DocumentRepository CreateDocumentRepository(IScopeProvider provider, out ContentTypeRepository contentTypeRepository) { var accessor = (IScopeAccessor) provider; + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = new TemplateRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(accessor, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches.Disabled, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); contentTypeRepository = new ContentTypeRepository(accessor, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(accessor); @@ -972,10 +974,11 @@ namespace Umbraco.Tests.Persistence.Repositories private MediaRepository CreateMediaRepository(IScopeProvider provider, out MediaTypeRepository mediaTypeRepository) { var accessor = (IScopeAccessor) provider; + var globalSettings = new GlobalSettingsBuilder().Build(); var templateRepository = new TemplateRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepository = new TagRepository(accessor, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, templateRepository, AppCaches.Disabled, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); mediaTypeRepository = new MediaTypeRepository(accessor, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(accessor); diff --git a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs index b7c1f6a2a8..fdf7b48a4a 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -238,10 +239,10 @@ namespace Umbraco.Tests.Persistence.Repositories using (ScopeProvider.CreateScope()) { var templateRepository = CreateRepository(ScopeProvider); - + var globalSettings = new GlobalSettingsBuilder().Build(); var tagRepository = new TagRepository(ScopeProvider, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(ScopeProvider, templateRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(ScopeProvider, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(ScopeProvider, AppCaches.Disabled, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); var contentTypeRepository = new ContentTypeRepository(ScopeProvider, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(ScopeProvider, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(ScopeProvider); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index da67a76eb9..d65d89a363 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -201,14 +201,14 @@ namespace Umbraco.Tests.PublishedContent Mock.Of(), new TestDefaultCultureAccessor(), dataSource, - globalSettings, + Microsoft.Extensions.Options.Options.Create(globalSettings), Mock.Of(), publishedModelFactory, new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(TestHelper.ShortStringHelper) }), TestHelper.GetHostingEnvironment(), new MockShortStringHelper(), TestHelper.IOHelper, - nuCacheSettings); + Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); diff --git a/src/Umbraco.Tests/Routing/ContentFinderByIdTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByIdTests.cs index d3c820d239..069aead6b3 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByIdTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByIdTests.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using Umbraco.Core; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web; using Umbraco.Web.Routing; @@ -17,7 +18,8 @@ namespace Umbraco.Tests.Routing var umbracoContext = GetUmbracoContext(urlAsString); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); - var lookup = new ContentFinderByIdPath(SettingsForTests.GenerateMockWebRoutingSettings(), Logger, Factory.GetInstance()); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + var lookup = new ContentFinderByIdPath(Microsoft.Extensions.Options.Options.Create(webRoutingSettings), Logger, Factory.GetInstance()); var result = lookup.TryFindContent(frequest); diff --git a/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs index 07f0e587e3..2c991ce455 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Routing var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); - var lookup = new ContentFinderByUrlAndTemplate(Logger, ServiceContext.FileService, ServiceContext.ContentTypeService, webRoutingSettings); + var lookup = new ContentFinderByUrlAndTemplate(Logger, ServiceContext.FileService, ServiceContext.ContentTypeService, Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); var result = lookup.TryFindContent(frequest); diff --git a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs index e55a22065b..4545dc5a0e 100644 --- a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs @@ -13,6 +13,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.ValueConverters; using Umbraco.Core.Services; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -34,12 +35,12 @@ namespace Umbraco.Tests.Routing var logger = Mock.Of(); var mediaFileSystemMock = Mock.Of(); - var contentSection = Mock.Of(); + var contentSettings = new ContentSettingsBuilder().Build(); var dataTypeService = Mock.Of(); var propertyEditors = new MediaUrlGeneratorCollection(new IMediaUrlGenerator[] { - new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), - new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), + new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), + new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), }); _mediaUrlProvider = new DefaultMediaUrlProvider(propertyEditors, UriUtility); } @@ -149,9 +150,10 @@ namespace Umbraco.Tests.Routing private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext) { + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); return new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(new []{_mediaUrlProvider}), Mock.Of() diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 4dfcd46788..252e03f4c0 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -16,6 +16,8 @@ using Umbraco.Core.Services; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Configuration; +using ConfigModelConversions = Umbraco.Tests.TestHelpers.ConfigModelConversions; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -32,8 +34,8 @@ namespace Umbraco.Tests.Routing // FIXME: be able to get the UmbracoModule from the container. any reason settings were from testobjects? //create the module var logger = Mock.Of(); - var globalSettings = TestObjects.GetGlobalSettings(); - var runtime = new RuntimeState(ConfigModelConversions.ConvertGlobalSettings(globalSettings), UmbracoVersion); + var globalSettings = new GlobalSettingsBuilder().Build(); + var runtime = new RuntimeState(globalSettings, UmbracoVersion); _module = new UmbracoInjectedModule ( @@ -41,10 +43,10 @@ namespace Umbraco.Tests.Routing logger, null, // FIXME: PublishedRouter complexities... Mock.Of(), - new RoutableDocumentFilter(globalSettings, IOHelper), + new RoutableDocumentFilter(ConfigModelConversions.ConvertGlobalSettings(globalSettings), IOHelper), UriUtility, AppCaches.RequestCache, - globalSettings, + ConfigModelConversions.ConvertGlobalSettings(globalSettings), HostingEnvironment ); diff --git a/src/Umbraco.Tests/Routing/UrlProviderTests.cs b/src/Umbraco.Tests/Routing/UrlProviderTests.cs index 1ff0a2b33d..d7a6cc701a 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderTests.cs @@ -17,6 +17,7 @@ using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -45,14 +46,16 @@ namespace Umbraco.Tests.Routing [Test] public void Ensure_Cache_Is_Correct() { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -100,13 +103,13 @@ namespace Umbraco.Tests.Routing private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) { + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); return new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(new []{urlProvider}), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of() - ); + Mock.Of()); } // test hideTopLevelNodeFromPath false @@ -120,15 +123,16 @@ namespace Umbraco.Tests.Routing [TestCase(1172, "/test-page/")] public void Get_Url_Not_Hiding_Top_Level(int nodeId, string niceUrlMatch) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -149,13 +153,15 @@ namespace Umbraco.Tests.Routing [TestCase(1172, "/test-page/")] // not hidden because not first root public void Get_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(true); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(true).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -168,11 +174,9 @@ namespace Umbraco.Tests.Routing { const string currentUri = "http://example.us/test"; - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); - - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Culture); var publishedContent = new SolidPublishedContent(contentType) { Id = 1234 }; @@ -193,12 +197,14 @@ namespace Umbraco.Tests.Routing snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny())) .Returns(snapshot); - var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: globalSettings.Object, + globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -216,10 +222,9 @@ namespace Umbraco.Tests.Routing { const string currentUri = "http://example.fr/test"; - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Culture); var publishedContent = new SolidPublishedContent(contentType) { Id = 1234 }; @@ -249,12 +254,14 @@ namespace Umbraco.Tests.Routing snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny())) .Returns(snapshot); - var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: globalSettings.Object, + globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -272,10 +279,9 @@ namespace Umbraco.Tests.Routing { const string currentUri = "http://example.us/test"; - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Culture); var publishedContent = new SolidPublishedContent(contentType) { Id = 1234 }; @@ -306,10 +312,13 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: globalSettings.Object, + globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); @@ -323,15 +332,16 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Relative_Or_Absolute() { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: globalSettings.Object); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -344,14 +354,15 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Unpublished() { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var urlProvider = new DefaultUrlProvider(requestHandlerSettings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), UmbracoContextAccessor, UriUtility); - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: globalSettings.Object); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); //mock the Umbraco settings that we need diff --git a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs index d8e373b428..79813e662c 100644 --- a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -178,14 +179,15 @@ namespace Umbraco.Tests.Routing [TestCase(10011, "https://domain1.com", false, "/1001-1/")] public void Get_Url_SimpleDomain(int nodeId, string currentUrl, bool absolute, string expected) { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -212,14 +214,14 @@ namespace Umbraco.Tests.Routing [TestCase(10011, "https://domain1.com", false, "http://domain1.com/foo/1001-1/")] public void Get_Url_SimpleWithSchemeAndPath(int nodeId, string currentUrl, bool absolute, string expected) { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains - - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -238,14 +240,15 @@ namespace Umbraco.Tests.Routing [TestCase(1002, "http://domain1.com", false, "/1002/")] public void Get_Url_DeepDomain(int nodeId, string currentUrl, bool absolute, string expected) { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -270,14 +273,16 @@ namespace Umbraco.Tests.Routing [TestCase(100321, "http://domain3.com", false, "/fr/1003-2-1/")] public void Get_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected) { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -292,14 +297,16 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_DomainsAndCache() { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -356,14 +363,16 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Relative_Or_Absolute() { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -381,14 +390,16 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Alternate() { - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -408,9 +419,10 @@ namespace Umbraco.Tests.Routing private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) { + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); return new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(new []{urlProvider}), new MediaUrlProviderCollection(Enumerable.Empty()), Mock.Of() diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index 13ee5afa3e..085cf7f274 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Services; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Web; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -33,19 +34,20 @@ namespace Umbraco.Tests.Routing [Test] public void DoNotPolluteCache() { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); - - var settings = TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings(); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); SetDomains1(); const string url = "http://domain1.com/1001-1/1001-1-1"; // get the nice url for 100111 - var umbracoContext = GetUmbracoContext(url, 9999, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext(url, 9999, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider(settings, Logger, globalSettings.Object, + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -97,9 +99,10 @@ namespace Umbraco.Tests.Routing private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) { + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); return new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(new []{urlProvider}), new MediaUrlProviderCollection(Enumerable.Empty()), Mock.Of() diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 5984164497..394ed902f8 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -161,7 +161,6 @@ namespace Umbraco.Tests.Runtimes var scopeProvider = factory.GetInstance(); using (var scope = scopeProvider.CreateScope()) { - var globalSettings = new GlobalSettingsBuilder().Build(); var creator = new DatabaseSchemaCreator(scope.Database, logger, umbracoVersion, globalSettings); creator.InitializeDatabaseSchema(); scope.Complete(); @@ -277,7 +276,9 @@ namespace Umbraco.Tests.Runtimes composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); // create the core runtime and have it compose itself - var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); // get the components // all of them? diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index c646bdcf79..e47e9692bd 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Services; using Umbraco.Tests.Components; using Current = Umbraco.Web.Composing.Current; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Scoping { @@ -38,7 +39,8 @@ namespace Umbraco.Tests.Scoping _testObjects = new TestObjects(register); - composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance(), TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings(), TestHelper.GetHostingEnvironment())); + var globalSettings = new GlobalSettingsBuilder().Build(); + composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance(), TestHelper.IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings), TestHelper.GetHostingEnvironment())); composition.WithCollectionBuilder(); composition.Configs.Add(() => SettingsForTests.DefaultGlobalSettings); diff --git a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs index d5afde6477..02f6ad330f 100644 --- a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs +++ b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.TestHelpers.Stubs; @@ -43,10 +44,11 @@ namespace Umbraco.Tests.Services private DocumentRepository CreateDocumentRepository(IScopeProvider provider) { var accessor = (IScopeAccessor)provider; + var globalSettings = new GlobalSettingsBuilder().Build(); var tRepository = new TemplateRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock(), IOHelper, ShortStringHelper); var tagRepo = new TagRepository(accessor, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository(accessor, tRepository, AppCaches, ShortStringHelper); - var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, TestObjects.GetGlobalSettings()); + var languageRepository = new LanguageRepository(accessor, AppCaches.Disabled, Logger, Microsoft.Extensions.Options.Options.Create(globalSettings)); var ctRepository = new ContentTypeRepository(accessor, AppCaches.Disabled, Logger, commonRepository, languageRepository, ShortStringHelper); var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Logger); var entityRepository = new EntityRepository(accessor); diff --git a/src/Umbraco.Tests/Strings/CmsHelperCasingTests.cs b/src/Umbraco.Tests/Strings/CmsHelperCasingTests.cs index 84ffa3b696..71d789eddb 100644 --- a/src/Umbraco.Tests/Strings/CmsHelperCasingTests.cs +++ b/src/Umbraco.Tests/Strings/CmsHelperCasingTests.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -30,7 +31,8 @@ namespace Umbraco.Tests.Strings [TestCase("WhoIsNumber6InTheVillage", "Who Is Number6 In The Village")] // issue is fixed public void CompatibleDefaultReplacement(string input, string expected) { - var helper = new DefaultShortStringHelper(SettingsForTests.GenerateMockRequestHandlerSettings()); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); var output = input.Length < 2 ? input : helper.SplitPascalCasing(input, ' ').ToFirstUpperInvariant(); Assert.AreEqual(expected, output); } diff --git a/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs b/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs index 14e45d976c..4dc7ad0278 100644 --- a/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs +++ b/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs @@ -14,6 +14,7 @@ using Umbraco.Core; using System.Diagnostics; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Templates { @@ -76,9 +77,9 @@ namespace Umbraco.Tests.Templates var umbracoContextFactory = TestUmbracoContextFactory.Create( umbracoContextAccessor: umbracoContextAccessor); - + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); var publishedUrlProvider = new UrlProvider(umbracoContextAccessor, - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(new []{mediaUrlProvider.Object}), Mock.Of() diff --git a/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs b/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs index 20677468c6..375dc91d19 100644 --- a/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs +++ b/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing.Objects; using Umbraco.Web; @@ -72,8 +73,9 @@ namespace Umbraco.Tests.Templates var umbracoContextFactory = TestUmbracoContextFactory.Create( umbracoContextAccessor: umbracoContextAccessor); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); var publishedUrlProvider = new UrlProvider(umbracoContextAccessor, - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(new []{contentUrlProvider.Object}), new MediaUrlProviderCollection(new []{mediaUrlProvider.Object}), Mock.Of() diff --git a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs index 8926c02182..e51a10da50 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -13,6 +14,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Web; @@ -91,13 +93,14 @@ namespace Umbraco.Tests.TestHelpers internal PublishedRouter CreatePublishedRouter(IFactory container = null, ContentFinderCollection contentFinders = null) { - return CreatePublishedRouter(SettingsForTests.GenerateMockWebRoutingSettings(), container ?? Factory, contentFinders); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + return CreatePublishedRouter(webRoutingSettings, container ?? Factory, contentFinders); } - internal static PublishedRouter CreatePublishedRouter(IWebRoutingSettings webRoutingSettings, IFactory container = null, ContentFinderCollection contentFinders = null) + internal static PublishedRouter CreatePublishedRouter(WebRoutingSettings webRoutingSettings, IFactory container = null, ContentFinderCollection contentFinders = null) { return new PublishedRouter( - webRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), contentFinders ?? new ContentFinderCollection(Enumerable.Empty()), new TestLastChanceFinder(), new TestVariationContextAccessor(), diff --git a/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs b/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs new file mode 100644 index 0000000000..800374c690 --- /dev/null +++ b/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs @@ -0,0 +1,109 @@ +using System.Net.Mail; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.TestHelpers +{ + /// + /// TEMPORARY: this class has been added just to ensure tests on Umbraco.Web functionality, that still use the interface + /// based configuration, by converting between e.g (used by + /// legacy configuration and (used by Netcore/IOptions configuration). + /// + public static class ConfigModelConversions + { + public static IGlobalSettings ConvertGlobalSettings(GlobalSettings globalSettings) + { + return new TestGlobalSettings + { + DatabaseFactoryServerVersion = globalSettings.DatabaseFactoryServerVersion, + DefaultUILanguage = globalSettings.DefaultUILanguage, + DisableElectionForSingleServer = globalSettings.DisableElectionForSingleServer, + HideTopLevelNodeFromPath = globalSettings.HideTopLevelNodeFromPath, + InstallEmptyDatabase = globalSettings.InstallEmptyDatabase, + InstallMissingDatabase = globalSettings.InstallMissingDatabase, + MainDomLock = globalSettings.MainDomLock, + NoNodesViewPath = globalSettings.NoNodesViewPath, + RegisterType = globalSettings.RegisterType, + ReservedPaths = globalSettings.ReservedPaths, + ReservedUrls = globalSettings.ReservedUrls, + SmtpSettings = new TestSmtpSettings + { + DeliveryMethod = globalSettings.Smtp.DeliveryMethod, + From = globalSettings.Smtp.From, + Host = globalSettings.Smtp.Host, + Password = globalSettings.Smtp.Password, + PickupDirectoryLocation = globalSettings.Smtp.PickupDirectoryLocation, + Port = globalSettings.Smtp.Port, + Username = globalSettings.Smtp.Username, + }, + TimeOutInMinutes = globalSettings.TimeOutInMinutes, + UmbracoCssPath = globalSettings.UmbracoCssPath, + UmbracoMediaPath = globalSettings.UmbracoMediaPath, + UmbracoPath = globalSettings.UmbracoPath, + UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, + UseHttps = globalSettings.UseHttps, + VersionCheckPeriod = globalSettings.VersionCheckPeriod, + }; + } + + private class TestGlobalSettings : IGlobalSettings + { + public string ReservedUrls { get; set; } + + public string ReservedPaths { get; set; } + + public int TimeOutInMinutes { get; set; } + + public string DefaultUILanguage { get; set; } + + public bool HideTopLevelNodeFromPath { get; set; } + + public bool UseHttps { get; set; } + + public int VersionCheckPeriod { get; set; } + + public string UmbracoPath { get; set; } + + public string UmbracoCssPath { get; set; } + + public string UmbracoScriptsPath { get; set; } + + public string UmbracoMediaPath { get; set; } + + public bool IsSmtpServerConfigured { get; set; } + + public ISmtpSettings SmtpSettings { get; set; } + + public bool InstallMissingDatabase { get; set; } + + public bool InstallEmptyDatabase { get; set; } + + public bool DisableElectionForSingleServer { get; set; } + + public string RegisterType { get; set; } + + public string DatabaseFactoryServerVersion { get; set; } + + public string MainDomLock { get; set; } + + public string NoNodesViewPath { get; set; } + } + + private class TestSmtpSettings : ISmtpSettings + { + public string From { get; set; } + + public string Host { get; set; } + + public int Port { get; set; } + + public string PickupDirectoryLocation { get; set; } + + public SmtpDeliveryMethod DeliveryMethod { get; set; } + + public string Username { get; set; } + + public string Password { get; set; } + } + } +} diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index 6f5739eb02..0232cafb1c 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -27,6 +27,7 @@ using Umbraco.Web.Security; using Umbraco.Web.Security.Providers; using Umbraco.Web.WebApi; using Current = Umbraco.Web.Composing.Current; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Testing.TestingTests { @@ -84,9 +85,10 @@ namespace Umbraco.Tests.Testing.TestingTests .Returns(UrlInfo.Url("/hello/world/1234")); var urlProvider = urlProviderMock.Object; + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); var theUrlProvider = new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), - TestHelper.WebRoutingSettings, + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(new [] { urlProvider }), new MediaUrlProviderCollection( Enumerable.Empty()) , umbracoContext.VariationContextAccessor); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 5d8e047161..d339143c61 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -13,13 +13,18 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Configuration; +using Umbraco.Core.Dictionary; using Umbraco.Core.Events; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.IO.MediaPathSchemes; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Manifest; +using Umbraco.Core.Mapping; +using Umbraco.Core.Media; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; @@ -27,41 +32,35 @@ using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Scoping; +using Umbraco.Core.Security; +using Umbraco.Core.Serialization; +using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; +using Umbraco.Net; +using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Components; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Web; -using Umbraco.Web.Services; using Umbraco.Web.Actions; +using Umbraco.Web.AspNet; using Umbraco.Web.ContentApps; +using Umbraco.Web.Hosting; +using Umbraco.Web.Install; +using Umbraco.Web.PropertyEditors; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; -using Umbraco.Core.Composing.CompositionExtensions; -using Umbraco.Core.Hosting; -using Umbraco.Core.Mapping; -using Umbraco.Core.Serialization; -using Umbraco.Web.Composing.CompositionExtensions; -using Umbraco.Web.Hosting; using Umbraco.Web.Sections; -using FileSystems = Umbraco.Core.IO.FileSystems; -using Umbraco.Web.Templates; -using Umbraco.Web.PropertyEditors; -using Umbraco.Core.Dictionary; -using Umbraco.Net; -using Umbraco.Core.Security; -using Umbraco.Core.Services; -using Umbraco.Web.AspNet; -using Umbraco.Web.Install; using Umbraco.Web.Security; using Umbraco.Web.Security.Providers; +using Umbraco.Web.Services; +using Umbraco.Web.Templates; using Umbraco.Web.Trees; +using ConfigModelConversions = Umbraco.Tests.TestHelpers.ConfigModelConversions; using Current = Umbraco.Web.Composing.Current; -using Umbraco.Tests.Common; -using Umbraco.Core.Media; -using Umbraco.Tests.Common.Builders; -using Umbraco.Web.Configuration; +using FileSystems = Umbraco.Core.IO.FileSystems; namespace Umbraco.Tests.Testing { @@ -174,12 +173,12 @@ namespace Umbraco.Tests.Testing TypeFinder = new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); var appCaches = GetAppCaches(); - var globalSettings = TestHelpers.SettingsForTests.DefaultGlobalSettings; + var globalSettings = new GlobalSettingsBuilder().Build(); var settings = TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings(); - IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, logger, settings); + IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversions.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); IIpResolver ipResolver = new AspNetIpResolver(); - UmbracoVersion = new UmbracoVersion(ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + UmbracoVersion = new UmbracoVersion(globalSettings); LocalizedTextService = new LocalizedTextService(new Dictionary>(), logger); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 9a552d04d8..b21814cab7 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -145,6 +145,7 @@ + @@ -558,8 +559,7 @@ - - + diff --git a/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs b/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs index 0d55fd99d7..eac16e457f 100644 --- a/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Strings; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Components; using Umbraco.Tests.TestHelpers; @@ -33,8 +34,8 @@ namespace Umbraco.Tests.UmbracoExamine protected override void Compose() { base.Compose(); - - Composition.RegisterUnique(_ => new DefaultShortStringHelper(SettingsForTests.GenerateMockRequestHandlerSettings())); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + Composition.RegisterUnique(_ => new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings))); } } } diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index 4c222b9116..8e0c534550 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Web; @@ -155,8 +156,8 @@ namespace Umbraco.Tests.Web.Mvc var content = Mock.Of(publishedContent => publishedContent.Id == 12345); - - var publishedRouter = BaseWebTest.CreatePublishedRouter(TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings()); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + var publishedRouter = BaseWebTest.CreatePublishedRouter(webRoutingSettings); var frequest = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/test")); frequest.PublishedContent = content; diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index 6f1a073eca..5e89f29496 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -22,6 +22,7 @@ using Umbraco.Web.Models; using Umbraco.Web.Mvc; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Web.Mvc { @@ -387,7 +388,8 @@ namespace Umbraco.Tests.Web.Mvc { var umbracoContext = GetUmbracoContext("/dang", 0); - var publishedRouter = BaseWebTest.CreatePublishedRouter(TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings()); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + var publishedRouter = BaseWebTest.CreatePublishedRouter(webRoutingSettings); var frequest = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/dang")); frequest.Culture = CultureInfo.InvariantCulture; diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs index c6ded26ce2..b34ffb4def 100644 --- a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs +++ b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs @@ -9,7 +9,7 @@ namespace Umbraco.Web.Configuration { /// /// TEMPORARY: this class has been added just to ensure Umbraco.Web functionality continues to compile, by - /// converting between (used by + /// converting between e.g. (used by /// legacy configuration and (used by Netcore/IOptions configuration). /// public static class ConfigModelConversions From 2ed3568295d54b6bb3e8404d356180348a3ec8b8 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 10:11:19 +0200 Subject: [PATCH 15/58] Fix after merge. --- .../Services/Implement/NotificationService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 467338455b..411babe247 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -411,9 +411,9 @@ namespace Umbraco.Core.Services.Implement string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), summary.ToString()); - var fromMail = _contentSettings.Notifications.NotificationEmailAddress ?? _globalSettings.SmtpSettings.From; + var fromMail = _contentSettings.Notifications.NotificationEmailAddress ?? _globalSettings.Smtp.From; // create the mail message - var mail = new MailMessage(fromMail, mailingUser.Email); + var mail = new MailMessage(fromMail, fromMail); // populate the message From ae6fdede767734f9a9cf79ccf8a822f9e40fe504 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 10:23:50 +0200 Subject: [PATCH 16/58] Restored Umbraco.Tests to compiling state. --- src/Umbraco.Core/Composing/Composition.cs | 5 +++++ src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index 72d45605a6..6989d4d0a2 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -60,6 +60,11 @@ namespace Umbraco.Core.Composing /// public IRuntimeState RuntimeState { get; } + /// + /// Gets the configurations. + /// + public Configs Configs { get; } + #endregion #region IRegister diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index f63c56b64e..26322aa801 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -118,7 +118,7 @@ namespace Umbraco.Tests.Runtimes public class TestRuntime : CoreRuntime { public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - :base(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) + : base(Umbraco.Web.Configuration.ConfigModelConversions.ConvertGlobalSettings(configs.Global()), Umbraco.Web.Configuration.ConfigModelConversions.ConvertConnectionStrings(configs.ConnectionStrings()), umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) { } diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 9aeb668518..1675d75fc1 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -33,6 +33,7 @@ using Umbraco.Web; using Umbraco.Web.Hosting; using Umbraco.Web.Routing; using File = System.IO.File; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.TestHelpers { @@ -105,7 +106,7 @@ namespace Umbraco.Tests.TestHelpers public static IWebRoutingSettings WebRoutingSettings => _testHelperInternal.WebRoutingSettings; - public static IEmailSender EmailSender { get; } = new EmailSender(SettingsForTests.GenerateMockGlobalSettings()); + public static IEmailSender EmailSender { get; } = new EmailSender(new GlobalSettingsBuilder().Build()); /// From 2c05718689033eec24be76f10a6fb64587665c85 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 10:25:30 +0200 Subject: [PATCH 17/58] Restored Umbraco.Tests.Benchmarks. --- .../ModelToSqlExpressionHelperBenchmarks.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs index d200b3e295..6eb955ea8f 100644 --- a/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Linq.Expressions; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Diagnosers; +using Moq; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; From 967f0be705a8272c1760b7dcaddb0b45119eb1c9 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 10:45:54 +0200 Subject: [PATCH 18/58] Aligned property names in code with those in configuration. --- .../Configuration/GlobalSettingsExtensions.cs | 6 +-- .../Models/ContentNotificationSettings.cs | 2 +- .../Configuration/Models/ContentSettings.cs | 2 +- .../Configuration/Models/GlobalSettings.cs | 2 +- .../Configuration/Models/HostingSettings.cs | 2 +- .../Models/RequestHandlerSettings.cs | 6 ++- .../Configuration/Models/SecuritySettings.cs | 4 ++ .../FolderAndFilePermissionsCheck.cs | 2 +- .../Packaging/CompiledPackageXmlParser.cs | 2 +- .../Strings/DefaultShortStringHelperConfig.cs | 4 +- .../CompositionExtensions/Services.cs | 2 +- .../EmailNotificationMethod.cs | 2 +- .../Install/FilePermissionHelper.cs | 2 +- .../Services/Implement/FileService.cs | 4 +- .../Services/Implement/NotificationService.cs | 6 +-- .../BackOfficeJavaScriptInitializer.cs | 2 +- .../Builders/GlobalSettingsBuilder.cs | 18 +-------- .../Builders/HostingSettingsBuilder.cs | 10 ++--- .../BackOfficeCookieManagerTests.cs | 8 ++-- .../Builders/HostingSettingsBuilderTests.cs | 4 +- .../TestHelpers/ConfigModelConversions.cs | 2 +- .../Controllers/BackOfficeAssetsController.cs | 2 +- .../Controllers/BackOfficeController.cs | 4 +- .../Controllers/PreviewController.cs | 2 +- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 2 +- .../AspNetCoreHostingEnvironment.cs | 2 +- .../AspNetCore/UmbracoViewPage.cs | 2 +- .../UmbracoCoreServiceCollectionExtensions.cs | 38 +++++++++---------- .../Install/InstallController.cs | 4 +- .../Macros/MacroRenderer.cs | 2 +- .../Security/WebSecurity.cs | 2 +- .../Configuration/ConfigModelConversions.cs | 2 +- 32 files changed, 73 insertions(+), 81 deletions(-) diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs index f9b2362e14..dc52c8dcd6 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Configuration public static string GetBackOfficePath(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { if (_backOfficePath != null) return _backOfficePath; - _backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); + _backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.Path); return _backOfficePath; } @@ -44,9 +44,9 @@ namespace Umbraco.Core.Configuration internal static string GetUmbracoMvcAreaNoCache(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - var path = string.IsNullOrEmpty(globalSettings.UmbracoPath) + var path = string.IsNullOrEmpty(globalSettings.Path) ? string.Empty - : hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); + : hostingEnvironment.ToAbsolute(globalSettings.Path); if (path.IsNullOrWhiteSpace()) throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified"); diff --git a/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs index 0ae1ffd991..ab1c10ff77 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs @@ -2,7 +2,7 @@ { public class ContentNotificationSettings { - public string NotificationEmailAddress { get; set; } + public string Email { get; set; } public bool DisableHtmlEmail { get; set; } = false; } diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index 0a405d7db3..31a97e6615 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Configuration.Models public string PreviewBadge { get; set; } = DefaultPreviewBadge; - public MacroErrorBehaviour MacroErrorBehaviour { get; set; } = MacroErrorBehaviour.Inline; + public MacroErrorBehaviour MacroErrors { get; set; } = MacroErrorBehaviour.Inline; public IEnumerable DisallowedUploadFiles { get; set; } = new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }; diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index 8f5f64ffbc..ac659b6d05 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -30,7 +30,7 @@ public int VersionCheckPeriod { get; set; } = 7; - public string UmbracoPath { get; set; } = "~/umbraco"; + public string Path { get; set; } = "~/umbraco"; public string UmbracoCssPath { get; set; } = "~/css"; diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index ea389efde4..0863181922 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -13,6 +13,6 @@ /// Gets a value indicating whether umbraco is running in [debug mode]. /// /// true if [debug mode]; otherwise, false. - public bool DebugMode { get; set; } = false; + public bool Debug { get; set; } = false; } } diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs index e168122738..a2422fc899 100644 --- a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -35,9 +35,11 @@ namespace Umbraco.Core.Configuration.Models public bool AddTrailingSlash { get; set; } = true; - public bool ConvertUrlsToAscii { get; set; } = true; + public string ConvertUrlsToAscii { get; set; } = "try"; - public bool TryConvertUrlsToAscii { get; set; } = false; + public bool ShouldConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("true"); + + public bool ShouldTryConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("try"); //We need to special handle ":", as this character is special in keys diff --git a/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs index 5295abb368..f40160d69b 100644 --- a/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs @@ -13,5 +13,9 @@ public string AuthCookieDomain { get; set; } public bool UsernameIsEmail { get; set; } = true; + + public UserPasswordConfigurationSettings UserPassword { get; set; } + + public MemberPasswordConfigurationSettings MemberPassword { get; set; } } } diff --git a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs index d6fbfae813..8cd0d3a575 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs @@ -77,7 +77,7 @@ namespace Umbraco.Web.HealthCheck.Checks.Permissions { _globalSettings.UmbracoCssPath, PermissionCheckRequirement.Optional }, { _globalSettings.UmbracoMediaPath, PermissionCheckRequirement.Optional }, { _globalSettings.UmbracoScriptsPath, PermissionCheckRequirement.Optional }, - { _globalSettings.UmbracoPath, PermissionCheckRequirement.Optional }, + { _globalSettings.Path, PermissionCheckRequirement.Optional }, { Constants.SystemDirectories.MvcViews, PermissionCheckRequirement.Optional } }; diff --git a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs index 010e6469bf..2013fd9904 100644 --- a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs +++ b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs @@ -138,7 +138,7 @@ namespace Umbraco.Core.Packaging if (path.Contains("[$")) { //this is experimental and undocumented... - path = path.Replace("[$UMBRACO]", _globalSettings.UmbracoPath); + path = path.Replace("[$UMBRACO]", _globalSettings.Path); path = path.Replace("[$CONFIG]", Constants.SystemDirectories.Config); path = path.Replace("[$DATA]", Constants.SystemDirectories.Data); } diff --git a/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs b/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs index 32c02c09fb..d6adf5b221 100644 --- a/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs +++ b/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs @@ -65,9 +65,9 @@ namespace Umbraco.Core.Strings .ToDictionary(x => x.Char, x => x.Replacement); var urlSegmentConvertTo = CleanStringType.Utf8; - if (requestHandlerSettings.ConvertUrlsToAscii) + if (requestHandlerSettings.ShouldConvertUrlsToAscii) urlSegmentConvertTo = CleanStringType.Ascii; - if (requestHandlerSettings.TryConvertUrlsToAscii) + if (requestHandlerSettings.ShouldTryConvertUrlsToAscii) urlSegmentConvertTo = CleanStringType.TryAscii; return WithConfig(CleanStringType.UrlSegment, new Config diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs index ffd8b880f2..105ef00f73 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs @@ -103,7 +103,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions { var hostingEnvironment = container.GetInstance(); var globalSettings = container.GetInstance>().Value; - var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.UmbracoPath , "config","lang"))); + var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.Path , "config","lang"))); var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins)); var configLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Config ,"lang"))); diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index dd2f27320e..19d63d7d6a 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -79,7 +79,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods private MailMessage CreateMailMessage(string subject, string message) { - var to = _contentSettings.Notifications.NotificationEmailAddress; + var to = _contentSettings.Notifications.Email; if (string.IsNullOrWhiteSpace(subject)) subject = "Umbraco Health Check Status"; diff --git a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs index 7a20a1189e..07d78444c1 100644 --- a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Install _ioHelper = ioHelper; _publishedSnapshotService = publishedSnapshotService; _permissionDirs = new[] { _globalSettings.UmbracoCssPath, Constants.SystemDirectories.Config, Constants.SystemDirectories.Data, _globalSettings.UmbracoMediaPath, Constants.SystemDirectories.Preview }; - _packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.UmbracoPath, Constants.SystemDirectories.Packages }; + _packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.Path, Constants.SystemDirectories.Packages }; } public bool RunFilePermissionTestSuite(out Dictionary> report) diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index e82c71d1a5..086092597f 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -675,7 +675,7 @@ namespace Umbraco.Core.Services.Implement public IEnumerable GetPartialViewSnippetNames(params string[] filterNames) { - var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.UmbracoPath}/PartialViewMacros/Templates/"); + var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.Path}/PartialViewMacros/Templates/"); var files = Directory.GetFiles(snippetPath, "*.cshtml") .Select(Path.GetFileNameWithoutExtension) .Except(filterNames, StringComparer.InvariantCultureIgnoreCase) @@ -909,7 +909,7 @@ namespace Umbraco.Core.Services.Implement fileName += ".cshtml"; } - var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.UmbracoPath}/PartialViewMacros/Templates/{fileName}"); + var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.Path}/PartialViewMacros/Templates/{fileName}"); return System.IO.File.Exists(snippetPath) ? Attempt.Succeed(snippetPath) : Attempt.Fail(); diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 411babe247..9b0045da7b 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -392,7 +392,7 @@ namespace Umbraco.Core.Services.Implement var protocol = _globalSettings.UseHttps ? "https" : "http"; var subjectVars = new NotificationEmailSubjectParams( - string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), + string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.Path)), actionName, content.Name); @@ -408,10 +408,10 @@ namespace Umbraco.Core.Services.Implement string.Concat(content.Id, ".aspx"), protocol), performingUser.Name, - string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), + string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.Path)), summary.ToString()); - var fromMail = _contentSettings.Notifications.NotificationEmailAddress ?? _globalSettings.Smtp.From; + var fromMail = _contentSettings.Notifications.Email ?? _globalSettings.Smtp.From; // create the mail message var mail = new MailMessage(fromMail, fromMail); diff --git a/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs b/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs index 77db7bcbfd..8908978e4b 100644 --- a/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs +++ b/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.WebAssets } jarray.Append("]"); - return WriteScript(jarray.ToString(), hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), angularModule); + return WriteScript(jarray.ToString(), hostingEnvironment.ToAbsolute(globalSettings.Path), angularModule); } /// diff --git a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs index 72cc6de9a1..ab07331108 100644 --- a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs @@ -18,7 +18,6 @@ namespace Umbraco.Tests.Common.Builders private bool? _hideTopLevelNodeFromPath; private bool? _installEmptyDatabase; private bool? _installMissingDatabase; - private bool? _isSmtpServerConfigured; private string _path; private string _registerType; private string _reservedPaths; @@ -26,7 +25,6 @@ namespace Umbraco.Tests.Common.Builders private int? _timeOutInMinutes; private string _umbracoCssPath; private string _umbracoMediaPath; - private string _umbracoPath; private string _umbracoScriptsPath; private string _mainDomLock; private string _noNodesViewPath; @@ -83,12 +81,6 @@ namespace Umbraco.Tests.Common.Builders return this; } - public GlobalSettingsBuilder WithIsSmtpServerConfigured(bool isSmtpServerConfigured) - { - _isSmtpServerConfigured = isSmtpServerConfigured; - return this; - } - public GlobalSettingsBuilder WithPath(string path) { _path = path; @@ -113,12 +105,6 @@ namespace Umbraco.Tests.Common.Builders return this; } - public GlobalSettingsBuilder WithUmbracoPath(string umbracoPath) - { - _umbracoPath = umbracoPath; - return this; - } - public GlobalSettingsBuilder WithUseHttps(bool useHttps) { _useHttps = useHttps; @@ -178,7 +164,7 @@ namespace Umbraco.Tests.Common.Builders var registerType = _registerType ?? null; var reservedPaths = _reservedPaths ?? "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; var reservedUrls = _reservedUrls ?? "~/config/splashes/noNodes.aspx,~/.well-known,"; - var umbracoPath = _umbracoPath ?? "~/umbraco"; + var path = _path ?? "~/umbraco"; var useHttps = _useHttps ?? false; var umbracoCssPath = _umbracoCssPath ?? "~/css"; var umbracoMediaPath = _umbracoMediaPath ?? "~/media"; @@ -201,7 +187,7 @@ namespace Umbraco.Tests.Common.Builders RegisterType = registerType, ReservedPaths = reservedPaths, ReservedUrls = reservedUrls, - UmbracoPath = umbracoPath, + Path = path, UseHttps = useHttps, UmbracoCssPath = umbracoCssPath, UmbracoMediaPath = umbracoMediaPath, diff --git a/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs index 11e622d4d4..3e5e1db391 100644 --- a/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/HostingSettingsBuilder.cs @@ -6,7 +6,7 @@ namespace Umbraco.Tests.Common.Builders public class HostingSettingsBuilder : BuilderBase { private string _applicationVirtualPath; - private bool? _debugMode; + private bool? _debug; private LocalTempStorage? _localTempStorageLocation; public HostingSettingsBuilder WithApplicationVirtualPath(string applicationVirtualPath) @@ -15,9 +15,9 @@ namespace Umbraco.Tests.Common.Builders return this; } - public HostingSettingsBuilder WithDebugMode(bool debugMode) + public HostingSettingsBuilder WithDebug(bool debug) { - _debugMode = debugMode; + _debug = debug; return this; } @@ -29,14 +29,14 @@ namespace Umbraco.Tests.Common.Builders public override HostingSettings Build() { - var debugMode = _debugMode ?? false; + var debug = _debug ?? false; var localTempStorageLocation = _localTempStorageLocation ?? LocalTempStorage.Default; var applicationVirtualPath = _applicationVirtualPath ?? null; return new HostingSettings { ApplicationVirtualPath = applicationVirtualPath, - DebugMode = debugMode, + Debug = debug, LocalTempStorageLocation = localTempStorageLocation, }; } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs index 6fd5672085..d03d4386f0 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs @@ -57,7 +57,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco"), globalSettings, Mock.Of(), Mock.Of()); @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), globalSettings, Mock.Of(), GetMockLinkGenerator(out var remainingTimeoutSecondsPath, out var isAuthPath)); @@ -105,7 +105,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), globalSettings, Mock.Of(x => x.IsAvailable == true && x.Get(Constants.Security.ForceReAuthFlag) == "not null"), GetMockLinkGenerator(out var remainingTimeoutSecondsPath, out var isAuthPath)); @@ -127,7 +127,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), globalSettings, Mock.Of(), GetMockLinkGenerator(out var remainingTimeoutSecondsPath, out var isAuthPath)); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs index 81ab0a7183..377e143b97 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/HostingSettingsBuilderTests.cs @@ -18,12 +18,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders // Act var hostingSettings = builder - .WithDebugMode(debugMode) + .WithDebug(debugMode) .WithLocalTempStorageLocation(localTempStorageLocation) .Build(); // Assert - Assert.AreEqual(debugMode, hostingSettings.DebugMode); + Assert.AreEqual(debugMode, hostingSettings.Debug); Assert.AreEqual(localTempStorageLocation, hostingSettings.LocalTempStorageLocation); } } diff --git a/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs b/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs index 800374c690..5417116713 100644 --- a/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs +++ b/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs @@ -39,7 +39,7 @@ namespace Umbraco.Tests.TestHelpers TimeOutInMinutes = globalSettings.TimeOutInMinutes, UmbracoCssPath = globalSettings.UmbracoCssPath, UmbracoMediaPath = globalSettings.UmbracoMediaPath, - UmbracoPath = globalSettings.UmbracoPath, + UmbracoPath = globalSettings.Path, UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, UseHttps = globalSettings.UseHttps, VersionCheckPeriod = globalSettings.VersionCheckPeriod, diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs index 5ee7cf31cf..92df3b0fad 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.BackOffice.Controllers public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IOptions globalSettings) { - _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib"); + _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.Value.Path + Path.DirectorySeparatorChar + "lib"); } [HttpGet] diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index e3480984fd..6cf92d9100 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -78,7 +78,7 @@ namespace Umbraco.Web.BackOffice.Controllers [HttpGet] public async Task Default() { - var viewPath = Path.Combine(_globalSettings.UmbracoPath , Constants.Web.Mvc.BackOfficeArea, nameof(Default) + ".cshtml") + var viewPath = Path.Combine(_globalSettings.Path , Constants.Web.Mvc.BackOfficeArea, nameof(Default) + ".cshtml") .Replace("\\", "/"); // convert to forward slashes since it's a virtual path return await RenderDefaultOrProcessExternalLoginAsync( @@ -156,7 +156,7 @@ namespace Umbraco.Web.BackOffice.Controllers [StatusCodeResult(System.Net.HttpStatusCode.ServiceUnavailable)] public async Task AuthorizeUpgrade() { - var viewPath = Path.Combine(_globalSettings.UmbracoPath, Umbraco.Core.Constants.Web.Mvc.BackOfficeArea, nameof(AuthorizeUpgrade) + ".cshtml"); + var viewPath = Path.Combine(_globalSettings.Path, Umbraco.Core.Constants.Web.Mvc.BackOfficeArea, nameof(AuthorizeUpgrade) + ".cshtml"); return await RenderDefaultOrProcessExternalLoginAsync( //The default view to render when there is no external login info or errors () => View(viewPath), diff --git a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs index 3878eb9b14..7b370b1824 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs @@ -77,7 +77,7 @@ namespace Umbraco.Web.BackOffice.Controllers } var viewPath = Path.Combine( - _globalSettings.UmbracoPath, + _globalSettings.Path, Constants.Web.Mvc.BackOfficeArea, ControllerExtensions.GetControllerName() + ".cshtml") .Replace("\\", "/"); // convert to forward slashes since it's a virtual path diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index 6f40800307..6c83bc5747 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.Common.AspNetCore public AspNetCoreBackOfficeInfo(GlobalSettings globalSettings) { - GetAbsoluteUrl = globalSettings.UmbracoPath; + GetAbsoluteUrl = globalSettings.Path; } public string GetAbsoluteUrl { get; } // TODO make absolute diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index 54502fbe29..32c291bbce 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.Common.AspNetCore public string ApplicationServerAddress { get; } public string ApplicationVirtualPath { get; } - public bool IsDebugMode => _hostingSettings.DebugMode; + public bool IsDebugMode => _hostingSettings.Debug; public Version IISVersion { get; } public string LocalTempPath diff --git a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs index fde3d095fe..776f22eea1 100644 --- a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs +++ b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs @@ -64,7 +64,7 @@ namespace Umbraco.Web.Common.AspNetCore // creating previewBadge markup markupToInject = string.Format(ContentSettings.PreviewBadge, - IOHelper.ResolveUrl(GlobalSettings.UmbracoPath), + IOHelper.ResolveUrl(GlobalSettings.Path), Context.Request.GetEncodedUrl(), UmbracoContext.PublishedRequest.PublishedContent.Id); } diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 46d035d76b..b5583f0b7e 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -104,28 +104,28 @@ namespace Umbraco.Extensions { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); - services.Configure(configuration.GetSection("ConnectionStrings"), o => o.BindNonPublicProperties = true); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Core:Debug")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder")); + services.Configure(configuration.GetSection("ConnectionStrings"), o => o.BindNonPublicProperties = true); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Core:Debug")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Global")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "ModelsBuilder")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "HealthChecks")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "ModelsBuilder")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); // TODO: remove this var configsFactory = new AspNetCoreConfigsFactory(configuration); diff --git a/src/Umbraco.Web.Common/Install/InstallController.cs b/src/Umbraco.Web.Common/Install/InstallController.cs index b5da8eabd4..d3c0e5e0f3 100644 --- a/src/Umbraco.Web.Common/Install/InstallController.cs +++ b/src/Umbraco.Web.Common/Install/InstallController.cs @@ -78,7 +78,7 @@ namespace Umbraco.Web.Common.Install { case ValidateRequestAttempt.FailedNoPrivileges: case ValidateRequestAttempt.FailedNoContextId: - return Redirect(_globalSettings.UmbracoPath + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl()); + return Redirect(_globalSettings.Path + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl()); } } @@ -86,7 +86,7 @@ namespace Umbraco.Web.Common.Install ViewData.SetInstallApiBaseUrl(Url.GetInstallerApiUrl()); // get the base umbraco folder - var baseFolder = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath); + var baseFolder = _hostingEnvironment.ToAbsolute(_globalSettings.Path); ViewData.SetUmbracoBaseFolder(baseFolder); ViewData.SetUmbracoVersion(_umbracoVersion.SemanticVersion); diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index c1fb033d20..58c1e59338 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -290,7 +290,7 @@ namespace Umbraco.Web.Macros Alias = macro.Alias, MacroSource = macro.MacroSource, Exception = e, - Behaviour = _contentSettings.MacroErrorBehaviour + Behaviour = _contentSettings.MacroErrors }; switch (macroErrorEventArgs.Behaviour) diff --git a/src/Umbraco.Web.Common/Security/WebSecurity.cs b/src/Umbraco.Web.Common/Security/WebSecurity.cs index b822adf656..0f3831b94c 100644 --- a/src/Umbraco.Web.Common/Security/WebSecurity.cs +++ b/src/Umbraco.Web.Common/Security/WebSecurity.cs @@ -115,7 +115,7 @@ namespace Umbraco.Web.Common.Security private static bool RequestIsInUmbracoApplication(IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToString().IndexOf(hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), StringComparison.InvariantCultureIgnoreCase) > -1; + return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToString().IndexOf(hostingEnvironment.ToAbsolute(globalSettings.Path), StringComparison.InvariantCultureIgnoreCase) > -1; } } } diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs index b34ffb4def..7225c1c058 100644 --- a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs +++ b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs @@ -42,7 +42,7 @@ namespace Umbraco.Web.Configuration TimeOutInMinutes = globalSettings.TimeOutInMinutes, UmbracoCssPath = globalSettings.UmbracoCssPath, UmbracoMediaPath = globalSettings.UmbracoMediaPath, - UmbracoPath = globalSettings.UmbracoPath, + Path = globalSettings.UmbracoPath, UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, UseHttps = globalSettings.UseHttps, VersionCheckPeriod = globalSettings.VersionCheckPeriod, From b4e01392d9bf3bb1c44da26fb9127230abc85f49 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 11:00:11 +0200 Subject: [PATCH 19/58] Removed registration of old-style configuration in Netcore executable. --- .../Builders/RequestHandlerSettingsBuilder.cs | 9 ++++----- .../Builders/RequestHandlerSettingsBuilderTests.cs | 2 +- src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs | 2 +- .../Strings/DefaultShortStringHelperTests.cs | 6 +++--- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 5 ----- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs index 33f63c9d16..3c6f652014 100644 --- a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs @@ -7,7 +7,7 @@ namespace Umbraco.Tests.Common.Builders public class RequestHandlerSettingsBuilder : BuilderBase { private bool? _addTrailingSlash; - private bool? _convertUrlsToAscii; + private string _convertUrlsToAscii; private IEnumerable _charCollection; public RequestHandlerSettingsBuilder WithAddTrailingSlash(bool addTrailingSlash) @@ -16,7 +16,7 @@ namespace Umbraco.Tests.Common.Builders return this; } - public RequestHandlerSettingsBuilder WithConvertUrlsToAscii(bool convertUrlsToAscii) + public RequestHandlerSettingsBuilder WithConvertUrlsToAscii(string convertUrlsToAscii) { _convertUrlsToAscii = convertUrlsToAscii; return this; @@ -26,13 +26,12 @@ namespace Umbraco.Tests.Common.Builders { _charCollection = charCollection; return this; - } - + } public override RequestHandlerSettings Build() { var addTrailingSlash = _addTrailingSlash ?? false; - var convertUrlsToAscii = _convertUrlsToAscii ?? false; + var convertUrlsToAscii = _convertUrlsToAscii ?? "false"; var charCollection = _charCollection ?? RequestHandlerSettings.DefaultCharCollection; return new RequestHandlerSettings diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs index af6bc0ed6f..8d84a6d4c6 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs @@ -15,7 +15,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders { // Arrange const bool addTrailingSlash = true; - const bool convertUrlsToAscii = true; + const string convertUrlsToAscii = "try"; var charCollection = new List { new CharItem { Char = "a", Replacement = "b" } }; var builder = new RequestHandlerSettingsBuilder(); diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index fa6949cd09..cae2919621 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -25,7 +25,7 @@ namespace Umbraco.Tests.Configurations var hostingEnvironment = new AspNetHostingEnvironment(mockHostingSettings.Object); - var globalSettings = new GlobalSettingsBuilder().WithUmbracoPath(path).Build(); + var globalSettings = new GlobalSettingsBuilder().WithPath(path).Build(); Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment)); } diff --git a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs index 0def86e8d2..28d7d90f7e 100644 --- a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs +++ b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs @@ -98,7 +98,7 @@ namespace Umbraco.Tests.Strings public void U4_4056() { var requestHandlerSettings = new RequestHandlerSettingsBuilder() - .WithConvertUrlsToAscii(false) + .WithConvertUrlsToAscii("false") .WithCharCollection(Enumerable.Empty()) .Build(); @@ -123,7 +123,7 @@ namespace Umbraco.Tests.Strings public void U4_4056_TryAscii() { var requestHandlerSettings = new RequestHandlerSettingsBuilder() - .WithConvertUrlsToAscii(false) + .WithConvertUrlsToAscii("false") .WithCharCollection(Enumerable.Empty()) .Build(); @@ -411,7 +411,7 @@ namespace Umbraco.Tests.Strings var settings = _requestHandlerSettings; var contentMock = Mock.Get(settings); contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); - contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); + contentMock.Setup(x => x.ConvertUrlsToAscii).Returns("false"); var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings)); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index b5583f0b7e..b4911d6b59 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -127,11 +127,6 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); - // TODO: remove this - var configsFactory = new AspNetCoreConfigsFactory(configuration); - var configs = configsFactory.Create(); - services.AddSingleton(configs); - return services; } From 82416431834fef4a7a38c816b31ad070812402cb Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 12:30:43 +0200 Subject: [PATCH 20/58] Resolved various failing tests. --- src/Umbraco.Core/Composing/Composition.cs | 8 ++- .../Models/RequestHandlerSettings.cs | 2 +- .../ConfigModelConversionsFromLegacy.cs | 57 +++++++++++++++++++ .../ConfigModelConversionsToLegacy.cs} | 27 ++++++++- .../Models/ContentEditing/UserInvite.cs | 1 + .../Runtime/CoreRuntime.cs | 7 ++- .../ContainerTests.cs | 2 +- .../RequestHandlerSettingsBuilderTests.cs | 1 + .../Components/ComponentTests.cs | 28 ++++----- .../Composing/CollectionBuildersTests.cs | 2 +- .../Composing/CompositionTests.cs | 2 +- .../Composing/LazyCollectionBuilderTests.cs | 10 ++-- .../Composing/PackageActionCollectionTests.cs | 2 +- src/Umbraco.Tests/IO/FileSystemsTests.cs | 2 +- .../PropertyEditorValueEditorTests.cs | 2 +- .../Published/ConvertersTests.cs | 2 +- .../Routing/UmbracoModuleTests.cs | 20 ++----- src/Umbraco.Tests/Routing/UrlProviderTests.cs | 23 ++++---- .../Routing/UrlsProviderWithDomainsTests.cs | 17 +++--- .../Routing/UrlsWithNestedDomains.cs | 3 +- .../Runtimes/CoreRuntimeTests.cs | 6 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 4 +- .../Scoping/ScopeEventDispatcherTests.cs | 2 +- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 25 ++++++-- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - .../UmbracoCoreServiceCollectionExtensions.cs | 5 ++ src/Umbraco.Web/AppBuilderExtensions.cs | 4 +- .../Compose/AuditEventsComponent.cs | 6 +- .../Configuration/ConfigModelConversions.cs | 47 +-------------- .../Editors/BackOfficeController.cs | 6 +- .../Editors/BackOfficeServerVariables.cs | 18 +++--- .../Mvc/AreaRegistrationExtensions.cs | 7 +-- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 6 +- .../Mvc/UmbracoAuthorizeAttribute.cs | 6 +- .../Runtime/WebInitialComponent.cs | 9 +-- .../Security/BackOfficeOwinUserManager.cs | 3 +- .../Security/BackOfficeSignInManager.cs | 5 +- .../Security/GetUserSecondsMiddleWare.cs | 6 +- src/Umbraco.Web/UmbracoApplication.cs | 16 ++---- src/Umbraco.Web/UmbracoApplicationBase.cs | 11 ++-- src/Umbraco.Web/UmbracoContext.cs | 4 +- src/Umbraco.Web/UmbracoInjectedModule.cs | 13 ++--- .../CheckIfUserTicketDataIsStaleAttribute.cs | 11 ++-- 44 files changed, 234 insertions(+), 207 deletions(-) create mode 100644 src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs rename src/{Umbraco.Tests/TestHelpers/ConfigModelConversions.cs => Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs} (80%) diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index 6989d4d0a2..e248d9eaf3 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -28,14 +28,16 @@ namespace Umbraco.Core.Composing /// A type loader. /// A logger. /// The runtime state. + /// Optional configs. /// An IOHelper /// - public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, IIOHelper ioHelper, AppCaches appCaches) + public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs, IIOHelper ioHelper, AppCaches appCaches) { _register = register ?? throw new ArgumentNullException(nameof(register)); TypeLoader = typeLoader ?? throw new ArgumentNullException(nameof(typeLoader)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); RuntimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); + Configs = configs ?? throw new ArgumentNullException(nameof(configs)); IOHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); AppCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); } @@ -60,6 +62,7 @@ namespace Umbraco.Core.Composing /// public IRuntimeState RuntimeState { get; } + // TODO: remove this once no longer required for functionality in Umbraco.Web. /// /// Gets the configurations. /// @@ -133,8 +136,7 @@ namespace Umbraco.Core.Composing IFactory factory = null; - // TODO: what to do about this? - //Configs.RegisterWith(_register); + Configs.RegisterWith(_register); // ReSharper disable once AccessToModifiedClosure -- on purpose _register.Register(_ => factory, Lifetime.Singleton); diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs index a2422fc899..d7203b4901 100644 --- a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -59,7 +59,7 @@ namespace Umbraco.Core.Configuration.Models //} // return DefaultCharCollection; - public IEnumerable CharCollection { get; set; } + public IEnumerable CharCollection { get; set; } = DefaultCharCollection; public class CharItem : IChar { diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs new file mode 100644 index 0000000000..42ed290e63 --- /dev/null +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -0,0 +1,57 @@ +using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Infrastructure.Configuration +{ + /// + /// TEMPORARY: this class has been added just to ensure Umbraco.Web functionality continues to compile, by + /// converting between e.g. (used by + /// legacy configuration and (used by Netcore/IOptions configuration). + /// + public static class ConfigModelConversionsFromLegacy + { + public static GlobalSettings ConvertGlobalSettings(IGlobalSettings globalSettings) + { + return new GlobalSettings + { + DatabaseFactoryServerVersion = globalSettings.DatabaseFactoryServerVersion, + DefaultUILanguage = globalSettings.DefaultUILanguage, + DisableElectionForSingleServer = globalSettings.DisableElectionForSingleServer, + HideTopLevelNodeFromPath = globalSettings.HideTopLevelNodeFromPath, + InstallEmptyDatabase = globalSettings.InstallEmptyDatabase, + InstallMissingDatabase = globalSettings.InstallMissingDatabase, + MainDomLock = globalSettings.MainDomLock, + NoNodesViewPath = globalSettings.NoNodesViewPath, + RegisterType = globalSettings.RegisterType, + ReservedPaths = globalSettings.ReservedPaths, + ReservedUrls = globalSettings.ReservedUrls, + Smtp = new SmtpSettings + { + DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, + From = globalSettings.SmtpSettings.From, + Host = globalSettings.SmtpSettings.Host, + Password = globalSettings.SmtpSettings.Password, + PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, + Port = globalSettings.SmtpSettings.Port, + Username = globalSettings.SmtpSettings.Username, + }, + TimeOutInMinutes = globalSettings.TimeOutInMinutes, + UmbracoCssPath = globalSettings.UmbracoCssPath, + UmbracoMediaPath = globalSettings.UmbracoMediaPath, + Path = globalSettings.UmbracoPath, + UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, + UseHttps = globalSettings.UseHttps, + VersionCheckPeriod = globalSettings.VersionCheckPeriod, + }; + } + + public static ConnectionStrings ConvertConnectionStrings(IConnectionStrings connectionStrings) + { + return new ConnectionStrings + { + UmbracoConnectionString = connectionStrings[Constants.System.UmbracoConnectionName].ConnectionString + }; + } + } +} diff --git a/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs similarity index 80% rename from src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs rename to src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs index 5417116713..5b3607992c 100644 --- a/src/Umbraco.Tests/TestHelpers/ConfigModelConversions.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs @@ -1,15 +1,17 @@ -using System.Net.Mail; +using System.Collections.Generic; +using System.Net.Mail; +using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -namespace Umbraco.Tests.TestHelpers +namespace Umbraco.Infrastructure.Configuration { /// /// TEMPORARY: this class has been added just to ensure tests on Umbraco.Web functionality, that still use the interface /// based configuration, by converting between e.g (used by /// legacy configuration and (used by Netcore/IOptions configuration). /// - public static class ConfigModelConversions + public static class ConfigModelConversionsToLegacy { public static IGlobalSettings ConvertGlobalSettings(GlobalSettings globalSettings) { @@ -46,6 +48,13 @@ namespace Umbraco.Tests.TestHelpers }; } + public static IConnectionStrings ConvertConnectionStrings(ConnectionStrings connectionStrings) + { + var result = new TestConnectionStrings(); + result.AddEntry(Constants.System.UmbracoConnectionName, connectionStrings.UmbracoConnectionString); + return result; + } + private class TestGlobalSettings : IGlobalSettings { public string ReservedUrls { get; set; } @@ -105,5 +114,17 @@ namespace Umbraco.Tests.TestHelpers public string Password { get; set; } } + + private class TestConnectionStrings : IConnectionStrings + { + private IDictionary _dictionary = new Dictionary(); + + public ConfigConnectionString this[string key] => _dictionary[key]; + + public void AddEntry(string key, string connectionString) + { + _dictionary.Add(key, new ConfigConnectionString(connectionString, string.Empty, key)); + } + } } } diff --git a/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs b/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs index 06e4d0748c..428f85937b 100644 --- a/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs +++ b/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs @@ -33,6 +33,7 @@ namespace Umbraco.Web.Models.ContentEditing if (UserGroups.Any() == false) yield return new ValidationResult("A user must be assigned to at least one group", new[] { nameof(UserGroups) }); + // TODO: this will need another way of retrieving this setting if and when Configs are removed from Current. if (Current.Configs.Security().UsernameIsEmail == false && Username.IsNullOrWhiteSpace()) yield return new ValidationResult("A username cannot be empty", new[] { nameof(Username) }); } diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index ad036e12eb..968c240d62 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -12,6 +12,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; +using Umbraco.Infrastructure.Configuration; namespace Umbraco.Core.Runtime { @@ -179,7 +180,11 @@ namespace Umbraco.Core.Runtime var typeLoader = new TypeLoader(TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(HostingEnvironment.LocalTempPath), ProfilingLogger); // create the composition - composition = new Composition(register, typeLoader, ProfilingLogger, _state, IOHelper, appCaches); + // TODO: remove the configs parameter once we no longer need to provide it for Umbraco.Web and Umbraco.Tests functionality. + var configs = new Configs(); + configs.Add(() => ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + configs.Add(() => ConfigModelConversionsToLegacy.ConvertConnectionStrings(_connectionStrings)); + composition = new Composition(register, typeLoader, ProfilingLogger, _state, configs, IOHelper, appCaches); composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, MainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, UmbracoVersion, DbProviderFactoryCreator, HostingEnvironment, BackOfficeInfo); // register ourselves (TODO: Should we put this in RegisterEssentials?) diff --git a/src/Umbraco.Tests.Integration/ContainerTests.cs b/src/Umbraco.Tests.Integration/ContainerTests.cs index a50a24e780..2098b7241e 100644 --- a/src/Umbraco.Tests.Integration/ContainerTests.cs +++ b/src/Umbraco.Tests.Integration/ContainerTests.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.Integration // Register in the container var composition = new Composition(umbracoContainer, typeLoader, - testHelper.Logger, runtimeState, testHelper.IOHelper, testHelper.AppCaches); + testHelper.Logger, runtimeState, testHelper.GetConfigs(), testHelper.IOHelper, testHelper.AppCaches); composition.RegisterEssentials(testHelper.Logger, testHelper.Profiler, testHelper.Logger, testHelper.MainDom, testHelper.AppCaches, umbracoDatabaseFactory, typeLoader, runtimeState, testHelper.GetTypeFinder(), testHelper.IOHelper, testHelper.GetUmbracoVersion(), dbProviderFactoryCreator, diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs index 8d84a6d4c6..199b3dadde 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs @@ -24,6 +24,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders var requestHandlerSettings = builder .WithAddTrailingSlash(addTrailingSlash) .WithConvertUrlsToAscii(convertUrlsToAscii) + .WithCharCollection(charCollection) .Build(); // Assert diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 6f86108edb..4ce790db6c 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -75,7 +75,7 @@ namespace Umbraco.Tests.Components { var register = MockRegister(); var typeLoader = MockTypeLoader(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -114,7 +114,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -130,7 +130,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -145,7 +145,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -162,7 +162,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -185,7 +185,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -221,7 +221,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -247,7 +247,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -262,7 +262,7 @@ namespace Umbraco.Tests.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -280,7 +280,7 @@ namespace Umbraco.Tests.Components var register = MockRegister(); var typeLoader = MockTypeLoader(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -299,7 +299,7 @@ namespace Umbraco.Tests.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -338,7 +338,7 @@ namespace Umbraco.Tests.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -353,7 +353,7 @@ namespace Umbraco.Tests.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer26) }; var enableDisableAttributes = new[] { new DisableComposerAttribute(typeof(Composer26)) }; @@ -380,7 +380,7 @@ namespace Umbraco.Tests.Components var register = MockRegister(); var composition = new Composition(register, typeLoader, Mock.Of(), - MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var allComposers = typeLoader.GetTypes().ToList(); var types = allComposers.Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")).ToList(); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 4416723a55..2d977e89c7 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.Composing Current.Reset(); var register = TestHelper.GetRegister(); - _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); } [TearDown] diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 229ba1102b..380511eaaa 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing var typeFinder = TestHelper.GetTypeFinder(); var ioHelper = TestHelper.IOHelper; var typeLoader = new TypeLoader(typeFinder, Mock.Of(), new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), logger); - var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); // create the factory, ensure it is the mocked factory var factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index c17e80a34a..4d0135d6c4 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -67,7 +67,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -118,7 +118,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -140,7 +140,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 118eaab41a..390997173b 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Composing { var container = TestHelper.GetRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var expectedPackageActions = TypeLoader.GetPackageActions(); composition.WithCollectionBuilder() diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 71dd954052..c1d3fbb331 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.IO { _register = TestHelper.GetRegister(); - var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 439036fa16..d2d8cb952b 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.PropertyEditors Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); register.Register(_ diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 2ae4c238cc..3ecae51ea8 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -182,7 +182,7 @@ namespace Umbraco.Tests.Published // Current.Reset(); var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 252e03f4c0..87d63f3d8f 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -1,23 +1,13 @@ using System; -using System.IO; using System.Threading; using Moq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Composing; +using Umbraco.Core.Logging; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; -using Umbraco.Core.Sync; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.Services; -using Umbraco.Web.PublishedCache; -using Umbraco.Web.Routing; -using Umbraco.Web.Configuration; -using ConfigModelConversions = Umbraco.Tests.TestHelpers.ConfigModelConversions; -using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -43,10 +33,10 @@ namespace Umbraco.Tests.Routing logger, null, // FIXME: PublishedRouter complexities... Mock.Of(), - new RoutableDocumentFilter(ConfigModelConversions.ConvertGlobalSettings(globalSettings), IOHelper), + new RoutableDocumentFilter(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper), UriUtility, AppCaches.RequestCache, - ConfigModelConversions.ConvertGlobalSettings(globalSettings), + ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), HostingEnvironment ); diff --git a/src/Umbraco.Tests/Routing/UrlProviderTests.cs b/src/Umbraco.Tests/Routing/UrlProviderTests.cs index d7a6cc701a..b84bf41bee 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderTests.cs @@ -5,10 +5,11 @@ using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Web.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers; @@ -16,8 +17,6 @@ using Umbraco.Tests.Testing; using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; -using Umbraco.Tests.Common; -using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -50,7 +49,7 @@ namespace Umbraco.Tests.Routing var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -127,7 +126,7 @@ namespace Umbraco.Tests.Routing var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -156,7 +155,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(true).Build(); var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -198,7 +197,7 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings), + globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( @@ -255,7 +254,7 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings), + globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( @@ -312,7 +311,7 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings), + globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( @@ -336,7 +335,7 @@ namespace Umbraco.Tests.Routing var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -362,7 +361,7 @@ namespace Umbraco.Tests.Routing Logger, Microsoft.Extensions.Options.Options.Create(globalSettings), new SiteDomainHelper(), UmbracoContextAccessor, UriUtility); - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); //mock the Umbraco settings that we need diff --git a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs index 79813e662c..0998f1e722 100644 --- a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs @@ -4,14 +4,13 @@ using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; -using Umbraco.Tests.TestHelpers; using Umbraco.Web; using Umbraco.Web.Routing; @@ -183,7 +182,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, @@ -217,7 +216,7 @@ namespace Umbraco.Tests.Routing var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, @@ -244,7 +243,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, @@ -277,7 +276,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -301,7 +300,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -367,7 +366,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -394,7 +393,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index 085cf7f274..6e00b7a7f0 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -13,6 +13,7 @@ using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Web; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; +using Umbraco.Infrastructure.Configuration; namespace Umbraco.Tests.Routing { @@ -42,7 +43,7 @@ namespace Umbraco.Tests.Routing const string url = "http://domain1.com/1001-1/1001-1-1"; // get the nice url for 100111 - var umbracoContext = GetUmbracoContext(url, 9999, globalSettings: ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext(url, 9999, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 26322aa801..369eaeeac5 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Data; using Examine; using Moq; using NUnit.Framework; @@ -9,14 +8,13 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Events; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; -using Umbraco.Core.Scoping; +using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Stubs; @@ -118,7 +116,7 @@ namespace Umbraco.Tests.Runtimes public class TestRuntime : CoreRuntime { public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - : base(Umbraco.Web.Configuration.ConfigModelConversions.ConvertGlobalSettings(configs.Global()), Umbraco.Web.Configuration.ConfigModelConversions.ConvertConnectionStrings(configs.ConnectionStrings()), umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) + : base(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(configs.Global()), ConfigModelConversionsFromLegacy.ConvertConnectionStrings(configs.ConnectionStrings()), umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) { } diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 394ed902f8..2773eef4ab 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, ioHelper, appCaches); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); // create the core runtime and have it compose itself @@ -271,7 +271,7 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, ioHelper, appCaches); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); var umbracoVersion = TestHelper.GetUmbracoVersion(); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index e47e9692bd..a0c954e7bb 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Scoping var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); _testObjects = new TestObjects(register); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 3faea42f01..6bc228bf83 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), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index d339143c61..b8cab0d0f7 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -37,6 +37,7 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; +using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; @@ -58,7 +59,6 @@ using Umbraco.Web.Security.Providers; using Umbraco.Web.Services; using Umbraco.Web.Templates; using Umbraco.Web.Trees; -using ConfigModelConversions = Umbraco.Tests.TestHelpers.ConfigModelConversions; using Current = Umbraco.Web.Composing.Current; using FileSystems = Umbraco.Core.IO.FileSystems; @@ -176,7 +176,7 @@ namespace Umbraco.Tests.Testing var globalSettings = new GlobalSettingsBuilder().Build(); var settings = TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings(); - IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversions.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); + IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); IIpResolver ipResolver = new AspNetIpResolver(); UmbracoVersion = new UmbracoVersion(globalSettings); @@ -188,7 +188,7 @@ namespace Umbraco.Tests.Testing - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); @@ -412,6 +412,23 @@ namespace Umbraco.Tests.Testing protected virtual void ComposeSettings() { + var contentSettings = new ContentSettingsBuilder().Build(); + var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var userPasswordConfigurationSettings = new UserPasswordConfigurationSettingsBuilder().Build(); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(coreDebugSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); + + // TODO: remove this once legacy config is fully extracted. Composition.Configs.Add(() => TestHelpers.SettingsForTests.DefaultGlobalSettings); Composition.Configs.Add(() => TestHelpers.SettingsForTests.DefaultHostingSettings); Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings); @@ -420,8 +437,6 @@ namespace Umbraco.Tests.Testing Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockUserPasswordConfiguration); Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockMemberPasswordConfiguration); Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); - - //Composition.Configs.Add(() => new DefaultUserPasswordConfig()); } protected virtual void ComposeApplication(bool withApplication) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index b21814cab7..193b4093f5 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -145,7 +145,6 @@ - diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index b4911d6b59..80ea591037 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -127,6 +127,11 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); + // TODO: remove this once no longer requred in Umbraco.Web. + var configsFactory = new AspNetCoreConfigsFactory(configuration); + var configs = configsFactory.Create(); + services.AddSingleton(configs); + return services; } diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index 18eb3a54fe..499ebbd929 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -4,7 +4,7 @@ using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Logging; namespace Umbraco.Web @@ -47,7 +47,7 @@ namespace Umbraco.Web /// public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - var umbracoPath = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true }); } diff --git a/src/Umbraco.Web/Compose/AuditEventsComponent.cs b/src/Umbraco.Web/Compose/AuditEventsComponent.cs index 9b9a1671f3..9aabfd0a66 100644 --- a/src/Umbraco.Web/Compose/AuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/AuditEventsComponent.cs @@ -7,11 +7,11 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; -using Umbraco.Net; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Extensions; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Net; namespace Umbraco.Core.Compose { @@ -50,7 +50,7 @@ namespace Umbraco.Core.Compose public void Terminate() { } - public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(ConfigModelConversions.ConvertGlobalSettings(globalSettings)) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; + public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; private IUser CurrentPerformingUser { diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs index 7225c1c058..f3b74734b4 100644 --- a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs +++ b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs @@ -9,54 +9,11 @@ namespace Umbraco.Web.Configuration { /// /// TEMPORARY: this class has been added just to ensure Umbraco.Web functionality continues to compile, by - /// converting between e.g. (used by - /// legacy configuration and (used by Netcore/IOptions configuration). + /// converting between e.g. (used by + /// legacy configuration and (used by Netcore/IOptions configuration). /// public static class ConfigModelConversions { - public static GlobalSettings ConvertGlobalSettings(IGlobalSettings globalSettings) - { - return new GlobalSettings - { - DatabaseFactoryServerVersion = globalSettings.DatabaseFactoryServerVersion, - DefaultUILanguage = globalSettings.DefaultUILanguage, - DisableElectionForSingleServer = globalSettings.DisableElectionForSingleServer, - HideTopLevelNodeFromPath = globalSettings.HideTopLevelNodeFromPath, - InstallEmptyDatabase = globalSettings.InstallEmptyDatabase, - InstallMissingDatabase = globalSettings.InstallMissingDatabase, - MainDomLock = globalSettings.MainDomLock, - NoNodesViewPath = globalSettings.NoNodesViewPath, - RegisterType = globalSettings.RegisterType, - ReservedPaths = globalSettings.ReservedPaths, - ReservedUrls = globalSettings.ReservedUrls, - Smtp = new SmtpSettings - { - DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, - From = globalSettings.SmtpSettings.From, - Host = globalSettings.SmtpSettings.Host, - Password = globalSettings.SmtpSettings.Password, - PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, - Port = globalSettings.SmtpSettings.Port, - Username = globalSettings.SmtpSettings.Username, - }, - TimeOutInMinutes = globalSettings.TimeOutInMinutes, - UmbracoCssPath = globalSettings.UmbracoCssPath, - UmbracoMediaPath = globalSettings.UmbracoMediaPath, - Path = globalSettings.UmbracoPath, - UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, - UseHttps = globalSettings.UseHttps, - VersionCheckPeriod = globalSettings.VersionCheckPeriod, - }; - } - - public static Umbraco.Core.Configuration.Models.ConnectionStrings ConvertConnectionStrings(IConnectionStrings connectionStrings) - { - return new Umbraco.Core.Configuration.Models.ConnectionStrings - { - UmbracoConnectionString = connectionStrings[Constants.System.UmbracoConnectionName].ConnectionString - }; - } - public static IOptions ConvertToOptionsOfUserPasswordConfigurationSettings(IOptions identityOptions) { var passwordOptions = identityOptions.Value.Password; diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 3106d02dc8..34d6e49563 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -11,13 +11,13 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Web.Mvc; using Umbraco.Core.Services; -using Umbraco.Web.Configuration; using Umbraco.Web.Features; using Umbraco.Web.Security; using Constants = Umbraco.Core.Constants; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using BackOfficeIdentityUser = Umbraco.Core.BackOffice.BackOfficeIdentityUser; +using Umbraco.Infrastructure.Configuration; namespace Umbraco.Web.Editors { @@ -140,7 +140,7 @@ namespace Umbraco.Web.Editors if (defaultResponse == null) throw new ArgumentNullException("defaultResponse"); if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse"); - ViewData.SetUmbracoPath(ConfigModelConversions.ConvertGlobalSettings(GlobalSettings).GetUmbracoMvcArea(_hostingEnvironment)); + ViewData.SetUmbracoPath(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(GlobalSettings).GetUmbracoMvcArea(_hostingEnvironment)); //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) || @@ -255,7 +255,7 @@ namespace Umbraco.Web.Editors var groups = Services.UserService.GetUserGroupsByAlias(autoLinkOptions.GetDefaultUserGroups(UmbracoContext, loginInfo)); var autoLinkUser = BackOfficeIdentityUser.CreateNew( - ConfigModelConversions.ConvertGlobalSettings(GlobalSettings), + ConfigModelConversionsFromLegacy.ConvertGlobalSettings(GlobalSettings), loginInfo.Email, loginInfo.Email, autoLinkOptions.GetDefaultCulture(UmbracoContext, loginInfo)); diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index ec8d7e5dd5..8babcc703f 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -7,17 +7,15 @@ using System.Web; using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Web.Configuration; -using Umbraco.Web.Features; -using Umbraco.Web.HealthCheck; -using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Mvc; -using Umbraco.Web.Trees; -using Constants = Umbraco.Core.Constants; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.WebAssets; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Web.Features; +using Umbraco.Web.Mvc; using Umbraco.Web.Security; +using Umbraco.Web.Trees; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors { @@ -144,7 +142,7 @@ namespace Umbraco.Web.Editors { "umbracoSettings", new Dictionary { - {"umbracoPath", ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}, + {"umbracoPath", ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}, {"mediaPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath).TrimEnd('/')}, {"appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd('/')}, { @@ -168,8 +166,8 @@ namespace Umbraco.Web.Editors {"cssPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoCssPath).TrimEnd('/')}, {"allowPasswordReset", _securitySettings.AllowPasswordReset}, {"loginBackgroundImage", _contentSettings.LoginBackgroundImage}, - {"showUserInvite", EmailSender.CanSendRequiredEmail(ConfigModelConversions.ConvertGlobalSettings(globalSettings))}, - {"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(ConfigModelConversions.ConvertGlobalSettings(globalSettings))}, + {"showUserInvite", EmailSender.CanSendRequiredEmail(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings))}, + {"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings))}, {"showAllowSegmentationForDocumentTypes", false}, } }, diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index eee675e9fd..679fb7987c 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -6,11 +6,8 @@ using System.Web.Routing; using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Web.Composing; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -61,7 +58,7 @@ namespace Umbraco.Web.Mvc if (routes == null) throw new ArgumentNullException(nameof(routes)); if (defaultId == null) throw new ArgumentNullException(nameof(defaultId)); - var umbracoArea = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoArea = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); //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 4a4202b42b..677ae18a1e 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,9 +1,7 @@ using System.Web.Mvc; -using Umbraco.Web.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Editors; namespace Umbraco.Web.Mvc @@ -51,6 +49,6 @@ namespace Umbraco.Web.Mvc new[] {typeof (BackOfficeController).Namespace}); } - public override string AreaName => ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetUmbracoMvcArea(_hostingEnvironment); + public override string AreaName => ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetUmbracoMvcArea(_hostingEnvironment); } } diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index 9fc58a208f..d9baa25823 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -2,9 +2,9 @@ using System.Web; using System.Web.Mvc; using Umbraco.Core; -using Umbraco.Web.Composing; using Umbraco.Core.Configuration; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Web.Composing; using Umbraco.Web.Security; namespace Umbraco.Web.Mvc @@ -56,7 +56,7 @@ namespace Umbraco.Web.Mvc { if (redirectToUmbracoLogin) { - _redirectUrl = ConfigModelConversions.ConvertGlobalSettings(Current.Configs.Global()).GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); + _redirectUrl = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(Current.Configs.Global()).GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index 5ad51acbc0..4c66322cde 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -10,12 +10,9 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Strings; -using Umbraco.Core.IO; -using Umbraco.Web.Configuration; -using Umbraco.Web.Install; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; - using Constants = Umbraco.Core.Constants; using Current = Umbraco.Web.Composing.Current; @@ -118,7 +115,7 @@ namespace Umbraco.Web.Runtime UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) { - var umbracoPath = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); // create the front-end route var defaultRoute = RouteTable.Routes.MapRoute( @@ -155,7 +152,7 @@ namespace Umbraco.Web.Runtime UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) { - var umbracoPath = ConfigModelConversions.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); // need to find the plugin controllers and route them var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray(); diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index 92e4fca420..d11edc7bba 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Mapping; using Umbraco.Core.Security; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Web.Configuration; @@ -54,7 +55,7 @@ namespace Umbraco.Web.Security IDataProtectionProvider dataProtectionProvider, ILogger> logger) { - var store = new BackOfficeUserStore(userService, entityService, externalLoginService, ConfigModelConversions.ConvertGlobalSettings(globalSettings), mapper); + var store = new BackOfficeUserStore(userService, entityService, externalLoginService, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings), mapper); return Create( passwordConfiguration, diff --git a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs index c998b579a1..fe90db9ec7 100644 --- a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs @@ -10,8 +10,7 @@ using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; -using Umbraco.Core.BackOffice; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; namespace Umbraco.Web.Security { @@ -79,7 +78,7 @@ namespace Umbraco.Web.Security var user = await _userManager.FindByNameAsync(userName); //if the user is null, create an empty one which can be used for auto-linking - if (user == null) user = BackOfficeIdentityUser.CreateNew(ConfigModelConversions.ConvertGlobalSettings(_globalSettings), userName, null, _globalSettings.DefaultUILanguage); + if (user == null) user = BackOfficeIdentityUser.CreateNew(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings), userName, null, _globalSettings.DefaultUILanguage); //check the password for the user, this will allow a developer to auto-link //an account if they have specified an IBackOfficeUserPasswordChecker diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index f73f25f859..5c3ab46101 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -9,9 +9,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Core.Security; -using Umbraco.Web.Configuration; +using Umbraco.Infrastructure.Configuration; namespace Umbraco.Web.Security { @@ -54,7 +52,7 @@ namespace Umbraco.Web.Security if (request.Uri.Scheme.InvariantStartsWith("http") && request.Uri.AbsolutePath.InvariantEquals( - $"{ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) + $"{ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) { var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName); if (cookie.IsNullOrWhiteSpace() == false) diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 4cdcecc1ce..843082e884 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -1,20 +1,14 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading; +using System.Runtime.InteropServices; using System.Web; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; -using Umbraco.Core.Logging.Serilog; -using Umbraco.Core.Runtime; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; +using Umbraco.Core.Runtime; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Runtime; -using Umbraco.Web.Configuration; namespace Umbraco.Web { @@ -30,8 +24,8 @@ namespace Umbraco.Web var dbProviderFactoryCreator = new UmbracoDbProviderFactoryCreator(); - var globalSettings = ConfigModelConversions.ConvertGlobalSettings(configs.Global()); - var connectionStrings = ConfigModelConversions.ConvertConnectionStrings(configs.ConnectionStrings()); + var globalSettings = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(configs.Global()); + var connectionStrings = ConfigModelConversionsFromLegacy.ConvertConnectionStrings(configs.ConnectionStrings()); // Determine if we should use the sql main dom or the default var appSettingMainDomLock = globalSettings.MainDomLock; diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 984f46bd60..4f6f2c7f0f 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -1,10 +1,10 @@ -using Serilog.Context; -using System; +using System; using System.IO; using System.Reflection; using System.Threading; using System.Web; using System.Web.Hosting; +using Serilog.Context; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; @@ -14,9 +14,8 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Logging.Serilog.Enrichers; +using Umbraco.Infrastructure.Configuration; using Umbraco.Net; -using Umbraco.Web.AspNet; -using Umbraco.Web.Configuration; using Umbraco.Web.Hosting; using Umbraco.Web.Logging; using Current = Umbraco.Web.Composing.Current; @@ -128,7 +127,7 @@ namespace Umbraco.Web /// protected virtual IRegister GetRegister(IGlobalSettings globalSettings) { - return RegisterFactory.Create(ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + return RegisterFactory.Create(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)); } // events - in the order they trigger @@ -161,7 +160,7 @@ namespace Umbraco.Web var globalSettings = Umbraco.Composing.Current.Configs.Global(); - var umbracoVersion = new UmbracoVersion(ConfigModelConversions.ConvertGlobalSettings(globalSettings)); + var umbracoVersion = new UmbracoVersion(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)); // create the register for the application, and boot // the boot manager is responsible for registrations diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index e94e0acc0b..73ee4a377e 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -4,8 +4,8 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Composing; -using Umbraco.Web.Configuration; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -182,7 +182,7 @@ namespace Umbraco.Web { var request = GetRequestFromContext(); if (request?.Url != null - && request.Url.IsBackOfficeRequest(ConfigModelConversions.ConvertGlobalSettings(_globalSettings), _hostingEnvironment) == false + && request.Url.IsBackOfficeRequest(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings), _hostingEnvironment) == false && Security.CurrentUser != null) { var previewToken = _cookieManager.GetPreviewCookieValue(); // may be null or empty diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index a610d216a3..3bd627be71 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -1,19 +1,16 @@ using System; -using System.Collections.Generic; using System.Web; using System.Web.Routing; using Umbraco.Core; -using Umbraco.Core.Security; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Logging; +using Umbraco.Core.Security; +using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Composing; using Umbraco.Web.Routing; -using Umbraco.Web.Security; -using Umbraco.Web.Configuration; namespace Umbraco.Web { @@ -114,7 +111,7 @@ namespace Umbraco.Web var umbracoContext = Current.UmbracoContext; // re-write for the default back office path - if (httpContext.Request.Url.IsDefaultBackOfficeRequest(ConfigModelConversions.ConvertGlobalSettings(_globalSettings), _hostingEnvironment)) + if (httpContext.Request.Url.IsDefaultBackOfficeRequest(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings), _hostingEnvironment)) { if (EnsureRuntime(httpContext, umbracoContext.OriginalRequestUrl)) RewriteToBackOfficeHandler(httpContext); @@ -247,7 +244,7 @@ namespace Umbraco.Web private void RewriteToBackOfficeHandler(HttpContextBase context) { // GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any) - var rewritePath = ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default"; + var rewritePath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default"; // rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc) context.RewritePath(rewritePath, "", "", false); @@ -280,7 +277,7 @@ namespace Umbraco.Web var query = pcr.Uri.Query.TrimStart('?'); // GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any) - var rewritePath = ConfigModelConversions.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc"; + var rewritePath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc"; // rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc) context.RewritePath(rewritePath, "", query, false); diff --git a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index bae6d00048..ee057408e9 100644 --- a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -5,14 +5,13 @@ using System.Threading.Tasks; using System.Web.Http.Controllers; using System.Web.Http.Filters; using Umbraco.Core; -using Umbraco.Web.Composing; using Umbraco.Core.BackOffice; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Security; -using Umbraco.Web.Security; using Umbraco.Core.Mapping; using Umbraco.Core.Models; -using Umbraco.Web.Configuration; +using Umbraco.Core.Models.Membership; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Web.Composing; +using Umbraco.Web.Security; namespace Umbraco.Web.WebApi.Filters { @@ -79,7 +78,7 @@ namespace Umbraco.Web.WebApi.Filters () => user.Username != identity.Username, () => { - var culture = user.GetUserCulture(Current.Services.TextService, ConfigModelConversions.ConvertGlobalSettings(Current.Configs.Global())); + var culture = user.GetUserCulture(Current.Services.TextService, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(Current.Configs.Global())); return culture != null && culture.ToString() != identity.Culture; }, () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, From 8666547cf114f19de189ae94188062d74d0ce72a Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 25 Aug 2020 14:19:33 +0200 Subject: [PATCH 21/58] Updated configuration models used within Umbraco.ModelsBuilder.Embedded project. --- .../BackOffice/ContentTypeModelValidator.cs | 3 ++- .../BackOffice/ContentTypeModelValidatorBase.cs | 6 +++--- .../BackOffice/DashboardReport.cs | 8 +++++--- .../BackOffice/MediaTypeModelValidator.cs | 4 ++-- .../BackOffice/MemberTypeModelValidator.cs | 4 ++-- .../BackOffice/ModelsBuilderDashboardController.cs | 8 +++++--- src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs | 8 +++++--- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 1 - 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs index 75affe09e7..af2a2a04cd 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +11,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class ContentTypeModelValidator : ContentTypeModelValidatorBase { - public ContentTypeModelValidator(IModelsBuilderConfig config) : base(config) + public ContentTypeModelValidator(ModelsBuilderConfig config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs index 1e96e64df8..02ac9e42eb 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Umbraco.Core.Configuration; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Editors; using Umbraco.Web.Models.ContentEditing; @@ -13,9 +13,9 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice where TModel : ContentTypeSave where TProperty : PropertyTypeBasic { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; - public ContentTypeModelValidatorBase(IModelsBuilderConfig config) + public ContentTypeModelValidatorBase(ModelsBuilderConfig config) { _config = config; } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs index 6e22313474..a0928fafcf 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/DashboardReport.cs @@ -1,18 +1,20 @@ using System.Text; +using Microsoft.Extensions.Options; using Umbraco.Configuration; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.ModelsBuilder.Embedded.BackOffice { internal class DashboardReport { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly ModelsGenerationError _mbErrors; - public DashboardReport(IModelsBuilderConfig config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) + public DashboardReport(IOptions config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { - _config = config; + _config = config.Value; _outOfDateModels = outOfDateModels; _mbErrors = mbErrors; } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs index fcd42908e7..5e29a888a0 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs @@ -1,4 +1,4 @@ -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +10,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class MediaTypeModelValidator : ContentTypeModelValidatorBase { - public MediaTypeModelValidator(IModelsBuilderConfig config) : base(config) + public MediaTypeModelValidator(ModelsBuilderConfig config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs index 2e249eed4d..970259d06b 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs @@ -1,4 +1,4 @@ -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +10,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class MemberTypeModelValidator : ContentTypeModelValidatorBase { - public MemberTypeModelValidator(IModelsBuilderConfig config) : base(config) + public MemberTypeModelValidator(ModelsBuilderConfig config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs index 17b694de56..6179e7c756 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs @@ -3,8 +3,10 @@ using System.Net; using System.Net.Http; using System.Runtime.Serialization; using System.Web.Hosting; +using Microsoft.Extensions.Options; using Umbraco.Configuration; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Exceptions; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Web.Editors; @@ -23,16 +25,16 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice [UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)] public class ModelsBuilderDashboardController : UmbracoAuthorizedJsonController { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly ModelsGenerator _modelGenerator; private readonly OutOfDateModelsStatus _outOfDateModels; private readonly ModelsGenerationError _mbErrors; private readonly DashboardReport _dashboardReport; - public ModelsBuilderDashboardController(IModelsBuilderConfig config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) + public ModelsBuilderDashboardController(IOptions config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { //_umbracoServices = umbracoServices; - _config = config; + _config = config.Value; _modelGenerator = modelsGenerator; _outOfDateModels = outOfDateModels; _mbErrors = mbErrors; diff --git a/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs b/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs index 61d39cd373..ef3b215968 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/LiveModelsProvider.cs @@ -6,6 +6,8 @@ using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Web.Cache; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.ModelsBuilder.Embedded { @@ -15,7 +17,7 @@ namespace Umbraco.ModelsBuilder.Embedded private static Mutex _mutex; private static int _req; private readonly ILogger _logger; - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly ModelsGenerator _modelGenerator; private readonly ModelsGenerationError _mbErrors; private readonly IHostingEnvironment _hostingEnvironment; @@ -23,10 +25,10 @@ namespace Umbraco.ModelsBuilder.Embedded // we do not manage pure live here internal bool IsEnabled => _config.ModelsMode.IsLiveNotPure(); - public LiveModelsProvider(ILogger logger, IModelsBuilderConfig config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IHostingEnvironment hostingEnvironment) + public LiveModelsProvider(ILogger logger, IOptions config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IHostingEnvironment hostingEnvironment) { _logger = logger; - _config = config ?? throw new ArgumentNullException(nameof(config)); + _config = config.Value ?? throw new ArgumentNullException(nameof(config)); _modelGenerator = modelGenerator; _mbErrors = mbErrors; _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 80ea591037..d829f6a3f2 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -14,7 +14,6 @@ using Serilog; using Serilog.Extensions.Hosting; using Serilog.Extensions.Logging; using Umbraco.Configuration; -using Umbraco.Configuration.Models; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; From 8fd59d546eea64d000ec3dbf0a59bc004a51c5cf Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 26 Aug 2020 07:55:23 +0200 Subject: [PATCH 22/58] Fixed failing tests. --- src/Umbraco.Core/Umbraco.Core.csproj | 2 +- .../ConfigModelConversionsFromLegacy.cs | 22 ++-- .../Packaging/PackageDataInstallation.cs | 5 +- .../Persistence/UmbracoDatabaseFactory.cs | 3 - src/Umbraco.Tests.Integration/RuntimeTests.cs | 2 +- src/Umbraco.Tests/App.config | 2 +- src/Umbraco.Tests/IO/FileSystemsTests.cs | 5 +- .../Packaging/PackageInstallationTest.cs | 4 +- .../Routing/BaseUrlProviderTest.cs | 49 ++++++++ .../Routing/GetContentUrlsTests.cs | 2 +- ...oviderWithHideTopLevelNodeFromPathTests.cs | 60 +++++++++ ...erWithoutHideTopLevelNodeFromPathTests.cs} | 116 +++++------------- .../Routing/UrlsProviderWithDomainsTests.cs | 14 +-- .../Routing/UrlsWithNestedDomains.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 18 +++ .../Strings/DefaultShortStringHelperTests.cs | 69 ++++++----- .../TEMP/DatabaseContextTests.sdf | Bin 983040 -> 983040 bytes src/Umbraco.Tests/TestHelpers/TestObjects.cs | 6 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 +- .../Controllers/ContentTypeController.cs | 2 +- 20 files changed, 235 insertions(+), 152 deletions(-) create mode 100644 src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs create mode 100644 src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs rename src/Umbraco.Tests/Routing/{UrlProviderTests.cs => UrlProviderWithoutHideTopLevelNodeFromPathTests.cs} (76%) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 4f1c421d97..ca5569aa4d 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index 42ed290e63..529568ca16 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -26,16 +26,18 @@ namespace Umbraco.Infrastructure.Configuration RegisterType = globalSettings.RegisterType, ReservedPaths = globalSettings.ReservedPaths, ReservedUrls = globalSettings.ReservedUrls, - Smtp = new SmtpSettings - { - DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, - From = globalSettings.SmtpSettings.From, - Host = globalSettings.SmtpSettings.Host, - Password = globalSettings.SmtpSettings.Password, - PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, - Port = globalSettings.SmtpSettings.Port, - Username = globalSettings.SmtpSettings.Username, - }, + Smtp = globalSettings.SmtpSettings != null + ? new SmtpSettings + { + DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, + From = globalSettings.SmtpSettings.From, + Host = globalSettings.SmtpSettings.Host, + Password = globalSettings.SmtpSettings.Password, + PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, + Port = globalSettings.SmtpSettings.Port, + Username = globalSettings.SmtpSettings.Username, + } + : new SmtpSettings(), TimeOutInMinutes = globalSettings.TimeOutInMinutes, UmbracoCssPath = globalSettings.UmbracoCssPath, UmbracoMediaPath = globalSettings.UmbracoMediaPath, diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index a868170c5f..79f830bc51 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Xml.Linq; using System.Xml.XPath; +using Microsoft.Extensions.Options; using Umbraco.Core.Collections; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; @@ -38,7 +39,7 @@ namespace Umbraco.Core.Packaging public PackageDataInstallation(ILogger logger, IFileService fileService, IMacroService macroService, ILocalizationService localizationService, IDataTypeService dataTypeService, IEntityService entityService, IContentTypeService contentTypeService, - IContentService contentService, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, IShortStringHelper shortStringHelper, GlobalSettings globalSettings, + IContentService contentService, PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, IShortStringHelper shortStringHelper, IOptions globalSettings, ILocalizedTextService localizedTextService) { _logger = logger; @@ -49,7 +50,7 @@ namespace Umbraco.Core.Packaging _propertyEditors = propertyEditors; _scopeProvider = scopeProvider; _shortStringHelper = shortStringHelper; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _localizedTextService = localizedTextService; _entityService = entityService; _contentTypeService = contentTypeService; diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index 1b46a6a3cd..afdf4c879a 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -1,11 +1,8 @@ using System; using System.Data.Common; -using System.Data.SqlClient; using System.Threading; using NPoco; using NPoco.FluentMappings; -using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.FaultHandling; diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index 11bda500b2..c51c991e26 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -75,7 +75,7 @@ namespace Umbraco.Tests.Integration Assert.IsFalse(MyComponent.IsInit); Assert.IsFalse(MyComponent.IsTerminated); - // TODO: found these registration were necessary here (as we haven't called the HostBuilder?), and dependencies for ComponentCollection + // TODO: found these registration were necessary here (as we haven't called the HostBuilder?), as dependencies for ComponentCollection // are not resolved. Need to check this if these explicit registrations are the best way to handle this. var contentSettings = new ContentSettingsBuilder().Build(); var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); diff --git a/src/Umbraco.Tests/App.config b/src/Umbraco.Tests/App.config index 09c025aeb4..2781babfbe 100644 --- a/src/Umbraco.Tests/App.config +++ b/src/Umbraco.Tests/App.config @@ -16,7 +16,7 @@ - + diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index c1d3fbb331..eabd331a02 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -16,6 +16,7 @@ using Umbraco.Tests.TestHelpers; using Umbraco.Core.Composing.CompositionExtensions; using Current = Umbraco.Web.Composing.Current; using FileSystems = Umbraco.Core.IO.FileSystems; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.IO { @@ -42,7 +43,9 @@ namespace Umbraco.Tests.IO composition.RegisterUnique(TestHelper.GetHostingEnvironment()); composition.Configs.Add(() => SettingsForTests.DefaultGlobalSettings); - composition.Configs.Add(SettingsForTests.GenerateMockContentSettings); + + var globalSettings = new GlobalSettingsBuilder().Build(); + composition.Register(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); composition.ComposeFileSystems(); diff --git a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs index 04c51029c7..16c57a7dcb 100644 --- a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs +++ b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs @@ -60,8 +60,8 @@ namespace Umbraco.Tests.Packaging Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), - new GlobalSettingsBuilder().Build(), - Factory.GetInstance() ); + Microsoft.Extensions.Options.Options.Create(new GlobalSettingsBuilder().Build()), + Factory.GetInstance()); private IPackageInstallation PackageInstallation => new PackageInstallation( PackageDataInstallation, diff --git a/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs b/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs new file mode 100644 index 0000000000..999748bc73 --- /dev/null +++ b/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs @@ -0,0 +1,49 @@ +using System.Linq; +using Moq; +using Umbraco.Core; +using Umbraco.Core.Models.PublishedContent; +using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.TestHelpers; +using Umbraco.Web; +using Umbraco.Web.Routing; + +namespace Umbraco.Tests.Routing +{ + public abstract class BaseUrlProviderTest : BaseWebTest + { + protected IUmbracoContextAccessor UmbracoContextAccessor { get; } = new TestUmbracoContextAccessor(); + + protected abstract bool HideTopLevelNodeFromPath { get; } + + protected override void Compose() + { + base.Compose(); + Composition.Register(); + } + + protected override void ComposeSettings() + { + var contentSettings = new ContentSettingsBuilder().Build(); + var userPasswordConfigurationSettings = new UserPasswordConfigurationSettingsBuilder().Build(); + + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); + + // TODO: remove this once legacy config is fully extracted. + Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); + Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockGlobalSettings); + } + + protected IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) + { + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + return new UrlProvider( + new TestUmbracoContextAccessor(umbracoContext), + Microsoft.Extensions.Options.Options.Create(webRoutingSettings), + new UrlProviderCollection(new[] { urlProvider }), + new MediaUrlProviderCollection(Enumerable.Empty()), + Mock.Of()); + } + } +} diff --git a/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs b/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs index 7456d32aa4..27027c007f 100644 --- a/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs +++ b/src/Umbraco.Tests/Routing/GetContentUrlsTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Routing _globalSettings = new GlobalSettingsBuilder().Build(); _webRoutingSettings = new WebRoutingSettingsBuilder().Build(); - _requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + _requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); } private ILocalizedTextService GetTextService() diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs new file mode 100644 index 0000000000..b38e7b5fc9 --- /dev/null +++ b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs @@ -0,0 +1,60 @@ +using Moq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Testing; +using Umbraco.Web.Routing; + +namespace Umbraco.Tests.Routing +{ + [TestFixture] + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] + public class UrlProviderWithHideTopLevelNodeFromPathTests : BaseUrlProviderTest + { + private readonly GlobalSettings _globalSettings; + + public UrlProviderWithHideTopLevelNodeFromPathTests() + { + _globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(HideTopLevelNodeFromPath).Build(); + } + + protected override bool HideTopLevelNodeFromPath => true; + + protected override void ComposeSettings() + { + base.ComposeSettings(); + Composition.RegisterUnique(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); + } + + [TestCase(1046, "/")] + [TestCase(1173, "/sub1/")] + [TestCase(1174, "/sub1/sub2/")] + [TestCase(1176, "/sub1/sub-3/")] + [TestCase(1177, "/sub1/custom-sub-1/")] + [TestCase(1178, "/sub1/custom-sub-2/")] + [TestCase(1175, "/sub-2/")] + [TestCase(1172, "/test-page/")] // not hidden because not first root + public void Get_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch) + { + var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container + globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(true); + + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); + var urlProvider = new DefaultUrlProvider( + Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), + Logger, + Microsoft.Extensions.Options.Options.Create(_globalSettings), + new SiteDomainHelper(), umbracoContextAccessor, UriUtility); + var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); + + var result = publishedUrlProvider.GetUrl(nodeId); + Assert.AreEqual(niceUrlMatch, result); + } + } +} diff --git a/src/Umbraco.Tests/Routing/UrlProviderTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs similarity index 76% rename from src/Umbraco.Tests/Routing/UrlProviderTests.cs rename to src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs index b84bf41bee..e4275fe391 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs @@ -4,7 +4,7 @@ using System.Globalization; using System.Linq; using Moq; using NUnit.Framework; -using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Infrastructure.Configuration; @@ -12,9 +12,7 @@ using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.PublishedContent; -using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; -using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; @@ -22,20 +20,21 @@ namespace Umbraco.Tests.Routing { [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] - public class UrlProviderTests : BaseWebTest + public class UrlProviderWithoutHideTopLevelNodeFromPathTests : BaseUrlProviderTest { - private IUmbracoContextAccessor UmbracoContextAccessor { get; } = new TestUmbracoContextAccessor(); + private readonly GlobalSettings _globalSettings; - protected override void Compose() + public UrlProviderWithoutHideTopLevelNodeFromPathTests() { - base.Compose(); - Composition.Register(); + _globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(HideTopLevelNodeFromPath).Build(); } + protected override bool HideTopLevelNodeFromPath => false; + protected override void ComposeSettings() { - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockGlobalSettings); + base.ComposeSettings(); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); } /// @@ -45,21 +44,17 @@ namespace Umbraco.Tests.Routing [Test] public void Ensure_Cache_Is_Correct() { - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(false).Build(); - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); - var requestHandlerMock = Mock.Get(requestHandlerSettings); - requestHandlerMock.Setup(x => x.AddTrailingSlash).Returns(false);// (cached routes have none) var samples = new Dictionary { { 1046, "/home" }, @@ -100,18 +95,6 @@ namespace Umbraco.Tests.Routing Assert.AreEqual(0, cachedIds.Count); } - private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) - { - var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); - return new UrlProvider( - new TestUmbracoContextAccessor(umbracoContext), - Microsoft.Extensions.Options.Options.Create(webRoutingSettings), - new UrlProviderCollection(new []{urlProvider}), - new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); - } - - // test hideTopLevelNodeFromPath false [TestCase(1046, "/home/")] [TestCase(1173, "/home/sub1/")] [TestCase(1174, "/home/sub1/sub2/")] @@ -122,45 +105,14 @@ namespace Umbraco.Tests.Routing [TestCase(1172, "/test-page/")] public void Get_Url_Not_Hiding_Top_Level(int nodeId, string niceUrlMatch) { - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), - new SiteDomainHelper(), umbracoContextAccessor, UriUtility); - var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); - - var result = publishedUrlProvider.GetUrl(nodeId); - Assert.AreEqual(niceUrlMatch, result); - } - - // no need for umbracoUseDirectoryUrls test = should be handled by UriUtilityTests - - // test hideTopLevelNodeFromPath true - [TestCase(1046, "/")] - [TestCase(1173, "/sub1/")] - [TestCase(1174, "/sub1/sub2/")] - [TestCase(1176, "/sub1/sub-3/")] - [TestCase(1177, "/sub1/custom-sub-1/")] - [TestCase(1178, "/sub1/custom-sub-2/")] - [TestCase(1175, "/sub-2/")] - [TestCase(1172, "/test-page/")] // not hidden because not first root - public void Get_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch) - { - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(true).Build(); - - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); - var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); - var urlProvider = new DefaultUrlProvider( - Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), - Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -173,9 +125,7 @@ namespace Umbraco.Tests.Routing { const string currentUri = "http://example.us/test"; - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Culture); var publishedContent = new SolidPublishedContent(contentType) { Id = 1234 }; @@ -197,13 +147,13 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), + globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -221,9 +171,7 @@ namespace Umbraco.Tests.Routing { const string currentUri = "http://example.fr/test"; - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Culture); var publishedContent = new SolidPublishedContent(contentType) { Id = 1234 }; @@ -254,13 +202,13 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), + globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -278,9 +226,7 @@ namespace Umbraco.Tests.Routing { const string currentUri = "http://example.us/test"; - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Culture); var publishedContent = new SolidPublishedContent(contentType) { Id = 1234 }; @@ -311,13 +257,13 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), + globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings), snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); @@ -331,16 +277,14 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Relative_Or_Absolute() { - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), umbracoContextAccessor, UriUtility); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); @@ -353,15 +297,13 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Unpublished() { - var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), UmbracoContextAccessor, UriUtility); - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); //mock the Umbraco settings that we need diff --git a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs index 0998f1e722..3e7fb611df 100644 --- a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Routing [TestCase(10011, "https://domain1.com", false, "/1001-1/")] public void Get_Url_SimpleDomain(int nodeId, string currentUrl, bool absolute, string expected) { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); @@ -213,7 +213,7 @@ namespace Umbraco.Tests.Routing [TestCase(10011, "https://domain1.com", false, "http://domain1.com/foo/1001-1/")] public void Get_Url_SimpleWithSchemeAndPath(int nodeId, string currentUrl, bool absolute, string expected) { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); @@ -239,7 +239,7 @@ namespace Umbraco.Tests.Routing [TestCase(1002, "http://domain1.com", false, "/1002/")] public void Get_Url_DeepDomain(int nodeId, string currentUrl, bool absolute, string expected) { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); @@ -272,7 +272,7 @@ namespace Umbraco.Tests.Routing [TestCase(100321, "http://domain3.com", false, "/fr/1003-2-1/")] public void Get_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected) { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); @@ -296,7 +296,7 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_DomainsAndCache() { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); @@ -362,7 +362,7 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Relative_Or_Absolute() { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); @@ -389,7 +389,7 @@ namespace Umbraco.Tests.Routing [Test] public void Get_Url_Alternate() { - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index 6e00b7a7f0..fdd891bda6 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Routing public void DoNotPolluteCache() { var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); SetDomains1(); diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 2773eef4ab..4b4dfeec48 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -38,6 +38,7 @@ using Umbraco.Tests.Common; using Umbraco.Tests.Common.Composing; using Umbraco.Core.Media; using Umbraco.Tests.Common.Builders; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.Runtimes { @@ -118,6 +119,23 @@ namespace Umbraco.Tests.Runtimes composition.RegisterUnique(); composition.RegisterUnique(_ => new MediaUrlProviderCollection(Enumerable.Empty())); + // TODO: found these registration were necessary here as dependencies for ComponentCollection + // are not resolved. Need to check this if these explicit registrations are the best way to handle this. + var contentSettings = new ContentSettingsBuilder().Build(); + var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var userPasswordConfigurationSettings = new UserPasswordConfigurationSettingsBuilder().Build(); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + + composition.Register(x => Options.Create(globalSettings)); + composition.Register(x => Options.Create(contentSettings)); + composition.Register(x => Options.Create(coreDebugSettings)); + composition.Register(x => Options.Create(nuCacheSettings)); + composition.Register(x => Options.Create(requestHandlerSettings)); + composition.Register(x => Options.Create(userPasswordConfigurationSettings)); + composition.Register(x => Options.Create(webRoutingSettings)); + // initialize some components only/individually composition.WithCollectionBuilder() .Clear() diff --git a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs index 28d7d90f7e..12f5022b55 100644 --- a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs +++ b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs @@ -3,15 +3,12 @@ using System.Diagnostics; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Strings; using Umbraco.Tests.Common.Builders; -using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Strings @@ -19,7 +16,6 @@ namespace Umbraco.Tests.Strings [TestFixture] public class DefaultShortStringHelperTests : UmbracoTestBase { - private RequestHandlerSettings _requestHandlerSettings; private DefaultShortStringHelper _helper; public override void SetUp() @@ -28,8 +24,8 @@ namespace Umbraco.Tests.Strings // NOTE pre-filters runs _before_ Recode takes place // so there still may be utf8 chars even though you want ascii - _requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); - _helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + _helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.FileName, new DefaultShortStringHelperConfig.Config { //PreFilter = ClearFileChars, // done in IsTerm @@ -148,7 +144,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringUnderscoreInTerm() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // underscore is accepted within terms @@ -158,7 +155,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo_bar*nil", helper.CleanString("foo_bar nil", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // underscore is not accepted within terms @@ -172,7 +169,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringLeadingChars() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // letters and digits are valid leading chars @@ -182,7 +180,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("0123foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { // only letters are valid leading chars @@ -193,14 +191,15 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias)); Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123 foo_bar 543 nil 321", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings)); + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings)); Assert.AreEqual("child2", helper.CleanStringForSafeAlias("1child2")); } [Test] public void CleanStringTermOnUpper() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -210,7 +209,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo*Bar", helper.CleanString("fooBar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -224,7 +223,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringAcronymOnNonUpper() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -237,7 +237,7 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("foo*BAnil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -254,7 +254,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringGreedyAcronyms() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -267,7 +268,7 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("foo*BA*nil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -284,7 +285,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringWhiteSpace() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -297,7 +299,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringSeparator() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -305,7 +308,7 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo*bar", helper.CleanString("foo bar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -313,14 +316,14 @@ namespace Umbraco.Tests.Strings })); Assert.AreEqual("foo bar", helper.CleanString("foo bar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged })); Assert.AreEqual("foobar", helper.CleanString("foo bar", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -332,7 +335,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringSymbols() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -386,7 +390,9 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringEncoding() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, @@ -395,7 +401,7 @@ namespace Umbraco.Tests.Strings Assert.AreEqual("中文测试", helper.CleanString("中文测试", CleanStringType.Alias)); Assert.AreEqual("léger*中文测试*ZÔRG", helper.CleanString("léger 中文测试 ZÔRG", CleanStringType.Alias)); - helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Ascii | CleanStringType.Unchanged, @@ -408,12 +414,12 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringDefaultConfig() { - var settings = _requestHandlerSettings; - var contentMock = Mock.Get(settings); - contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); - contentMock.Setup(x => x.ConvertUrlsToAscii).Returns("false"); + var requestHandlerSettings = new RequestHandlerSettingsBuilder() + .WithCharCollection(Enumerable.Empty()) + .WithConvertUrlsToAscii("false") + .Build(); - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(settings)); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings)); const string input = "0123 中文测试 中文测试 léger ZÔRG (2) a?? *x"; @@ -434,7 +440,8 @@ namespace Umbraco.Tests.Strings [Test] public void CleanStringCasing() { - var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(_requestHandlerSettings) + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(requestHandlerSettings) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, diff --git a/src/Umbraco.Tests/TEMP/DatabaseContextTests.sdf b/src/Umbraco.Tests/TEMP/DatabaseContextTests.sdf index d13671d77ac03808a75689089e57bfb8fcf82b8d..c21739c1249f0c8f447f8ff94d081f3b0448d5bb 100644 GIT binary patch delta 2869 zcmZuzdr(x@8Q;76eRuEPy_d((#Rn!JC=f9`8f(y!O4I^HYZox9@(@VXYK=&$CW>iT z1`|zHg06Tl6v4*U5{Qyga%`#&F&S-|wpr8Kis_8_M`l{-I4F{Uu}#lC_v{5S*%`RM z@Avy&d(L;xUB5re@6Uqco6`#p!K_&>#bz6@*=)f6F2zgizxfGgk9@n$Cfgh<$ju0; z;;pWgweZW%`3XJX&(|?yZjKb+l%XvTv>iNz3k{3($3aR@MMHZeR86lu6o7WG&fU6f zHva6XY;Q}0r>0+;+5^E|PW-mW;p@5fj}!@)8D`+b^=Umb`*%yY+%S7iTrc-P{+AFN zfT1EYB2YTC5uf1B9}KM$X!e~Ds=HH+-{I=Oof3hv?-t`C&b8ewHPPYW)q*M;F2QUr zo*yn0=o|M|3bf^(PoO{C3;89F6yahX;UDn{^vTE?T*|oxpRE+=@Mo*=yPUhtI1}Z5 zUM5h-=fwgkqm=?xjh15$kN9}BOrUvVA+C9>NN_`Ag#zW?FTgw=(Q2XL`^ES@&J})9 zB+wgQlnA6gD8_uQZhEjrpvw=QHc?ONe?N}*WUbKlMS$0KLktAp8tRFY2GczE?a#j( z#k5UqI*bqBC+hJU+Kj`IN28fmKUwojgW>Ra-1-6vjZ&5qR~XgV@c2jzk?OI;Flj=w zbPcf7l6aI zS&{WI+WZ5@#vo+XN6jM;2SNOap-^^=qa}gw&4dmxG25?v;(Z@_iTg4s1C7ZnS7kCYy6J`=+-TEsaQ|Xil zq~q_$74w^Cw@OY@dq@qZ(=+fiTC$HMJdVxyd?*k1KAMTtq>QC6r!fm~jf^{mPYgY> z2%o72`eE-03f;KEX-Q_|Z&IwsT~T#N3^kT?*U36*J1DnUA!e^l4RW(ZEvDOFl@DZlrbk~K*vw8#re>a&J-i`LP#%o+ zB)H!m+QPJ|$=Z-SxD^`a@3=;w!r5nKOrk>-PD#PNp+4#IP0ru?JnJtU4Xa^UAk3_= z&#chrWECDx(Qm!Lw3x}-fT7JF-v84VnU*$D>-8vuv5*#jD~ipe(vPo%ijmBj%6Zcy z1(LRbR>UhMi2H?Zu0V9M;Fj-k-5 zunXXTk<&b=O(&H|84r#Vu1=)}Fu)0xa|S(mMk%cZ?{C^}umNz{6+9w3@{!79mmiyi z$*XH*+9R$vCve8~K-l##)tu*%#v&WjC@KuX9)S1A{-wV?ouc|J?9q6n~P&pqlj+ zsz0daeuaAUin>^D6@mOoU$~;~N%g$(-D(V_^zs28s5#Ml8F*~ zNxBEqAf{|~IR&r#-+*nrc{VD=#<|tV>ZjbNOfqz%YP8tr4gj`?zUEr$Epd0BgijN1 zdz(N@#$OmpZ-y2lnUJz{OA%im4;YoT5eJ?$2%eU|F7w>l+3iqYo(k;N(UwT~E1@S5 zc9P?aeT|^6*J;&&rz|D(ZiyyUFKf-?LLlf>=)%3)X&HYloW*1;Y0%C~iMMk$p1KU# zw(mb|uGIVNC#94wbHjL1kMiO)u~ECe6*`t(tmy?k9qK7@-GV2db^BWBC(Hr`JCQoniF!w@6@|3ACcqHUHTLm RPluLbFIx&)T^rWu|39waNN)fD delta 2869 zcmZuzdr(wW7{7P-J9qEiy%*P^MG1|ECYTA>QyXR^Eg@1{QC9_&#me!8Qb{SAETf}6 z%uujH8G)147%0$2$4VO-O?ynWnoeRbtf`q=r;vw1QgrS;=UyK52kiI#e&6|h-+t#i z=WHO576_!lvcl#Kdtm%{2?U`{5Cr-moJtVse?f54zyAJy;X=G1NCGUxm)xSiseVBz zOy1u-Aqasi4J}CS5Tf=?QD;}wJhun=bPu=2!K9#nckM_xSN}_81=M;qBdlH!jL%>} zZA}Wie4uz+5JH`D&D+OFiHMTTg4M-I1YI`Wvcw{tOvmUfz9$2+q*c3sy3ZWVU< zxb<9QKlh3WQ zJ!af(y(U)GJD;=dz1iH#_-h`wsx7PYFH<@Dnz`c5Yq>m5>C550Ue&jRTc`V$Gb@<< z_t^wbRl~bayTL2`zy?AvwuX4(#BhoyKX2TLNXo6U8N*_7UY!esKfqCx+cuO7h~W{? z@Xp+B0_9?wgJse;9`DEEHk6|`hK#EcF96EbZG-Yvi`y+X3pZriRdV|);%Dxw~x1 zV8x`9jOn&_%i&D$y9f*+TggCZHmm1S$adLo#p{|1PC9RU-hvWwDAg{L@OfJc*JX(! zzOi*Y1aCdM*GC}Te!qy8^16&Ks*$?8?U8`;t!6~evTwKCL|jy=MdP9qFben1vhVy~ z;@gZND*|5vkn&7>NV1}DB~=gDSBBti^xF3r;vj_ldOkvrag@mIu6Q^E%%+=?g}o<1 zBfS%#??2$Yo1viscFw5pC(r_kc2qE^(+b{k0ybMv7NI&fDwdy)-}?eyvfM;Ms}10VTr&o&(T)IaYL9U;Ijv%z$>eIM8QI+MgKD{s%5eDh4&nGd{&=Sdt zi6NEK(b^&?Db9YKKqH##uqd{jhY8wdL5bMtqyH#+&yF56x-XGV{(=t_Mr)8y4 zkS8RCV?8}%r*#xkZrxC>T?(&r*g@TQP#!6vM+N|Aom>KFg8@*@G2~!_oL25Gx{RULnKmfUIP!GxqwxM(=TjEJFUGA0 zoFirQIM2*42qXHpL(V2fSS>J$aOz{NB+Qj?fvse>9tIqm*Wki;nN=`#y9xQYv>aMIT95I0d%; zlysJW*Yzu)%|`KbRC4rltK!8AU2ibZyirw><8xJ*k;X&h&2=>%gzn0pXYB(u32o6e zny08SA~Okq;^SiNE>8+#A6wy|F0p$}hJ;`zU zzPib)Woi)&V$8QC3a{ItRt*ppA+JpC+NmCqP$`$;lQDC*dR&}Pd1`g+X-F65+`u|@ zlK!L=QzgUEALIhjzdUR)1#uQ#n}1}y;%*D6C=4nhH*z=!W}XM(), Mock.Of(x => x.ApplicationPhysicalPath == ioHelper.MapPath("~"))), @@ -245,7 +246,8 @@ namespace Umbraco.Tests.TestHelpers public IScopeProvider GetScopeProvider(ILogger logger, ITypeFinder typeFinder = null, FileSystems fileSystems = null, IUmbracoDatabaseFactory databaseFactory = null) { var globalSettings = new GlobalSettingsBuilder().Build(); - var connectionStrings = new ConnectionStringsBuilder().Build(); + var connectionString = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName].ConnectionString; + var connectionStrings = new ConnectionStringsBuilder().WithUmbracoConnectionString(connectionString).Build(); var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); if (databaseFactory == null) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 193b4093f5..75c4bd773d 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -141,6 +141,8 @@ + + @@ -195,7 +197,7 @@ - + diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index 659062f4f9..f8bdd20f3e 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -578,7 +578,7 @@ namespace Umbraco.Web.BackOffice.Controllers } var dataInstaller = new PackageDataInstallation(_logger, _fileService, _macroService, _LocalizationService, - _dataTypeService, _entityService, _contentTypeService, _contentService, _propertyEditors, _scopeProvider, _shortStringHelper, _globalSettings, _localizedTextService); + _dataTypeService, _entityService, _contentTypeService, _contentService, _propertyEditors, _scopeProvider, _shortStringHelper, Options.Create(_globalSettings), _localizedTextService); var xd = new XmlDocument {XmlResolver = null}; xd.Load(filePath); From 25849703cc9de66bab5d55e967ac119d624cda89 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 26 Aug 2020 09:09:52 +0200 Subject: [PATCH 23/58] Fixed further failing tests. --- src/Umbraco.Tests/Scoping/ScopedXmlTests.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs index 852872fca0..72c6438324 100644 --- a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs @@ -5,19 +5,19 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Web.Composing; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Sync; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Web; using Umbraco.Web.Cache; +using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; namespace Umbraco.Tests.Scoping @@ -44,6 +44,15 @@ namespace Umbraco.Tests.Scoping protected override void ComposeSettings() { + var contentSettings = new ContentSettingsBuilder().Build(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var userPasswordConfigurationSettings = new UserPasswordConfigurationSettingsBuilder().Build(); + + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); + Composition.Register(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); + + // TODO: remove this once legacy config is fully extracted. Composition.Configs.Add(SettingsForTests.GenerateMockContentSettings); Composition.Configs.Add(SettingsForTests.GenerateMockGlobalSettings); } From 96104b9fdfa65f9afb8ffd64e2c1111583cfb795 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 26 Aug 2020 11:29:21 +0200 Subject: [PATCH 24/58] Fixed further failing tests. --- .../ConfigModelConversionsFromLegacy.cs | 31 +++++++--- .../ConfigModelConversionsToLegacy.cs | 30 ++++++++++ .../Builders/GlobalSettingsBuilder.cs | 4 +- .../Configurations/GlobalSettingsTests.cs | 2 - .../Migrations/AdvancedMigrationTests.cs | 1 - .../Migrations/MigrationPlanTests.cs | 2 - .../Routing/UmbracoModuleTests.cs | 5 +- .../BackOfficeOwinUserManagerTests.cs | 5 +- .../Configuration/ConfigModelConversions.cs | 56 ------------------- .../Security/BackOfficeOwinUserManager.cs | 9 ++- src/Umbraco.Web/Umbraco.Web.csproj | 1 - 11 files changed, 64 insertions(+), 82 deletions(-) delete mode 100644 src/Umbraco.Web/Configuration/ConfigModelConversions.cs diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index 529568ca16..6ce73a9f6c 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -28,15 +28,15 @@ namespace Umbraco.Infrastructure.Configuration ReservedUrls = globalSettings.ReservedUrls, Smtp = globalSettings.SmtpSettings != null ? new SmtpSettings - { - DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, - From = globalSettings.SmtpSettings.From, - Host = globalSettings.SmtpSettings.Host, - Password = globalSettings.SmtpSettings.Password, - PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, - Port = globalSettings.SmtpSettings.Port, - Username = globalSettings.SmtpSettings.Username, - } + { + DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, + From = globalSettings.SmtpSettings.From, + Host = globalSettings.SmtpSettings.Host, + Password = globalSettings.SmtpSettings.Password, + PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, + Port = globalSettings.SmtpSettings.Port, + Username = globalSettings.SmtpSettings.Username, + } : new SmtpSettings(), TimeOutInMinutes = globalSettings.TimeOutInMinutes, UmbracoCssPath = globalSettings.UmbracoCssPath, @@ -55,5 +55,18 @@ namespace Umbraco.Infrastructure.Configuration UmbracoConnectionString = connectionStrings[Constants.System.UmbracoConnectionName].ConnectionString }; } + + public static UserPasswordConfigurationSettings ConvertUserPasswordConfiguration(IUserPasswordConfiguration passwordConfiguration) + { + return new UserPasswordConfigurationSettings + { + HashAlgorithmType = passwordConfiguration.HashAlgorithmType, + RequireDigit = passwordConfiguration.RequireDigit, + RequiredLength = passwordConfiguration.RequiredLength, + RequireLowercase = passwordConfiguration.RequireLowercase, + RequireNonLetterOrDigit = passwordConfiguration.RequireNonLetterOrDigit, + RequireUppercase = passwordConfiguration.RequireUppercase, + }; + } } } diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs index 5b3607992c..5c2d8c090f 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs @@ -55,6 +55,19 @@ namespace Umbraco.Infrastructure.Configuration return result; } + public static IUserPasswordConfiguration ConvertUserPasswordConfiguration(UserPasswordConfigurationSettings passwordConfiguration) + { + return new TestUserPasswordConfiguration + { + HashAlgorithmType = passwordConfiguration.HashAlgorithmType, + RequireDigit = passwordConfiguration.RequireDigit, + RequiredLength = passwordConfiguration.RequiredLength, + RequireLowercase = passwordConfiguration.RequireLowercase, + RequireNonLetterOrDigit = passwordConfiguration.RequireNonLetterOrDigit, + RequireUppercase = passwordConfiguration.RequireUppercase, + }; + } + private class TestGlobalSettings : IGlobalSettings { public string ReservedUrls { get; set; } @@ -126,5 +139,22 @@ namespace Umbraco.Infrastructure.Configuration _dictionary.Add(key, new ConfigConnectionString(connectionString, string.Empty, key)); } } + + private class TestUserPasswordConfiguration : IUserPasswordConfiguration + { + public int RequiredLength { get; set; } + + public bool RequireNonLetterOrDigit { get; set; } + + public bool RequireDigit { get; set; } + + public bool RequireLowercase { get; set; } + + public bool RequireUppercase { get; set; } + + public string HashAlgorithmType { get; set; } + + public int MaxFailedAccessAttemptsBeforeLockout { get; set; } + } } } diff --git a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs index ab07331108..735495b8d7 100644 --- a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs @@ -162,8 +162,8 @@ namespace Umbraco.Tests.Common.Builders var installEmptyDatabase = _installEmptyDatabase ?? false; var installMissingDatabase = _installMissingDatabase ?? false; var registerType = _registerType ?? null; - var reservedPaths = _reservedPaths ?? "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; - var reservedUrls = _reservedUrls ?? "~/config/splashes/noNodes.aspx,~/.well-known,"; + var reservedPaths = _reservedPaths ?? GlobalSettings.StaticReservedPaths; + var reservedUrls = _reservedUrls ?? GlobalSettings.StaticReservedUrls; var path = _path ?? "~/umbraco"; var useHttps = _useHttps ?? false; var umbracoCssPath = _umbracoCssPath ?? "~/css"; diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index cae2919621..69e20fe063 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -1,10 +1,8 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Configuration; -using Umbraco.Core.IO; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; -using Umbraco.Web.Configuration; using Umbraco.Web.Hosting; namespace Umbraco.Tests.Configurations diff --git a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs index dd5fd32971..bba2649af3 100644 --- a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs @@ -12,7 +12,6 @@ using Umbraco.Core.Services; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; -using Umbraco.Web.Configuration; namespace Umbraco.Tests.Migrations { diff --git a/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs b/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs index 273255f987..6fc06d0618 100644 --- a/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs +++ b/src/Umbraco.Tests/Migrations/MigrationPlanTests.cs @@ -9,14 +9,12 @@ using Umbraco.Core.Logging; using Umbraco.Core.Migrations; using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Persistence; -using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Scoping; using Umbraco.Core.Services; using Umbraco.Persistance.SqlCe; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; -using Umbraco.Web.Configuration; namespace Umbraco.Tests.Migrations { diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 87d63f3d8f..bc2511fe41 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -3,6 +3,7 @@ using System.Threading; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common.Builders; @@ -24,7 +25,9 @@ namespace Umbraco.Tests.Routing // FIXME: be able to get the UmbracoModule from the container. any reason settings were from testobjects? //create the module var logger = Mock.Of(); - var globalSettings = new GlobalSettingsBuilder().Build(); + var globalSettings = new GlobalSettingsBuilder() + .WithReservedPaths((GlobalSettings.StaticReservedPaths + "~/umbraco")) + .Build(); var runtime = new RuntimeState(globalSettings, UmbracoVersion); _module = new UmbracoInjectedModule diff --git a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs index b6a8c225e0..ca38f0ce70 100644 --- a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs @@ -10,8 +10,8 @@ using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Core.Models.Membership; +using Umbraco.Infrastructure.Configuration; using Umbraco.Net; -using Umbraco.Tests.Common.Builders; using Umbraco.Web.Security; namespace Umbraco.Tests.Security @@ -45,8 +45,7 @@ namespace Umbraco.Tests.Security var mockGlobalSettings = new Mock(); mockGlobalSettings.Setup(x => x.DefaultUILanguage).Returns("test"); - var globalSettings = new GlobalSettingsBuilder().Build(); - var user = new BackOfficeIdentityUser(globalSettings, 2, new List()) + var user = new BackOfficeIdentityUser(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(mockGlobalSettings.Object), 2, new List()) { UserName = "alice", Name = "Alice", diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs deleted file mode 100644 index f3b74734b4..0000000000 --- a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Options; -using Umbraco.Core; -using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; - -namespace Umbraco.Web.Configuration -{ - /// - /// TEMPORARY: this class has been added just to ensure Umbraco.Web functionality continues to compile, by - /// converting between e.g. (used by - /// legacy configuration and (used by Netcore/IOptions configuration). - /// - public static class ConfigModelConversions - { - public static IOptions ConvertToOptionsOfUserPasswordConfigurationSettings(IOptions identityOptions) - { - var passwordOptions = identityOptions.Value.Password; - var lockOutOptions = identityOptions.Value.Lockout; - var passwordConfiguration = new UserPasswordConfigurationSettings - { - MaxFailedAccessAttemptsBeforeLockout = lockOutOptions.MaxFailedAccessAttempts, - HashAlgorithmType = Constants.Security.AspNetCoreV3PasswordHashAlgorithmName, // TODO: not sure where to map this from. - RequireDigit = passwordOptions.RequireDigit, - RequiredLength = passwordOptions.RequiredLength, - RequireLowercase = passwordOptions.RequireLowercase, - RequireNonLetterOrDigit = passwordOptions.RequireNonAlphanumeric, - RequireUppercase = passwordOptions.RequireUppercase, - }; - - return Options.Create(passwordConfiguration); - } - - public static IOptions ConvertToOptionsOfBackOfficeIdentityOptions(IUserPasswordConfiguration passwordConfiguration) - { - var identityOptions = new BackOfficeIdentityOptions - { - Lockout = new LockoutOptions - { - MaxFailedAccessAttempts = passwordConfiguration.MaxFailedAccessAttemptsBeforeLockout, - }, - Password = new PasswordOptions - { - RequireDigit = passwordConfiguration.RequireDigit, - RequiredLength = passwordConfiguration.RequiredLength, - RequireLowercase = passwordConfiguration.RequireLowercase, - RequireNonAlphanumeric = passwordConfiguration.RequireNonLetterOrDigit, - RequireUppercase = passwordConfiguration.RequireUppercase, - } - }; - - return Options.Create(identityOptions); - } - } -} diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index d11edc7bba..13dd242d26 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -13,7 +13,6 @@ using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Infrastructure.Configuration; using Umbraco.Net; -using Umbraco.Web.Configuration; namespace Umbraco.Web.Security { @@ -22,7 +21,7 @@ namespace Umbraco.Web.Security public const string OwinMarkerKey = "Umbraco.Web.Security.Identity.BackOfficeUserManagerMarker"; public BackOfficeOwinUserManager( - IOptions passwordConfiguration, + IUserPasswordConfiguration passwordConfiguration, IIpResolver ipResolver, IUserStore store, IOptions optionsAccessor, @@ -32,9 +31,9 @@ namespace Umbraco.Web.Security BackOfficeIdentityErrorDescriber errors, IDataProtectionProvider dataProtectionProvider, ILogger> logger) - : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, ConfigModelConversions.ConvertToOptionsOfUserPasswordConfigurationSettings(passwordConfiguration)) + : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, Microsoft.Extensions.Options.Options.Create(ConfigModelConversionsFromLegacy.ConvertUserPasswordConfiguration(passwordConfiguration))) { - PasswordConfiguration = ConfigModelConversions.ConvertToOptionsOfUserPasswordConfigurationSettings(passwordConfiguration).Value; + PasswordConfiguration = passwordConfiguration; InitUserManager(this, dataProtectionProvider); } @@ -105,7 +104,7 @@ namespace Umbraco.Web.Security options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(30); return new BackOfficeOwinUserManager( - ConfigModelConversions.ConvertToOptionsOfBackOfficeIdentityOptions(passwordConfiguration), + passwordConfiguration, ipResolver, customUserStore, new OptionsWrapper(options), diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 82af69a21c..64fc7b5886 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -148,7 +148,6 @@ - From 64f875258793ec941b6f0b2a56df40e184a459b9 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 26 Aug 2020 11:58:44 +0200 Subject: [PATCH 25/58] Removed introduced second constructors for IOptions based depenedencies and used Options.Create instead. --- src/Umbraco.Core/Routing/PublishedRequest.cs | 13 +--------- src/Umbraco.Core/Routing/PublishedRouter.cs | 2 +- src/Umbraco.Core/Scheduling/KeepAlive.cs | 8 +----- .../BackOffice/BackOfficeUserStore.cs | 7 +---- .../EmailNotificationMethod.cs | 2 +- .../Media/UploadAutoFillProperties.cs | 10 +------ .../Repositories/Implement/UserRepository.cs | 26 ++----------------- .../FileUploadPropertyEditor.cs | 18 +++---------- .../FileUploadPropertyValueEditor.cs | 14 +--------- .../ImageCropperPropertyEditor.cs | 20 ++------------ .../UploadFileTypeValidator.cs | 9 ++----- .../Scheduling/LogScrubber.cs | 8 +----- .../Scheduling/SchedulerComponent.cs | 4 +-- .../Scoping/ScopeProvider.cs | 7 +---- .../Services/Implement/NotificationService.cs | 10 ++----- .../Users/EmailSender.cs | 11 +------- .../ContentCache.cs | 7 +---- .../PublishedSnapshotService.cs | 2 +- .../Repositories/UserRepositoryTest.cs | 4 +-- .../Components/ComponentTests.cs | 2 +- src/Umbraco.Tests/Models/MediaXmlTest.cs | 2 +- .../Repositories/UserRepositoryTest.cs | 2 +- .../Security/BackOfficeOwinUserManager.cs | 2 +- 23 files changed, 31 insertions(+), 159 deletions(-) diff --git a/src/Umbraco.Core/Routing/PublishedRequest.cs b/src/Umbraco.Core/Routing/PublishedRequest.cs index d1bf6fda0f..3e13270fa0 100644 --- a/src/Umbraco.Core/Routing/PublishedRequest.cs +++ b/src/Umbraco.Core/Routing/PublishedRequest.cs @@ -36,21 +36,10 @@ namespace Umbraco.Web.Routing /// The Umbraco context. /// The request Uri. public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IOptions webRoutingSettings, Uri uri = null) - : this(publishedRouter, umbracoContext, webRoutingSettings.Value, uri) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The published router. - /// The Umbraco context. - /// The request Uri. - public PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, WebRoutingSettings webRoutingSettings, Uri uri = null) { UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; Uri = uri ?? umbracoContext.CleanedUmbracoUrl; } diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs index 207e8d7ed4..6de64800c3 100644 --- a/src/Umbraco.Core/Routing/PublishedRouter.cs +++ b/src/Umbraco.Core/Routing/PublishedRouter.cs @@ -69,7 +69,7 @@ namespace Umbraco.Web.Routing /// public IPublishedRequest CreateRequest(IUmbracoContext umbracoContext, Uri uri = null) { - return new PublishedRequest(this, umbracoContext, _webRoutingSettings, uri ?? umbracoContext.CleanedUmbracoUrl); + return new PublishedRequest(this, umbracoContext, Options.Create(_webRoutingSettings), uri ?? umbracoContext.CleanedUmbracoUrl); } #region Request diff --git a/src/Umbraco.Core/Scheduling/KeepAlive.cs b/src/Umbraco.Core/Scheduling/KeepAlive.cs index dec9d9daad..98c6268e69 100644 --- a/src/Umbraco.Core/Scheduling/KeepAlive.cs +++ b/src/Umbraco.Core/Scheduling/KeepAlive.cs @@ -21,17 +21,11 @@ namespace Umbraco.Web.Scheduling public KeepAlive(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, IRequestAccessor requestAccessor, IMainDom mainDom, IOptions keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) - : this(runner, delayMilliseconds, periodMilliseconds, requestAccessor, mainDom, keepAliveSettings.Value, logger, serverRegistrar) - { - } - - public KeepAlive(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IRequestAccessor requestAccessor, IMainDom mainDom, KeepAliveSettings keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar) : base(runner, delayMilliseconds, periodMilliseconds) { _requestAccessor = requestAccessor; _mainDom = mainDom; - _keepAliveSettings = keepAliveSettings; + _keepAliveSettings = keepAliveSettings.Value; _logger = logger; _serverRegistrar = serverRegistrar; if (_httpClient == null) diff --git a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs index 0c5f5fd6ab..d14a951877 100644 --- a/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/BackOffice/BackOfficeUserStore.cs @@ -39,16 +39,11 @@ namespace Umbraco.Core.BackOffice private bool _disposed = false; public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, IOptions globalSettings, UmbracoMapper mapper) - : this(userService, entityService, externalLoginService, globalSettings.Value, mapper) - { - } - - public BackOfficeUserStore(IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, GlobalSettings globalSettings, UmbracoMapper mapper) { _userService = userService; _entityService = entityService; _externalLoginService = externalLoginService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; if (userService == null) throw new ArgumentNullException("userService"); if (externalLoginService == null) throw new ArgumentNullException("externalLoginService"); _mapper = mapper; diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index 19d63d7d6a..49981b0b9a 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -70,7 +70,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods var subject = _textService.Localize("healthcheck/scheduledHealthCheckEmailSubject", new[] { host.ToString() }); - var mailSender = new EmailSender(_globalSettings); + var mailSender = new EmailSender(Options.Create(_globalSettings)); using (var mailMessage = CreateMailMessage(subject, message)) { await mailSender.SendAsync(mailMessage); diff --git a/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs b/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs index 3f8c1c217f..762e418441 100644 --- a/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs +++ b/src/Umbraco.Infrastructure/Media/UploadAutoFillProperties.cs @@ -25,18 +25,10 @@ namespace Umbraco.Web.Media IMediaFileSystem mediaFileSystem, ILogger logger, IOptions contentSettings) - : this(mediaFileSystem, logger, contentSettings.Value) - { - } - - public UploadAutoFillProperties( - IMediaFileSystem mediaFileSystem, - ILogger logger, - ContentSettings contentSettings) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); } /// diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs index 83bc3730b8..72c7ea8b33 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs @@ -50,33 +50,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement IOptions globalSettings, IOptions passwordConfiguration, IJsonSerializer jsonSerializer) - : this(scopeAccessor, appCaches, logger, mapperCollection, globalSettings.Value, passwordConfiguration.Value, jsonSerializer) - { - } - - /// - /// Constructor - /// - /// - /// - /// - /// - /// A dictionary specifying the configuration for user passwords. If this is null then no password configuration will be persisted or read. - /// - /// - public UserRepository( - IScopeAccessor scopeAccessor, - AppCaches appCaches, - ILogger logger, - IMapperCollection mapperCollection, - GlobalSettings globalSettings, - UserPasswordConfigurationSettings passwordConfiguration, - IJsonSerializer jsonSerializer) : base(scopeAccessor, appCaches, logger) { _mapperCollection = mapperCollection ?? throw new ArgumentNullException(nameof(mapperCollection)); - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); - _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); + _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); + _passwordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _jsonSerializer = jsonSerializer; } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs index 1297a0ba2d..d4c5130b21 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs @@ -38,22 +38,10 @@ namespace Umbraco.Web.PropertyEditors ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper) - : this(logger, mediaFileSystem, contentSettings.Value, dataTypeService, localizationService, localizedTextService, shortStringHelper) - { - } - - public FileUploadPropertyEditor( - ILogger logger, - IMediaFileSystem mediaFileSystem, - ContentSettings contentSettings, - IDataTypeService dataTypeService, - ILocalizationService localizationService, - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper) : base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); - _contentSettings = contentSettings; + _contentSettings = contentSettings.Value; _dataTypeService = dataTypeService; _localizationService = localizationService; _localizedTextService = localizedTextService; @@ -66,8 +54,8 @@ namespace Umbraco.Web.PropertyEditors /// The corresponding property value editor. protected override IDataValueEditor CreateValueEditor() { - var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem, _dataTypeService, _localizationService, _localizedTextService, ShortStringHelper, _contentSettings); - editor.Validators.Add(new UploadFileTypeValidator(_localizedTextService, _contentSettings)); + var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem, _dataTypeService, _localizationService, _localizedTextService, ShortStringHelper, Options.Create(_contentSettings)); + editor.Validators.Add(new UploadFileTypeValidator(_localizedTextService, Options.Create(_contentSettings))); return editor; } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs index 7425051480..db675e2e42 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -27,22 +27,10 @@ namespace Umbraco.Web.PropertyEditors ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IOptions contentSettings) - : this(attribute, mediaFileSystem, dataTypeService, localizationService, localizedTextService, shortStringHelper, contentSettings.Value) - { - } - - public FileUploadPropertyValueEditor( - DataEditorAttribute attribute, - IMediaFileSystem mediaFileSystem, - IDataTypeService dataTypeService, - ILocalizationService localizationService, - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper, - ContentSettings contentSettings) : base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); } /// diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs index 2b1efb6d2b..0fea46f2d3 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs @@ -49,32 +49,16 @@ namespace Umbraco.Web.PropertyEditors IIOHelper ioHelper, IShortStringHelper shortStringHelper, ILocalizedTextService localizedTextService) - : this(logger, mediaFileSystem, contentSettings.Value, dataTypeService, localizationService, ioHelper, shortStringHelper, localizedTextService) - { - } - - /// - /// Initializes a new instance of the class. - /// - public ImageCropperPropertyEditor( - ILogger logger, - IMediaFileSystem mediaFileSystem, - ContentSettings contentSettings, - IDataTypeService dataTypeService, - ILocalizationService localizationService, - IIOHelper ioHelper, - IShortStringHelper shortStringHelper, - ILocalizedTextService localizedTextService) : base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _dataTypeService = dataTypeService; _localizationService = localizationService; _ioHelper = ioHelper; // TODO: inject? - _autoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, _contentSettings); + _autoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, contentSettings); } public bool TryGetMediaPath(string alias, object value, out string mediaPath) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs index 72391c99c0..d3e1e7aabe 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/UploadFileTypeValidator.cs @@ -17,15 +17,10 @@ namespace Umbraco.Web.PropertyEditors private readonly ILocalizedTextService _localizedTextService; private readonly ContentSettings _contentSettings; - public UploadFileTypeValidator(ILocalizedTextService localizedTextService, ContentSettings contentSettings) + public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IOptions contentSettings) { _localizedTextService = localizedTextService; - _contentSettings = contentSettings; - } - - public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IOptions contentSettings) - : this(localizedTextService, contentSettings.Value) - { + _contentSettings = contentSettings.Value; } public IEnumerable Validate(object value, string valueType, object dataTypeConfiguration) diff --git a/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs b/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs index 2aff2ce5ab..51c62de581 100644 --- a/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs +++ b/src/Umbraco.Infrastructure/Scheduling/LogScrubber.cs @@ -21,18 +21,12 @@ namespace Umbraco.Web.Scheduling public LogScrubber(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, IOptions settings, IScopeProvider scopeProvider, IProfilingLogger logger) - : this(runner, delayMilliseconds, periodMilliseconds, mainDom, serverRegistrar, auditService, settings.Value, scopeProvider, logger) - { - } - - public LogScrubber(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IMainDom mainDom, IServerRegistrar serverRegistrar, IAuditService auditService, LoggingSettings settings, IScopeProvider scopeProvider, IProfilingLogger logger) : base(runner, delayMilliseconds, periodMilliseconds) { _mainDom = mainDom; _serverRegistrar = serverRegistrar; _auditService = auditService; - _settings = settings; + _settings = settings.Value; _scopeProvider = scopeProvider; _logger = logger; } diff --git a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs index cfa9ced735..8aabaf0b57 100644 --- a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs @@ -141,7 +141,7 @@ namespace Umbraco.Web.Scheduling { // ping/keepalive // on all servers - var task = new KeepAlive(_keepAliveRunner, DefaultDelayMilliseconds, FiveMinuteMilliseconds, _requestAccessor, _mainDom, keepAliveSettings, _logger, _serverRegistrar); + var task = new KeepAlive(_keepAliveRunner, DefaultDelayMilliseconds, FiveMinuteMilliseconds, _requestAccessor, _mainDom, Options.Create(keepAliveSettings), _logger, _serverRegistrar); _keepAliveRunner.TryAdd(task); return task; } @@ -185,7 +185,7 @@ namespace Umbraco.Web.Scheduling { // log scrubbing // install on all, will only run on non-replica servers - var task = new LogScrubber(_scrubberRunner, DefaultDelayMilliseconds, LogScrubber.GetLogScrubbingInterval(), _mainDom, _serverRegistrar, _auditService, settings, _scopeProvider, _logger); + var task = new LogScrubber(_scrubberRunner, DefaultDelayMilliseconds, LogScrubber.GetLogScrubbingInterval(), _mainDom, _serverRegistrar, _auditService, Options.Create(settings), _scopeProvider, _logger); _scrubberRunner.TryAdd(task); return task; } diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index 947d427995..a2f626909b 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -29,15 +29,10 @@ namespace Umbraco.Core.Scoping private readonly IMediaFileSystem _mediaFileSystem; public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptions coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) - :this(databaseFactory, fileSystems, coreDebugSettings.Value, mediaFileSystem, logger, typeFinder, requestCache) - { - } - - public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ITypeFinder typeFinder, IRequestCache requestCache) { DatabaseFactory = databaseFactory; _fileSystems = fileSystems; - _coreDebugSettings = coreDebugSettings; + _coreDebugSettings = coreDebugSettings.Value; _mediaFileSystem = mediaFileSystem; _logger = logger; _typeFinder = typeFinder; diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 9b0045da7b..6058427aae 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -33,16 +33,10 @@ namespace Umbraco.Core.Services.Implement public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IOptions globalSettings, IOptions contentSettings, IEmailSender emailSender) - : this(provider, userService, contentService, localizationService, logger, ioHelper, notificationsRepository, globalSettings.Value, contentSettings.Value, emailSender) - { - } - - public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, - ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, GlobalSettings globalSettings, ContentSettings contentSettings, IEmailSender emailSender) { _notificationsRepository = notificationsRepository; - _globalSettings = globalSettings; - _contentSettings = contentSettings; + _globalSettings = globalSettings.Value; + _contentSettings = contentSettings.Value; _emailSender = emailSender; _uowProvider = provider ?? throw new ArgumentNullException(nameof(provider)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); diff --git a/src/Umbraco.Infrastructure/Users/EmailSender.cs b/src/Umbraco.Infrastructure/Users/EmailSender.cs index d563a0c36f..c45a9af0d3 100644 --- a/src/Umbraco.Infrastructure/Users/EmailSender.cs +++ b/src/Umbraco.Infrastructure/Users/EmailSender.cs @@ -27,17 +27,8 @@ namespace Umbraco.Core } public EmailSender(IOptions globalSettings, bool enableEvents) - : this(globalSettings.Value, enableEvents) { - } - - public EmailSender(GlobalSettings globalSettings) : this(globalSettings, false) - { - } - - public EmailSender(GlobalSettings globalSettings, bool enableEvents) - { - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _enableEvents = enableEvents; _smtpConfigured = new Lazy(() => _globalSettings.IsSmtpServerConfigured); diff --git a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs index f18018d9f0..1bdb3711d1 100644 --- a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs +++ b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs @@ -32,18 +32,13 @@ namespace Umbraco.Web.PublishedCache.NuCache // but, no, UmbracoContext returns snapshot.Content which comes from elements SO a resync should create a new cache public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IOptions globalSettings, IVariationContextAccessor variationContextAccessor) - : this(previewDefault, snapshot, snapshotCache, elementsCache, domainCache, globalSettings.Value, variationContextAccessor) - { - } - - public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, GlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor) : base(previewDefault) { _snapshot = snapshot; _snapshotCache = snapshotCache; _elementsCache = elementsCache; _domainCache = domainCache; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _variationContextAccessor = variationContextAccessor; } diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index fabcb0c759..adadef337f 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -1239,7 +1239,7 @@ namespace Umbraco.Web.PublishedCache.NuCache return new PublishedSnapshot.PublishedSnapshotElements { - ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainCache, _globalSettings, VariationContextAccessor), + ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainCache, Options.Create(_globalSettings), VariationContextAccessor), MediaCache = new MediaCache(previewDefault, mediaSnap, VariationContextAccessor), MemberCache = new MemberCache(previewDefault, snapshotCache, _serviceContext.MemberService, memberTypeCache, PublishedSnapshotAccessor, VariationContextAccessor, _entitySerializer, _publishedModelFactory), DomainCache = domainCache, diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs index cf8f091dbc..df5e58e82a 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Persistence.Repositories private UserRepository CreateRepository(IScopeProvider provider) { var accessor = (IScopeAccessor) provider; - var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); + var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, Options.Create(GlobalSettings), Options.Create(new UserPasswordConfigurationSettings()), new JsonNetSerializer()); return repository; } @@ -119,7 +119,7 @@ namespace Umbraco.Tests.Persistence.Repositories var id = user.Id; - var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(), GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); + var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(), Options.Create(GlobalSettings), Options.Create(new UserPasswordConfigurationSettings()), new JsonNetSerializer()); repository2.Delete(user); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 4ce790db6c..aef126729c 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Components var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, Options.Create(globalSettings), TestHelper.GetHostingEnvironment()); var coreDebug = new CoreDebugSettingsBuilder().Build(); var mediaFileSystem = Mock.Of(); - var p = new ScopeProvider(f, fs, coreDebug, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); + var p = new ScopeProvider(f, fs, Microsoft.Extensions.Options.Options.Create(coreDebug), mediaFileSystem, logger, typeFinder, NoAppCache.Instance); mock.Setup(x => x.GetInstance(typeof (ILogger))).Returns(logger); mock.Setup(x => x.GetInstance(typeof (IProfilingLogger))).Returns(new ProfilingLogger(Mock.Of(), Mock.Of())); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index b40e56c252..593a581f85 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Models var contentSettings = new ContentSettingsBuilder().Build(); var mediaFileSystem = new MediaFileSystem(Mock.Of(), scheme, logger, ShortStringHelper); - var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, contentSettings, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper); + var ignored = new FileUploadPropertyEditor(Mock.Of(), mediaFileSystem, Microsoft.Extensions.Options.Options.Create(contentSettings), DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper); var media = MockedMedia.CreateMediaImage(mediaType, -1); media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs index e49d6854d2..ddb8794e90 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs @@ -73,7 +73,7 @@ namespace Umbraco.Tests.Persistence.Repositories { var accessor = (IScopeAccessor) provider; var globalSettings = new GlobalSettingsBuilder().Build(); - var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, globalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); + var repository = new UserRepository(accessor, AppCaches.Disabled, Logger, Mappers, Microsoft.Extensions.Options.Options.Create(globalSettings), Microsoft.Extensions.Options.Options.Create(new UserPasswordConfigurationSettings()), new JsonNetSerializer()); return repository; } diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index 13dd242d26..51b5947a99 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -54,7 +54,7 @@ namespace Umbraco.Web.Security IDataProtectionProvider dataProtectionProvider, ILogger> logger) { - var store = new BackOfficeUserStore(userService, entityService, externalLoginService, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings), mapper); + var store = new BackOfficeUserStore(userService, entityService, externalLoginService, Microsoft.Extensions.Options.Options.Create(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)), mapper); return Create( passwordConfiguration, From c0134b0b743dbbf64d3817bcb8164777b500c38b Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 26 Aug 2020 12:30:20 +0200 Subject: [PATCH 26/58] Added files missing from previous commit. --- src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs | 4 ++-- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 3 ++- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs index 4545dc5a0e..b134934ee9 100644 --- a/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/MediaUrlProviderTests.cs @@ -39,8 +39,8 @@ namespace Umbraco.Tests.Routing var dataTypeService = Mock.Of(); var propertyEditors = new MediaUrlGeneratorCollection(new IMediaUrlGenerator[] { - new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), - new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSettings, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), + new FileUploadPropertyEditor(logger, mediaFileSystemMock, Microsoft.Extensions.Options.Options.Create(contentSettings), dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper), + new ImageCropperPropertyEditor(logger, mediaFileSystemMock, Microsoft.Extensions.Options.Options.Create(contentSettings), dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService), }); _mediaUrlProvider = new DefaultMediaUrlProvider(propertyEditors, UriUtility); } diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 1675d75fc1..0eb96e753b 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -34,6 +34,7 @@ using Umbraco.Web.Hosting; using Umbraco.Web.Routing; using File = System.IO.File; using Umbraco.Tests.Common.Builders; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.TestHelpers { @@ -106,7 +107,7 @@ namespace Umbraco.Tests.TestHelpers public static IWebRoutingSettings WebRoutingSettings => _testHelperInternal.WebRoutingSettings; - public static IEmailSender EmailSender { get; } = new EmailSender(new GlobalSettingsBuilder().Build()); + public static IEmailSender EmailSender { get; } = new EmailSender(Options.Create(new GlobalSettingsBuilder().Build())); /// diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 531fb7923a..7014c75cf7 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -165,7 +165,7 @@ namespace Umbraco.Tests.TestHelpers var dataTypeService = GetLazyService(factory, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), ioHelper, localizedTextService.Value, localizationService.Value, TestHelper.ShortStringHelper)); var propertyValidationService = new Lazy(() => new PropertyValidationService(propertyEditorCollection, dataTypeService.Value, localizedTextService.Value)); var contentService = GetLazyService(factory, c => new ContentService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), propertyValidationService, TestHelper.ShortStringHelper)); - var notificationService = GetLazyService(factory, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, localizationService.Value, logger, ioHelper, GetRepo(c), globalSettings, contentSettings, TestHelper.EmailSender)); + var notificationService = GetLazyService(factory, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, localizationService.Value, logger, ioHelper, GetRepo(c), Options.Create(globalSettings), Options.Create(contentSettings), TestHelper.EmailSender)); var serverRegistrationService = GetLazyService(factory, c => new ServerRegistrationService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), TestHelper.GetHostingEnvironment())); var memberGroupService = GetLazyService(factory, c => new MemberGroupService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); var memberService = GetLazyService(factory, c => new MemberService(scopeProvider, logger, eventMessagesFactory, memberGroupService.Value, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c))); @@ -268,7 +268,7 @@ namespace Umbraco.Tests.TestHelpers fileSystems ??= new FileSystems(Current.Factory, logger, TestHelper.IOHelper, Options.Create(globalSettings), TestHelper.GetHostingEnvironment()); var coreDebug = TestHelper.CoreDebugSettings; var mediaFileSystem = Mock.Of(); - return new ScopeProvider(databaseFactory, fileSystems, coreDebugSettings, mediaFileSystem, logger, typeFinder, NoAppCache.Instance); + return new ScopeProvider(databaseFactory, fileSystems, Microsoft.Extensions.Options.Options.Create(coreDebugSettings), mediaFileSystem, logger, typeFinder, NoAppCache.Instance); } } From 4e222f103e54acfaf8927a382e2f60a8a13a9192 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 26 Aug 2020 18:21:09 +0200 Subject: [PATCH 27/58] Reintroduced legacy config into CoreRuntime to support remaining use of Current.Configs (e.g. in UserInvite) --- src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs | 10 ++++------ src/Umbraco.Tests.Integration/RuntimeTests.cs | 5 +++-- src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs | 4 ++-- src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 4 ++-- .../UmbracoCoreServiceCollectionExtensions.cs | 5 ++++- src/Umbraco.Web/UmbracoApplication.cs | 3 +-- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index 968c240d62..3d1f00ebb9 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -12,7 +12,6 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; -using Umbraco.Infrastructure.Configuration; namespace Umbraco.Core.Runtime { @@ -30,8 +29,10 @@ namespace Umbraco.Core.Runtime private readonly IRequestCache _requestCache; private readonly GlobalSettings _globalSettings; private readonly ConnectionStrings _connectionStrings; + private readonly Configs _configs; public CoreRuntime( + Configs configs, // TODO: remove this parameter with legacy configuraiton no longer needed in Umbraco.Web and Umbraco.Tests GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, @@ -46,6 +47,7 @@ namespace Umbraco.Core.Runtime ITypeFinder typeFinder, IRequestCache requestCache) { + _configs = configs; _globalSettings = globalSettings; _connectionStrings = connectionStrings; @@ -180,11 +182,7 @@ namespace Umbraco.Core.Runtime var typeLoader = new TypeLoader(TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(HostingEnvironment.LocalTempPath), ProfilingLogger); // create the composition - // TODO: remove the configs parameter once we no longer need to provide it for Umbraco.Web and Umbraco.Tests functionality. - var configs = new Configs(); - configs.Add(() => ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); - configs.Add(() => ConfigModelConversionsToLegacy.ConvertConnectionStrings(_connectionStrings)); - composition = new Composition(register, typeLoader, ProfilingLogger, _state, configs, IOHelper, appCaches); + composition = new Composition(register, typeLoader, ProfilingLogger, _state, _configs, IOHelper, appCaches); composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, MainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, UmbracoVersion, DbProviderFactoryCreator, HostingEnvironment, BackOfficeInfo); // register ourselves (TODO: Should we put this in RegisterEssentials?) diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index c51c991e26..2766f4b044 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -56,16 +56,17 @@ namespace Umbraco.Tests.Integration var testHelper = new TestHelper(); + var configs = testHelper.GetConfigs(); var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); // Create the core runtime - var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, testHelper.GetUmbracoVersion(), + var coreRuntime = new CoreRuntime(configs, globalSettings, connectionStrings, testHelper.GetUmbracoVersion(), testHelper.IOHelper, testHelper.Logger, testHelper.Profiler, testHelper.UmbracoBootPermissionChecker, testHelper.GetHostingEnvironment(), testHelper.GetBackOfficeInfo(), testHelper.DbProviderFactoryCreator, testHelper.MainDom, testHelper.GetTypeFinder(), NoAppCache.Instance); - // boot it! + // boot it! var factory = coreRuntime.Configure(umbracoContainer); Assert.IsTrue(coreRuntime.MainDom.IsMainDom); diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index dc6caa3ce0..668507b497 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -52,8 +52,8 @@ namespace Umbraco.Tests.Routing public class TestRuntime : CoreRuntime { - public TestRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - : base(globalSettings, connectionStrings, umbracoVersion, ioHelper, Mock.Of(), Mock.Of(), new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) + public TestRuntime(Configs configs, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + : base(configs, globalSettings, connectionStrings, umbracoVersion, ioHelper, Mock.Of(), Mock.Of(), new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) { } diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 369eaeeac5..67b3be0293 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -116,7 +116,7 @@ namespace Umbraco.Tests.Runtimes public class TestRuntime : CoreRuntime { public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - : base(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(configs.Global()), ConfigModelConversionsFromLegacy.ConvertConnectionStrings(configs.ConnectionStrings()), umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) + : base(configs, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(configs.Global()), ConfigModelConversionsFromLegacy.ConvertConnectionStrings(configs.ConnectionStrings()), umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), NoAppCache.Instance) { } diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 4b4dfeec48..965521be31 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -85,7 +85,7 @@ namespace Umbraco.Tests.Runtimes composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); // create the core runtime and have it compose itself - var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); + var coreRuntime = new CoreRuntime(configs, globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); // determine actual runtime level runtimeState.DetermineRuntimeLevel(databaseFactory, logger); @@ -296,7 +296,7 @@ namespace Umbraco.Tests.Runtimes // create the core runtime and have it compose itself var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); - var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); + var coreRuntime = new CoreRuntime(configs, globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, NoAppCache.Instance); // get the components // all of them? diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index d829f6a3f2..b514b4d918 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -241,7 +241,9 @@ namespace Umbraco.Extensions var umbracoVersion = new UmbracoVersion(globalSettings); var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); + var configs = serviceProvider.GetService(); var coreRuntime = GetCoreRuntime( + configs, globalSettings, connectionStrings, umbracoVersion, @@ -268,7 +270,7 @@ namespace Umbraco.Extensions } private static IRuntime GetCoreRuntime( - GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, Core.Logging.ILogger logger, + Configs configs, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, Core.Logging.ILogger logger, IProfiler profiler, Core.Hosting.IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, ITypeFinder typeFinder, IRequestCache requestCache, IDbProviderFactoryCreator dbProviderFactoryCreator) { @@ -283,6 +285,7 @@ namespace Umbraco.Extensions var mainDom = new MainDom(logger, mainDomLock); var coreRuntime = new CoreRuntime( + configs, globalSettings, connectionStrings, umbracoVersion, diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 843082e884..1ee5231ec7 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -19,7 +19,6 @@ namespace Umbraco.Web { protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { - var connectionStringConfig = configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; var dbProviderFactoryCreator = new UmbracoDbProviderFactoryCreator(); @@ -39,7 +38,7 @@ namespace Umbraco.Web var requestCache = new HttpRequestAppCache(() => HttpContext.Current != null ? HttpContext.Current.Items : null); var umbracoBootPermissionChecker = new AspNetUmbracoBootPermissionChecker(); - return new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, + return new CoreRuntime(configs, globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, GetTypeFinder(hostingEnvironment, logger, profiler), requestCache); } From e6ac534069bd9fdfe0ee3278d769ba7dc9e2d190 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 27 Aug 2020 09:27:11 +0200 Subject: [PATCH 28/58] Resolved post-merge issues. --- src/Umbraco.Core/Configuration/Models/GlobalSettings.cs | 2 ++ .../Configuration/ConfigModelConversionsFromLegacy.cs | 1 + .../Configuration/ConfigModelConversionsToLegacy.cs | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index ac659b6d05..e71d29412d 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -32,6 +32,8 @@ public string Path { get; set; } = "~/umbraco"; + public string IconsPath { get; set; } = $"~/umbraco/assets/icons"; + public string UmbracoCssPath { get; set; } = "~/css"; public string UmbracoScriptsPath { get; set; } = "~/scripts"; diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index 6ce73a9f6c..406e3a115f 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -43,6 +43,7 @@ namespace Umbraco.Infrastructure.Configuration UmbracoMediaPath = globalSettings.UmbracoMediaPath, Path = globalSettings.UmbracoPath, UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, + IconsPath = globalSettings.IconsPath, UseHttps = globalSettings.UseHttps, VersionCheckPeriod = globalSettings.VersionCheckPeriod, }; diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs index 5c2d8c090f..355326b082 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs @@ -43,6 +43,7 @@ namespace Umbraco.Infrastructure.Configuration UmbracoMediaPath = globalSettings.UmbracoMediaPath, UmbracoPath = globalSettings.Path, UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, + IconsPath = globalSettings.IconsPath, UseHttps = globalSettings.UseHttps, VersionCheckPeriod = globalSettings.VersionCheckPeriod, }; @@ -109,6 +110,10 @@ namespace Umbraco.Infrastructure.Configuration public string MainDomLock { get; set; } public string NoNodesViewPath { get; set; } + + public string IconsPath { get; set; } + + public string ConfigurationStatus { get; set; } } private class TestSmtpSettings : ISmtpSettings From f1bda37a64673623c5db4ed9cdab772e1626dedb Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 1 Sep 2020 18:10:12 +0200 Subject: [PATCH 29/58] Updates following PR review. --- .../Configuration/GlobalSettingsExtensions.cs | 6 +++--- .../Configuration/Models/GlobalSettings.cs | 2 +- .../Configuration/Models/ImagingCacheSettings.cs | 2 +- .../Permissions/FolderAndFilePermissionsCheck.cs | 2 +- src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs | 2 +- src/Umbraco.Core/Routing/UrlProvider.cs | 9 +++------ .../Composing/CompositionExtensions/Services.cs | 2 +- .../Configuration/ConfigModelConversionsFromLegacy.cs | 2 +- .../Configuration/ConfigModelConversionsToLegacy.cs | 2 +- .../Install/FilePermissionHelper.cs | 2 +- .../Persistence/UmbracoDatabaseFactory.cs | 5 +++-- src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs | 3 ++- .../Services/Implement/FileService.cs | 4 ++-- .../Services/Implement/NotificationService.cs | 4 ++-- .../WebAssets/BackOfficeJavaScriptInitializer.cs | 2 +- .../Builders/GlobalSettingsBuilder.cs | 10 +++++----- .../BackOfficeCookieManagerTests.cs | 8 ++++---- src/Umbraco.Tests/Components/ComponentTests.cs | 2 +- .../Configurations/GlobalSettingsTests.cs | 2 +- src/Umbraco.Tests/Persistence/DatabaseContextTests.cs | 3 ++- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 2 +- .../Controllers/BackOfficeAssetsController.cs | 2 +- .../Controllers/BackOfficeController.cs | 4 ++-- .../Controllers/PreviewController.cs | 2 +- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 2 +- src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs | 2 +- src/Umbraco.Web.Common/Install/InstallController.cs | 4 ++-- src/Umbraco.Web.Common/Security/WebSecurity.cs | 2 +- 29 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs index dc52c8dcd6..f9b2362e14 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Configuration public static string GetBackOfficePath(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { if (_backOfficePath != null) return _backOfficePath; - _backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.Path); + _backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); return _backOfficePath; } @@ -44,9 +44,9 @@ namespace Umbraco.Core.Configuration internal static string GetUmbracoMvcAreaNoCache(this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - var path = string.IsNullOrEmpty(globalSettings.Path) + var path = string.IsNullOrEmpty(globalSettings.UmbracoPath) ? string.Empty - : hostingEnvironment.ToAbsolute(globalSettings.Path); + : hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); if (path.IsNullOrWhiteSpace()) throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified"); diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index e71d29412d..c28e05b32e 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -30,7 +30,7 @@ public int VersionCheckPeriod { get; set; } = 7; - public string Path { get; set; } = "~/umbraco"; + public string UmbracoPath { get; set; } = "~/umbraco"; public string IconsPath { get; set; } = $"~/umbraco/assets/icons"; diff --git a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs index 03efac0ffd..9ab3386129 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs @@ -6,7 +6,7 @@ public int MaxCacheDays { get; set; } = 365; - public uint CachedNameLength { get; set; } = 7; + public uint CachedNameLength { get; set; } = 8; public string CacheFolder { get; set; } = "../App_Data/Cache"; } diff --git a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs index 8cd0d3a575..d6fbfae813 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs @@ -77,7 +77,7 @@ namespace Umbraco.Web.HealthCheck.Checks.Permissions { _globalSettings.UmbracoCssPath, PermissionCheckRequirement.Optional }, { _globalSettings.UmbracoMediaPath, PermissionCheckRequirement.Optional }, { _globalSettings.UmbracoScriptsPath, PermissionCheckRequirement.Optional }, - { _globalSettings.Path, PermissionCheckRequirement.Optional }, + { _globalSettings.UmbracoPath, PermissionCheckRequirement.Optional }, { Constants.SystemDirectories.MvcViews, PermissionCheckRequirement.Optional } }; diff --git a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs index 2013fd9904..010e6469bf 100644 --- a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs +++ b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs @@ -138,7 +138,7 @@ namespace Umbraco.Core.Packaging if (path.Contains("[$")) { //this is experimental and undocumented... - path = path.Replace("[$UMBRACO]", _globalSettings.Path); + path = path.Replace("[$UMBRACO]", _globalSettings.UmbracoPath); path = path.Replace("[$CONFIG]", Constants.SystemDirectories.Config); path = path.Replace("[$DATA]", Constants.SystemDirectories.Data); } diff --git a/src/Umbraco.Core/Routing/UrlProvider.cs b/src/Umbraco.Core/Routing/UrlProvider.cs index 6ad44c7716..69d2e00276 100644 --- a/src/Umbraco.Core/Routing/UrlProvider.cs +++ b/src/Umbraco.Core/Routing/UrlProvider.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core; -using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.Configuration.Models; using Microsoft.Extensions.Options; +using Umbraco.Core; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Web.Routing { @@ -28,8 +27,6 @@ namespace Umbraco.Web.Routing /// public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IOptions routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor) { - if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings)); - _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _urlProviders = urlProviders; _mediaUrlProviders = mediaUrlProviders; diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs index 105ef00f73..ffd8b880f2 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs @@ -103,7 +103,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions { var hostingEnvironment = container.GetInstance(); var globalSettings = container.GetInstance>().Value; - var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.Path , "config","lang"))); + var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.UmbracoPath , "config","lang"))); var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins)); var configLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Config ,"lang"))); diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index 406e3a115f..44223f68a4 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -41,7 +41,7 @@ namespace Umbraco.Infrastructure.Configuration TimeOutInMinutes = globalSettings.TimeOutInMinutes, UmbracoCssPath = globalSettings.UmbracoCssPath, UmbracoMediaPath = globalSettings.UmbracoMediaPath, - Path = globalSettings.UmbracoPath, + UmbracoPath = globalSettings.UmbracoPath, UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, IconsPath = globalSettings.IconsPath, UseHttps = globalSettings.UseHttps, diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs index 355326b082..60478aaee3 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs @@ -41,7 +41,7 @@ namespace Umbraco.Infrastructure.Configuration TimeOutInMinutes = globalSettings.TimeOutInMinutes, UmbracoCssPath = globalSettings.UmbracoCssPath, UmbracoMediaPath = globalSettings.UmbracoMediaPath, - UmbracoPath = globalSettings.Path, + UmbracoPath = globalSettings.UmbracoPath, UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, IconsPath = globalSettings.IconsPath, UseHttps = globalSettings.UseHttps, diff --git a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs index 07d78444c1..7a20a1189e 100644 --- a/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Install _ioHelper = ioHelper; _publishedSnapshotService = publishedSnapshotService; _permissionDirs = new[] { _globalSettings.UmbracoCssPath, Constants.SystemDirectories.Config, Constants.SystemDirectories.Data, _globalSettings.UmbracoMediaPath, Constants.SystemDirectories.Preview }; - _packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.Path, Constants.SystemDirectories.Packages }; + _packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.UmbracoPath, Constants.SystemDirectories.Packages }; } public bool RunFilePermissionTestSuite(out Dictionary> report) diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index b37f0dea81..eea82026ab 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -1,6 +1,7 @@ using System; using System.Data.Common; using System.Threading; +using Microsoft.Extensions.Options; using NPoco; using NPoco.FluentMappings; using Umbraco.Core.Configuration.Models; @@ -68,8 +69,8 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used by core runtime. - public UmbracoDatabaseFactory(ILogger logger, GlobalSettings globalSettings, ConnectionStrings connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) - : this(logger, globalSettings, connectionStrings, Constants.System.UmbracoConnectionName, mappers, dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, IOptions globalSettings, IOptions connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) + : this(logger, globalSettings.Value, connectionStrings.Value, Constants.System.UmbracoConnectionName, mappers, dbProviderFactoryCreator) { } diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index 3d1f00ebb9..9e1910d938 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using Microsoft.Extensions.Options; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -407,7 +408,7 @@ namespace Umbraco.Core.Runtime /// /// This is strictly internal, for tests only. protected internal virtual IUmbracoDatabaseFactory GetDatabaseFactory() - => new UmbracoDatabaseFactory(Logger, _globalSettings, _connectionStrings, new Lazy(() => _factory.GetInstance()), DbProviderFactoryCreator); + => new UmbracoDatabaseFactory(Logger, Options.Create(_globalSettings), Options.Create(_connectionStrings), new Lazy(() => _factory.GetInstance()), DbProviderFactoryCreator); #endregion diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index 086092597f..e82c71d1a5 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -675,7 +675,7 @@ namespace Umbraco.Core.Services.Implement public IEnumerable GetPartialViewSnippetNames(params string[] filterNames) { - var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.Path}/PartialViewMacros/Templates/"); + var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.UmbracoPath}/PartialViewMacros/Templates/"); var files = Directory.GetFiles(snippetPath, "*.cshtml") .Select(Path.GetFileNameWithoutExtension) .Except(filterNames, StringComparer.InvariantCultureIgnoreCase) @@ -909,7 +909,7 @@ namespace Umbraco.Core.Services.Implement fileName += ".cshtml"; } - var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.Path}/PartialViewMacros/Templates/{fileName}"); + var snippetPath = _hostingEnvironment.MapPathContentRoot($"{_globalSettings.UmbracoPath}/PartialViewMacros/Templates/{fileName}"); return System.IO.File.Exists(snippetPath) ? Attempt.Succeed(snippetPath) : Attempt.Fail(); diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs index 6058427aae..47e4ebed2c 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs @@ -386,7 +386,7 @@ namespace Umbraco.Core.Services.Implement var protocol = _globalSettings.UseHttps ? "https" : "http"; var subjectVars = new NotificationEmailSubjectParams( - string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.Path)), + string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), actionName, content.Name); @@ -402,7 +402,7 @@ namespace Umbraco.Core.Services.Implement string.Concat(content.Id, ".aspx"), protocol), performingUser.Name, - string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.Path)), + string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), summary.ToString()); var fromMail = _contentSettings.Notifications.Email ?? _globalSettings.Smtp.From; diff --git a/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs b/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs index 8908978e4b..77db7bcbfd 100644 --- a/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs +++ b/src/Umbraco.Infrastructure/WebAssets/BackOfficeJavaScriptInitializer.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.WebAssets } jarray.Append("]"); - return WriteScript(jarray.ToString(), hostingEnvironment.ToAbsolute(globalSettings.Path), angularModule); + return WriteScript(jarray.ToString(), hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), angularModule); } /// diff --git a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs index 61c0822cf3..d39bd71d2e 100644 --- a/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs @@ -18,7 +18,7 @@ namespace Umbraco.Tests.Common.Builders private bool? _hideTopLevelNodeFromPath; private bool? _installEmptyDatabase; private bool? _installMissingDatabase; - private string _path; + private string _umbracoPath; private string _registerType; private string _reservedPaths; private string _reservedUrls; @@ -81,9 +81,9 @@ namespace Umbraco.Tests.Common.Builders return this; } - public GlobalSettingsBuilder WithPath(string path) + public GlobalSettingsBuilder WithUmbracoPath(string umbracoPath) { - _path = path; + _umbracoPath = umbracoPath; return this; } @@ -164,7 +164,7 @@ namespace Umbraco.Tests.Common.Builders var registerType = _registerType ?? null; var reservedPaths = _reservedPaths ?? GlobalSettings.StaticReservedPaths; var reservedUrls = _reservedUrls ?? GlobalSettings.StaticReservedUrls; - var path = _path ?? "~/umbraco"; + var umbracoPath = _umbracoPath ?? "~/umbraco"; var useHttps = _useHttps ?? false; var umbracoCssPath = _umbracoCssPath ?? "~/css"; var umbracoMediaPath = _umbracoMediaPath ?? "~/media"; @@ -187,7 +187,7 @@ namespace Umbraco.Tests.Common.Builders RegisterType = registerType, ReservedPaths = reservedPaths, ReservedUrls = reservedUrls, - Path = path, + UmbracoPath = umbracoPath, UseHttps = useHttps, UmbracoCssPath = umbracoCssPath, UmbracoMediaPath = umbracoMediaPath, diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs index d03d4386f0..6fd5672085 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs @@ -57,7 +57,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco"), globalSettings, Mock.Of(), Mock.Of()); @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), globalSettings, Mock.Of(), GetMockLinkGenerator(out var remainingTimeoutSecondsPath, out var isAuthPath)); @@ -105,7 +105,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), globalSettings, Mock.Of(x => x.IsAvailable == true && x.Get(Constants.Security.ForceReAuthFlag) == "not null"), GetMockLinkGenerator(out var remainingTimeoutSecondsPath, out var isAuthPath)); @@ -127,7 +127,7 @@ namespace Umbraco.Tests.Security var mgr = new BackOfficeCookieManager( Mock.Of(), runtime, - Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.Path) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), + Mock.Of(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install"), globalSettings, Mock.Of(), GetMockLinkGenerator(out var remainingTimeoutSecondsPath, out var isAuthPath)); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index aef126729c..4b8ee755d2 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Components var typeFinder = TestHelper.GetTypeFinder(); var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); - var f = new UmbracoDatabaseFactory(logger, globalSettings, connectionStrings, new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); + var f = new UmbracoDatabaseFactory(logger, Options.Create(globalSettings), Options.Create(connectionStrings), new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.DbProviderFactoryCreator); var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, Options.Create(globalSettings), TestHelper.GetHostingEnvironment()); var coreDebug = new CoreDebugSettingsBuilder().Build(); var mediaFileSystem = Mock.Of(); diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index 69e20fe063..1eac33b5b9 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Configurations var hostingEnvironment = new AspNetHostingEnvironment(mockHostingSettings.Object); - var globalSettings = new GlobalSettingsBuilder().WithPath(path).Build(); + var globalSettings = new GlobalSettingsBuilder().WithUmbracoPath(path).Build(); Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment)); } diff --git a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs index 8f4947952f..d1ee5ac690 100644 --- a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs +++ b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs @@ -3,6 +3,7 @@ using System.Configuration; using System.Data.SqlServerCe; using System.IO; using System.Threading; +using Microsoft.Extensions.Options; using Moq; using NPoco; using NUnit.Framework; @@ -41,7 +42,7 @@ namespace Umbraco.Tests.Persistence _umbracoVersion = TestHelper.GetUmbracoVersion(); var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); - _databaseFactory = new UmbracoDatabaseFactory(_logger, globalSettings, connectionStrings, new Lazy(() => Mock.Of()), TestHelper.DbProviderFactoryCreator); + _databaseFactory = new UmbracoDatabaseFactory(_logger, Options.Create(globalSettings), Options.Create(connectionStrings), new Lazy(() => Mock.Of()), TestHelper.DbProviderFactoryCreator); } [TearDown] diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 965521be31..6ad675ed88 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -68,7 +68,7 @@ namespace Umbraco.Tests.Runtimes var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); var typeFinder = TestHelper.GetTypeFinder(); - var databaseFactory = new UmbracoDatabaseFactory(logger, globalSettings, connectionStrings, new Lazy(() => factory.GetInstance()), TestHelper.DbProviderFactoryCreator); + var databaseFactory = new UmbracoDatabaseFactory(logger, Options.Create(globalSettings), Options.Create(connectionStrings), new Lazy(() => factory.GetInstance()), TestHelper.DbProviderFactoryCreator); var ioHelper = TestHelper.IOHelper; var hostingEnvironment = Mock.Of(); var typeLoader = new TypeLoader(typeFinder, appCaches.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), profilingLogger); diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index e54d0ae46a..36544846ef 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -188,7 +188,7 @@ namespace Umbraco.Tests.TestHelpers new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, hostingEnvironment, new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, Options.Create(globalSettings), "installedPackages.config"), new PackageInstallation( - new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider, shortStringHelper, Microsoft.Extensions.Options.Options.Create(globalSettings), localizedTextService.Value), + new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider, shortStringHelper, Options.Create(globalSettings), localizedTextService.Value), new PackageFileInstallation(compiledPackageXmlParser, ioHelper, new ProfilingLogger(logger, new TestProfiler())), compiledPackageXmlParser, Mock.Of(), Mock.Of(x => x.ApplicationPhysicalPath == ioHelper.MapPath("~"))), diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs index 92df3b0fad..5ee7cf31cf 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.BackOffice.Controllers public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, IOptions globalSettings) { - _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.Value.Path + Path.DirectorySeparatorChar + "lib"); + _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib"); } [HttpGet] diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 6cf92d9100..e3480984fd 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -78,7 +78,7 @@ namespace Umbraco.Web.BackOffice.Controllers [HttpGet] public async Task Default() { - var viewPath = Path.Combine(_globalSettings.Path , Constants.Web.Mvc.BackOfficeArea, nameof(Default) + ".cshtml") + var viewPath = Path.Combine(_globalSettings.UmbracoPath , Constants.Web.Mvc.BackOfficeArea, nameof(Default) + ".cshtml") .Replace("\\", "/"); // convert to forward slashes since it's a virtual path return await RenderDefaultOrProcessExternalLoginAsync( @@ -156,7 +156,7 @@ namespace Umbraco.Web.BackOffice.Controllers [StatusCodeResult(System.Net.HttpStatusCode.ServiceUnavailable)] public async Task AuthorizeUpgrade() { - var viewPath = Path.Combine(_globalSettings.Path, Umbraco.Core.Constants.Web.Mvc.BackOfficeArea, nameof(AuthorizeUpgrade) + ".cshtml"); + var viewPath = Path.Combine(_globalSettings.UmbracoPath, Umbraco.Core.Constants.Web.Mvc.BackOfficeArea, nameof(AuthorizeUpgrade) + ".cshtml"); return await RenderDefaultOrProcessExternalLoginAsync( //The default view to render when there is no external login info or errors () => View(viewPath), diff --git a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs index 7b370b1824..3878eb9b14 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs @@ -77,7 +77,7 @@ namespace Umbraco.Web.BackOffice.Controllers } var viewPath = Path.Combine( - _globalSettings.Path, + _globalSettings.UmbracoPath, Constants.Web.Mvc.BackOfficeArea, ControllerExtensions.GetControllerName() + ".cshtml") .Replace("\\", "/"); // convert to forward slashes since it's a virtual path diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index 6c83bc5747..6f40800307 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.Common.AspNetCore public AspNetCoreBackOfficeInfo(GlobalSettings globalSettings) { - GetAbsoluteUrl = globalSettings.Path; + GetAbsoluteUrl = globalSettings.UmbracoPath; } public string GetAbsoluteUrl { get; } // TODO make absolute diff --git a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs index 776f22eea1..fde3d095fe 100644 --- a/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs +++ b/src/Umbraco.Web.Common/AspNetCore/UmbracoViewPage.cs @@ -64,7 +64,7 @@ namespace Umbraco.Web.Common.AspNetCore // creating previewBadge markup markupToInject = string.Format(ContentSettings.PreviewBadge, - IOHelper.ResolveUrl(GlobalSettings.Path), + IOHelper.ResolveUrl(GlobalSettings.UmbracoPath), Context.Request.GetEncodedUrl(), UmbracoContext.PublishedRequest.PublishedContent.Id); } diff --git a/src/Umbraco.Web.Common/Install/InstallController.cs b/src/Umbraco.Web.Common/Install/InstallController.cs index d3c0e5e0f3..b5da8eabd4 100644 --- a/src/Umbraco.Web.Common/Install/InstallController.cs +++ b/src/Umbraco.Web.Common/Install/InstallController.cs @@ -78,7 +78,7 @@ namespace Umbraco.Web.Common.Install { case ValidateRequestAttempt.FailedNoPrivileges: case ValidateRequestAttempt.FailedNoContextId: - return Redirect(_globalSettings.Path + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl()); + return Redirect(_globalSettings.UmbracoPath + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl()); } } @@ -86,7 +86,7 @@ namespace Umbraco.Web.Common.Install ViewData.SetInstallApiBaseUrl(Url.GetInstallerApiUrl()); // get the base umbraco folder - var baseFolder = _hostingEnvironment.ToAbsolute(_globalSettings.Path); + var baseFolder = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath); ViewData.SetUmbracoBaseFolder(baseFolder); ViewData.SetUmbracoVersion(_umbracoVersion.SemanticVersion); diff --git a/src/Umbraco.Web.Common/Security/WebSecurity.cs b/src/Umbraco.Web.Common/Security/WebSecurity.cs index 0f3831b94c..b822adf656 100644 --- a/src/Umbraco.Web.Common/Security/WebSecurity.cs +++ b/src/Umbraco.Web.Common/Security/WebSecurity.cs @@ -115,7 +115,7 @@ namespace Umbraco.Web.Common.Security private static bool RequestIsInUmbracoApplication(IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToString().IndexOf(hostingEnvironment.ToAbsolute(globalSettings.Path), StringComparison.InvariantCultureIgnoreCase) > -1; + return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToString().IndexOf(hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), StringComparison.InvariantCultureIgnoreCase) > -1; } } } From 8638419088baee8d071265a13321af8faeebd742 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 2 Sep 2020 08:41:41 +0200 Subject: [PATCH 30/58] Fixed dependency resolution issue in PackagingService. --- src/Umbraco.Core/IO/IOHelper.cs | 3 +-- src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs | 5 +++-- src/Umbraco.Core/Packaging/PackageFileInstallation.cs | 8 +------- src/Umbraco.Core/Packaging/PackagesRepository.cs | 1 - .../Packaging/PackageInstallation.cs | 1 - .../Services/Implement/AuditService.cs | 1 - .../Services/Implement/PackagingService.cs | 1 - src/Umbraco.Tests/Packaging/PackageInstallationTest.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 2 +- 9 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 3885930031..118b528869 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Reflection; using System.IO; using System.Linq; -using Umbraco.Core.Configuration; +using System.Reflection; using Umbraco.Core.Hosting; using Umbraco.Core.Strings; diff --git a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs index 010e6469bf..b4cd2bd03f 100644 --- a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs +++ b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Packaging; using File = System.IO.File; @@ -17,10 +18,10 @@ namespace Umbraco.Core.Packaging private readonly ConflictingPackageData _conflictingPackageData; private readonly GlobalSettings _globalSettings; - public CompiledPackageXmlParser(ConflictingPackageData conflictingPackageData, GlobalSettings globalSettings) + public CompiledPackageXmlParser(ConflictingPackageData conflictingPackageData, IOptions globalSettings) { _conflictingPackageData = conflictingPackageData; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } public CompiledPackage ToCompiledPackage(XDocument xml, FileInfo packageFile, string applicationRootFolder) diff --git a/src/Umbraco.Core/Packaging/PackageFileInstallation.cs b/src/Umbraco.Core/Packaging/PackageFileInstallation.cs index 4ae20cd951..4f6c622bb3 100644 --- a/src/Umbraco.Core/Packaging/PackageFileInstallation.cs +++ b/src/Umbraco.Core/Packaging/PackageFileInstallation.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Xml.Linq; -using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Logging; -using Umbraco.Core.Models; using Umbraco.Core.Models.Packaging; -using Umbraco.Core.Services; using File = System.IO.File; namespace Umbraco.Core.Packaging diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index d9c802121d..7e57fe25f4 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Packaging; diff --git a/src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs index cf31b3ea52..4970fc302e 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs @@ -28,7 +28,6 @@ namespace Umbraco.Core.Packaging public PackageInstallation(PackageDataInstallation packageDataInstallation, PackageFileInstallation packageFileInstallation, CompiledPackageXmlParser parser, IPackageActionRunner packageActionRunner, IHostingEnvironment hostingEnvironment) { - _packageExtraction = new PackageExtraction(); _packageFileInstallation = packageFileInstallation ?? throw new ArgumentNullException(nameof(packageFileInstallation)); _packageDataInstallation = packageDataInstallation ?? throw new ArgumentNullException(nameof(packageDataInstallation)); diff --git a/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs b/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs index 7d3be1d52b..4fa7dad253 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs @@ -4,7 +4,6 @@ using System.Linq; using Umbraco.Core.Events; using Umbraco.Core.Logging; using Umbraco.Core.Models; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.Repositories; diff --git a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs index 561b410786..238258b8c2 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs @@ -21,7 +21,6 @@ namespace Umbraco.Core.Services.Implement /// public class PackagingService : IPackagingService { - private readonly IPackageInstallation _packageInstallation; private readonly IIOHelper _ioHelper; private readonly IAuditService _auditService; diff --git a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs index 16c57a7dcb..3b4edd28c1 100644 --- a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs +++ b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs @@ -51,7 +51,7 @@ namespace Umbraco.Tests.Packaging new ConflictingPackageData( ServiceContext.MacroService, ServiceContext.FileService), - new GlobalSettingsBuilder().Build()); + Microsoft.Extensions.Options.Options.Create(new GlobalSettingsBuilder().Build())); private PackageDataInstallation PackageDataInstallation => new PackageDataInstallation( Logger, ServiceContext.FileService, ServiceContext.MacroService, ServiceContext.LocalizationService, diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 36544846ef..73d258a5ed 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -180,7 +180,7 @@ namespace Umbraco.Tests.TestHelpers var macroService = GetLazyService(factory, c => new MacroService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c))); var packagingService = GetLazyService(factory, c => { - var compiledPackageXmlParser = new CompiledPackageXmlParser(new ConflictingPackageData(macroService.Value, fileService.Value), globalSettings); + var compiledPackageXmlParser = new CompiledPackageXmlParser(new ConflictingPackageData(macroService.Value, fileService.Value), Options.Create(globalSettings)); return new PackagingService( auditService.Value, new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, hostingEnvironment, From 90d14158ee14d1bff3dfac4c831d8a47293040cf Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 2 Sep 2020 09:05:55 +0200 Subject: [PATCH 31/58] Clean up - Removed duplicate ctor in UmbracoVersion --- src/Umbraco.Core/Configuration/UmbracoVersion.cs | 8 -------- src/Umbraco.Tests.Common/TestHelperBase.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 4 ++-- src/Umbraco.Web/UmbracoApplicationBase.cs | 2 +- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index 3ae59189fa..7d6d02f33e 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -10,14 +10,6 @@ namespace Umbraco.Core.Configuration /// public class UmbracoVersion : IUmbracoVersion { - private readonly GlobalSettings _globalSettings; - - public UmbracoVersion(GlobalSettings globalSettings) - : this() - { - _globalSettings = globalSettings; - } - public UmbracoVersion() { var umbracoCoreAssembly = typeof(SemVersion).Assembly; diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 3e50cf2a53..df5f67a206 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -128,7 +128,7 @@ namespace Umbraco.Tests.Common return relativePath.Replace("~/", bin + "/"); } - public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(new GlobalSettingsBuilder().Build()); + public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(); public IRegister GetRegister() { diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index b8cab0d0f7..affce75c20 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Testing IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); IIpResolver ipResolver = new AspNetIpResolver(); - UmbracoVersion = new UmbracoVersion(globalSettings); + UmbracoVersion = new UmbracoVersion(); LocalizedTextService = new LocalizedTextService(new Dictionary>(), logger); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index b514b4d918..1428048875 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -126,7 +126,7 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); - // TODO: remove this once no longer requred in Umbraco.Web. + // TODO: remove this once no longer requred in Umbraco.Web. var configsFactory = new AspNetCoreConfigsFactory(configuration); var configs = configsFactory.Create(); services.AddSingleton(configs); @@ -238,7 +238,7 @@ namespace Umbraco.Extensions loggingConfiguration, out var logger, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler); - var umbracoVersion = new UmbracoVersion(globalSettings); + var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); var configs = serviceProvider.GetService(); diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 4f6f2c7f0f..8599464bd1 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -160,7 +160,7 @@ namespace Umbraco.Web var globalSettings = Umbraco.Composing.Current.Configs.Global(); - var umbracoVersion = new UmbracoVersion(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoVersion = new UmbracoVersion(); // create the register for the application, and boot // the boot manager is responsible for registrations From b87630250b5f86de83732c6c982b063145c78a43 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 3 Sep 2020 11:36:57 +0200 Subject: [PATCH 32/58] Removed unused private field and constructor variable for configuration global settings from UmbracoVersion. Updated singleton created instances in CreateCompositionRoot to accept IOptions based parameters for configuration. --- .../Composing/TypeFinderConfig.cs | 5 ++-- .../Configuration/UmbracoVersion.cs | 9 ------- src/Umbraco.Tests.Common/TestHelperBase.cs | 2 +- .../Implementations/TestHelper.cs | 3 ++- .../Extensions/UriExtensionsTests.cs | 5 ++-- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 7 +---- .../AspNetCoreHostingEnvironment.cs | 9 ++----- .../UmbracoCoreServiceCollectionExtensions.cs | 27 +++++++++++-------- src/Umbraco.Web/UmbracoApplicationBase.cs | 2 +- 10 files changed, 30 insertions(+), 41 deletions(-) diff --git a/src/Umbraco.Core/Composing/TypeFinderConfig.cs b/src/Umbraco.Core/Composing/TypeFinderConfig.cs index cf043ab381..ef862fd49d 100644 --- a/src/Umbraco.Core/Composing/TypeFinderConfig.cs +++ b/src/Umbraco.Core/Composing/TypeFinderConfig.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; @@ -14,9 +15,9 @@ namespace Umbraco.Core.Composing private readonly TypeFinderSettings _settings; private IEnumerable _assembliesAcceptingLoadExceptions; - public TypeFinderConfig(TypeFinderSettings settings) + public TypeFinderConfig(IOptions settings) { - _settings = settings; + _settings = settings.Value; } public IEnumerable AssembliesAcceptingLoadExceptions diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index 3ae59189fa..2e45be6cc6 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -1,7 +1,6 @@ using System; using System.Reflection; using Semver; -using Umbraco.Core.Configuration.Models; namespace Umbraco.Core.Configuration { @@ -10,14 +9,6 @@ namespace Umbraco.Core.Configuration /// public class UmbracoVersion : IUmbracoVersion { - private readonly GlobalSettings _globalSettings; - - public UmbracoVersion(GlobalSettings globalSettings) - : this() - { - _globalSettings = globalSettings; - } - public UmbracoVersion() { var umbracoCoreAssembly = typeof(SemVersion).Assembly; diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 3e50cf2a53..df5f67a206 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -128,7 +128,7 @@ namespace Umbraco.Tests.Common return relativePath.Replace("~/", bin + "/"); } - public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(new GlobalSettingsBuilder().Build()); + public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(); public IRegister GetRegister() { diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs index affb274662..c2beb3cdb3 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs @@ -20,6 +20,7 @@ using Umbraco.Tests.Common; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; using Umbraco.Tests.Common.Builders; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.Integration.Implementations { @@ -105,7 +106,7 @@ namespace Umbraco.Tests.Integration.Implementations if (_backOfficeInfo == null) { var globalSettings = new GlobalSettingsBuilder().Build(); - _backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); + _backOfficeInfo = new AspNetCoreBackOfficeInfo(Options.Create(globalSettings)); } return _backOfficeInfo; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs index 9a7b7f63ed..5e394eeffb 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs @@ -1,5 +1,6 @@ using System; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -48,7 +49,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions public void Is_Back_Office_Request(string input, string virtualPath, bool expected) { var hostingSettings = new HostingSettingsBuilder().WithApplicationVirtualPath(virtualPath).Build(); - var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, _hostEnvironment); + var hostingEnvironment = new AspNetCoreHostingEnvironment(Options.Create(hostingSettings), _hostEnvironment); var source = new Uri(input); Assert.AreEqual(expected, source.IsBackOfficeRequest(_globalSettings, hostingEnvironment)); @@ -67,7 +68,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions { var source = new Uri(input); var hostingSettings = new HostingSettingsBuilder().Build(); - var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, _hostEnvironment); + var hostingEnvironment = new AspNetCoreHostingEnvironment(Options.Create(hostingSettings), _hostEnvironment); Assert.AreEqual(expected, source.IsInstallerRequest(hostingEnvironment)); } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index b8cab0d0f7..affce75c20 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Testing IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); IIpResolver ipResolver = new AspNetIpResolver(); - UmbracoVersion = new UmbracoVersion(globalSettings); + UmbracoVersion = new UmbracoVersion(); LocalizedTextService = new LocalizedTextService(new Dictionary>(), logger); diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index 6f40800307..edc5efdd1e 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -7,13 +7,8 @@ namespace Umbraco.Web.Common.AspNetCore public class AspNetCoreBackOfficeInfo : IBackOfficeInfo { public AspNetCoreBackOfficeInfo(IOptions globalSettings) - : this(globalSettings.Value) { - } - - public AspNetCoreBackOfficeInfo(GlobalSettings globalSettings) - { - GetAbsoluteUrl = globalSettings.UmbracoPath; + GetAbsoluteUrl = globalSettings.Value.UmbracoPath; } public string GetAbsoluteUrl { get; } // TODO make absolute diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index 32c291bbce..84518c16de 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -16,13 +16,8 @@ namespace Umbraco.Web.Common.AspNetCore private string _localTempPath; public AspNetCoreHostingEnvironment(IOptions hostingSettings, IWebHostEnvironment webHostEnvironment) - : this(hostingSettings.Value, webHostEnvironment) { - } - - public AspNetCoreHostingEnvironment(HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) - { - _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); + _hostingSettings = hostingSettings.Value ?? throw new ArgumentNullException(nameof(hostingSettings)); _webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment)); SiteName = webHostEnvironment.ApplicationName; @@ -30,7 +25,7 @@ namespace Umbraco.Web.Common.AspNetCore ApplicationPhysicalPath = webHostEnvironment.ContentRootPath; //TODO how to find this, This is a server thing, not application thing. - ApplicationVirtualPath = hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') + ApplicationVirtualPath = _hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') ?? "/"; IISVersion = new Version(0, 0); // TODO not necessary IIS diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index b514b4d918..fb16d0db8e 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -126,6 +126,12 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); + //services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); + services.Configure(settings => + { + settings.EnableTours = false; + }); + // TODO: remove this once no longer requred in Umbraco.Web. var configsFactory = new AspNetCoreConfigsFactory(configuration); var configs = configsFactory.Create(); @@ -224,10 +230,10 @@ namespace Umbraco.Extensions // `RegisterEssentials`. var serviceProvider = services.BuildServiceProvider(); - var globalSettings = serviceProvider.GetService>().Value; - var connectionStrings = serviceProvider.GetService>().Value; - var hostingSettings = serviceProvider.GetService>().Value; - var typeFinderSettings = serviceProvider.GetService>().Value; + var globalSettings = serviceProvider.GetService>(); + var connectionStrings = serviceProvider.GetService>(); + var hostingSettings = serviceProvider.GetService>(); + var typeFinderSettings = serviceProvider.GetService>(); var dbProviderFactoryCreator = serviceProvider.GetRequiredService(); @@ -238,14 +244,14 @@ namespace Umbraco.Extensions loggingConfiguration, out var logger, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler); - var umbracoVersion = new UmbracoVersion(globalSettings); + var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); var configs = serviceProvider.GetService(); var coreRuntime = GetCoreRuntime( configs, - globalSettings, - connectionStrings, + globalSettings.Value, + connectionStrings.Value, umbracoVersion, ioHelper, logger, @@ -261,7 +267,7 @@ namespace Umbraco.Extensions return services; } - private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, TypeFinderSettings typeFinderSettings) + private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, IOptions typeFinderSettings) { var runtimeHashPaths = new RuntimeHashPaths(); runtimeHashPaths.AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin"))); @@ -305,8 +311,8 @@ namespace Umbraco.Extensions private static IServiceCollection CreateCompositionRoot( IServiceCollection services, - GlobalSettings globalSettings, - HostingSettings hostingSettings, + IOptions globalSettings, + IOptions hostingSettings, IWebHostEnvironment webHostEnvironment, ILoggingConfiguration loggingConfiguration, out Core.Logging.ILogger logger, @@ -318,7 +324,6 @@ namespace Umbraco.Extensions if (globalSettings == null) throw new InvalidOperationException($"Could not resolve type {typeof(GlobalSettings)} from the container, ensure {nameof(AddUmbracoConfiguration)} is called before calling {nameof(AddUmbracoCore)}"); - hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment); ioHelper = new IOHelper(hostingEnvironment); logger = AddLogger(services, hostingEnvironment, loggingConfiguration); diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 4f6f2c7f0f..8599464bd1 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -160,7 +160,7 @@ namespace Umbraco.Web var globalSettings = Umbraco.Composing.Current.Configs.Global(); - var umbracoVersion = new UmbracoVersion(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoVersion = new UmbracoVersion(); // create the register for the application, and boot // the boot manager is responsible for registrations From 14404f27203f58592d2a49537af912f154f34b58 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 3 Sep 2020 12:29:23 +0200 Subject: [PATCH 33/58] Changed singleton created dependencies in composition root to use IOptionsMonitor. --- .../Composing/TypeFinderConfig.cs | 4 +-- .../Implementations/TestHelper.cs | 29 ++++++++++++------- .../Implementations/TestHostingEnvironment.cs | 4 +-- .../Extensions/UriExtensionsTests.cs | 14 +++++---- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 4 +-- .../AspNetCoreHostingEnvironment.cs | 4 +-- .../UmbracoCoreServiceCollectionExtensions.cs | 14 ++++----- 7 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/Umbraco.Core/Composing/TypeFinderConfig.cs b/src/Umbraco.Core/Composing/TypeFinderConfig.cs index ef862fd49d..302d45b4e8 100644 --- a/src/Umbraco.Core/Composing/TypeFinderConfig.cs +++ b/src/Umbraco.Core/Composing/TypeFinderConfig.cs @@ -15,9 +15,9 @@ namespace Umbraco.Core.Composing private readonly TypeFinderSettings _settings; private IEnumerable _assembliesAcceptingLoadExceptions; - public TypeFinderConfig(IOptions settings) + public TypeFinderConfig(IOptionsMonitor settings) { - _settings = settings.Value; + _settings = settings.CurrentValue; } public IEnumerable AssembliesAcceptingLoadExceptions diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs index c2beb3cdb3..fc7974f8f3 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs @@ -1,26 +1,26 @@ - -using System; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Hosting; -using Moq; +using System; using System.Data.Common; using System.IO; using System.Net; using System.Reflection; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; +using Moq; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Diagnostics; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; -using Umbraco.Net; using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; +using Umbraco.Net; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; -using Umbraco.Tests.Common.Builders; -using Microsoft.Extensions.Options; namespace Umbraco.Tests.Integration.Implementations { @@ -106,7 +106,8 @@ namespace Umbraco.Tests.Integration.Implementations if (_backOfficeInfo == null) { var globalSettings = new GlobalSettingsBuilder().Build(); - _backOfficeInfo = new AspNetCoreBackOfficeInfo(Options.Create(globalSettings)); + var mockedOptionsMonitorOfGlobalSettings = Mock.Of>(x => x.CurrentValue == globalSettings); + _backOfficeInfo = new AspNetCoreBackOfficeInfo(mockedOptionsMonitorOfGlobalSettings); } return _backOfficeInfo; @@ -114,9 +115,15 @@ namespace Umbraco.Tests.Integration.Implementations public override IHostingEnvironment GetHostingEnvironment() => _hostingEnvironment ??= new TestHostingEnvironment( - new HostingSettingsBuilder().Build(), + GetIOptionsMonitorOfHostingSettings(), _hostEnvironment); + private IOptionsMonitor GetIOptionsMonitorOfHostingSettings() + { + var hostingSettings = new HostingSettingsBuilder().Build(); + return Mock.Of>(x => x.CurrentValue == hostingSettings); + } + public override IApplicationShutdownRegistry GetHostingEnvironmentLifetime() => _hostingLifetime; public override IIpResolver GetIpResolver() => _ipResolver; diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs index c03a1a1699..1a3415634b 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs @@ -8,8 +8,8 @@ namespace Umbraco.Tests.Integration.Implementations { public class TestHostingEnvironment : AspNetCoreHostingEnvironment, IHostingEnvironment { - public TestHostingEnvironment(HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) - : base(Options.Create(hostingSettings), webHostEnvironment) + public TestHostingEnvironment(IOptionsMonitor hostingSettings, IWebHostEnvironment webHostEnvironment) + : base(hostingSettings, webHostEnvironment) { } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs index 5e394eeffb..f098af7de6 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs @@ -48,10 +48,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions [TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)] public void Is_Back_Office_Request(string input, string virtualPath, bool expected) { - var hostingSettings = new HostingSettingsBuilder().WithApplicationVirtualPath(virtualPath).Build(); - var hostingEnvironment = new AspNetCoreHostingEnvironment(Options.Create(hostingSettings), _hostEnvironment); - var source = new Uri(input); + var hostingEnvironment = CreateHostingEnvironment(virtualPath); Assert.AreEqual(expected, source.IsBackOfficeRequest(_globalSettings, hostingEnvironment)); } @@ -67,11 +65,17 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions public void Is_Installer_Request(string input, bool expected) { var source = new Uri(input); - var hostingSettings = new HostingSettingsBuilder().Build(); - var hostingEnvironment = new AspNetCoreHostingEnvironment(Options.Create(hostingSettings), _hostEnvironment); + var hostingEnvironment = CreateHostingEnvironment(); Assert.AreEqual(expected, source.IsInstallerRequest(hostingEnvironment)); } + private AspNetCoreHostingEnvironment CreateHostingEnvironment(string virtualPath = "") + { + var hostingSettings = new HostingSettingsBuilder().WithApplicationVirtualPath(virtualPath).Build(); + var mockedOptionsMonitorOfHostingSettings = Mock.Of>(x => x.CurrentValue == hostingSettings); + return new AspNetCoreHostingEnvironment(mockedOptionsMonitorOfHostingSettings, _hostEnvironment); + } + [TestCase("http://www.domain.com/foo/bar", "/", "http://www.domain.com/")] [TestCase("http://www.domain.com/foo/bar#hop", "/", "http://www.domain.com/")] [TestCase("http://www.domain.com/foo/bar?q=2#hop", "/", "http://www.domain.com/?q=2")] diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index edc5efdd1e..fe991275de 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -6,9 +6,9 @@ namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreBackOfficeInfo : IBackOfficeInfo { - public AspNetCoreBackOfficeInfo(IOptions globalSettings) + public AspNetCoreBackOfficeInfo(IOptionsMonitor globalSettings) { - GetAbsoluteUrl = globalSettings.Value.UmbracoPath; + GetAbsoluteUrl = globalSettings.CurrentValue.UmbracoPath; } public string GetAbsoluteUrl { get; } // TODO make absolute diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index 84518c16de..296f083659 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -15,9 +15,9 @@ namespace Umbraco.Web.Common.AspNetCore private string _localTempPath; - public AspNetCoreHostingEnvironment(IOptions hostingSettings, IWebHostEnvironment webHostEnvironment) + public AspNetCoreHostingEnvironment(IOptionsMonitor hostingSettings, IWebHostEnvironment webHostEnvironment) { - _hostingSettings = hostingSettings.Value ?? throw new ArgumentNullException(nameof(hostingSettings)); + _hostingSettings = hostingSettings.CurrentValue ?? throw new ArgumentNullException(nameof(hostingSettings)); _webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment)); SiteName = webHostEnvironment.ApplicationName; diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index fb16d0db8e..8d91aad5f3 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -230,10 +230,10 @@ namespace Umbraco.Extensions // `RegisterEssentials`. var serviceProvider = services.BuildServiceProvider(); - var globalSettings = serviceProvider.GetService>(); + var globalSettings = serviceProvider.GetService>(); var connectionStrings = serviceProvider.GetService>(); - var hostingSettings = serviceProvider.GetService>(); - var typeFinderSettings = serviceProvider.GetService>(); + var hostingSettings = serviceProvider.GetService>(); + var typeFinderSettings = serviceProvider.GetService>(); var dbProviderFactoryCreator = serviceProvider.GetRequiredService(); @@ -250,7 +250,7 @@ namespace Umbraco.Extensions var configs = serviceProvider.GetService(); var coreRuntime = GetCoreRuntime( configs, - globalSettings.Value, + globalSettings.CurrentValue, connectionStrings.Value, umbracoVersion, ioHelper, @@ -267,7 +267,7 @@ namespace Umbraco.Extensions return services; } - private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, IOptions typeFinderSettings) + private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, IOptionsMonitor typeFinderSettings) { var runtimeHashPaths = new RuntimeHashPaths(); runtimeHashPaths.AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin"))); @@ -311,8 +311,8 @@ namespace Umbraco.Extensions private static IServiceCollection CreateCompositionRoot( IServiceCollection services, - IOptions globalSettings, - IOptions hostingSettings, + IOptionsMonitor globalSettings, + IOptionsMonitor hostingSettings, IWebHostEnvironment webHostEnvironment, ILoggingConfiguration loggingConfiguration, out Core.Logging.ILogger logger, From 88e3c586477b2f7fa28a42520e5fa2f823c34c23 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 3 Sep 2020 13:02:29 +0200 Subject: [PATCH 34/58] Fixed issue after merge. --- .../AutoFixture/AutoMoqDataAttribute.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index b04889a842..de9d8bb98a 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -5,10 +5,11 @@ using AutoFixture.Kernel; using AutoFixture.NUnit3; using Microsoft.AspNetCore.Identity; using Moq; +using Umbraco.Core; using Umbraco.Core.BackOffice; +using Umbraco.Core.Configuration; using Umbraco.Tests.Common.Builders; using Umbraco.Web.BackOffice.Controllers; -using Umbraco.Core; using Umbraco.Web.Common.Install; namespace Umbraco.Tests.UnitTests.AutoFixture From 3efee8284a22f97316aed375eda32ecbf31cf141 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 7 Sep 2020 15:28:58 +0200 Subject: [PATCH 35/58] Post merge fixes --- src/Umbraco.Core/Composing/Composition.cs | 6 +- .../UmbracoBuilderExtensions.cs | 64 +++++++++-------- .../AspNetCoreHostingEnvironment.cs | 15 ++-- .../Builder/UmbracoBuilderExtensions.cs | 2 +- .../UmbracoCoreServiceCollectionExtensions.cs | 71 +++++++++++-------- src/Umbraco.Web.UI.NetCore/Startup.cs | 1 + .../Umbraco.Web.UI.NetCore.csproj | 2 +- 7 files changed, 85 insertions(+), 76 deletions(-) diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index e248d9eaf3..c7842565f0 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -63,9 +63,9 @@ namespace Umbraco.Core.Composing public IRuntimeState RuntimeState { get; } // TODO: remove this once no longer required for functionality in Umbraco.Web. - /// - /// Gets the configurations. - /// + /// + /// Gets the configurations. + /// public Configs Configs { get; } #endregion diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs index 49c4f224ee..3514a8557c 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs @@ -17,41 +17,43 @@ namespace Umbraco.Tests.Integration.TestServerTest /// /// /// - public static IUmbracoBuilder WithTestCore(this IUmbracoBuilder builder, TestHelper testHelper, LightInjectContainer container, + public static IUmbracoBuilder WithTestCore(this IUmbracoBuilder builder, TestHelper testHelper, + LightInjectContainer container, Action dbInstallEventHandler) { return builder.AddWith(nameof(global::Umbraco.Web.Common.Builder.UmbracoBuilderExtensions.WithCore), - () => - { - builder.Services.AddUmbracoCore( - builder.WebHostEnvironment, - container, - typeof(UmbracoBuilderExtensions).Assembly, - AppCaches.NoCache, // Disable caches in integration tests - testHelper.GetLoggingConfiguration(), - // TODO: Yep that's extremely ugly - (configs, globalSettings, connectionStrings, umbVersion, ioHelper, logger, profiler, hostingEnv, backOfficeInfo, typeFinder, appCaches, dbProviderFactoryCreator) => - { - var runtime = UmbracoIntegrationTest.CreateTestRuntime( - configs, - globalSettings, - connectionStrings, - umbVersion, - ioHelper, - logger, - profiler, - hostingEnv, - backOfficeInfo, - typeFinder, - appCaches, - dbProviderFactoryCreator, - testHelper.MainDom, // SimpleMainDom - dbInstallEventHandler); // DB Installation event handler + () => + { + builder.Services.AddUmbracoCore( + builder.WebHostEnvironment, + container, + typeof(UmbracoBuilderExtensions).Assembly, + AppCaches.NoCache, // Disable caches in integration tests + testHelper.GetLoggingConfiguration(), + // TODO: Yep that's extremely ugly + (configs, globalSettings, connectionStrings, umbVersion, ioHelper, logger, profiler, hostingEnv, + backOfficeInfo, typeFinder, appCaches, dbProviderFactoryCreator) => + { + var runtime = UmbracoIntegrationTest.CreateTestRuntime( + configs, + globalSettings, + connectionStrings, + umbVersion, + ioHelper, + logger, + profiler, + hostingEnv, + backOfficeInfo, + typeFinder, + appCaches, + dbProviderFactoryCreator, + testHelper.MainDom, // SimpleMainDom + dbInstallEventHandler); // DB Installation event handler - return runtime; - }, - out _); - }); + return runtime; + }, + out _); + }); } } } diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index 296f083659..ede121a9f7 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -10,24 +10,20 @@ namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreHostingEnvironment : Core.Hosting.IHostingEnvironment { - private readonly HostingSettings _hostingSettings; + private IOptionsMonitor _hostingSettings; private readonly IWebHostEnvironment _webHostEnvironment; private string _localTempPath; public AspNetCoreHostingEnvironment(IOptionsMonitor hostingSettings, IWebHostEnvironment webHostEnvironment) { - _hostingSettings = hostingSettings.CurrentValue ?? throw new ArgumentNullException(nameof(hostingSettings)); + _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); _webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment)); SiteName = webHostEnvironment.ApplicationName; ApplicationId = AppDomain.CurrentDomain.Id.ToString(); ApplicationPhysicalPath = webHostEnvironment.ContentRootPath; - //TODO how to find this, This is a server thing, not application thing. - ApplicationVirtualPath = _hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') - ?? "/"; - IISVersion = new Version(0, 0); // TODO not necessary IIS } @@ -37,8 +33,9 @@ namespace Umbraco.Web.Common.AspNetCore public string ApplicationPhysicalPath { get; } public string ApplicationServerAddress { get; } - public string ApplicationVirtualPath { get; } - public bool IsDebugMode => _hostingSettings.Debug; + //TODO how to find this, This is a server thing, not application thing. + public string ApplicationVirtualPath => _hostingSettings.CurrentValue.ApplicationVirtualPath?.EnsureStartsWith('/') ?? "/"; + public bool IsDebugMode => _hostingSettings.CurrentValue.Debug; public Version IISVersion { get; } public string LocalTempPath @@ -48,7 +45,7 @@ namespace Umbraco.Web.Common.AspNetCore if (_localTempPath != null) return _localTempPath; - switch (_hostingSettings.LocalTempStorageLocation) + switch (_hostingSettings.CurrentValue.LocalTempStorageLocation) { case LocalTempStorage.AspNetTemp: diff --git a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs index dd91a2cca9..08b7670522 100644 --- a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs @@ -34,7 +34,7 @@ namespace Umbraco.Web.Common.Builder { options.ShouldProfile = request => false; // WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile })); - + public static IUmbracoBuilder WithMvcAndRazor(this IUmbracoBuilder builder, Action mvcOptions = null, Action mvcBuilding = null) => builder.AddWith(nameof(WithMvcAndRazor), () => { diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 7afa4adf68..06b2d7b421 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -29,6 +29,8 @@ using Umbraco.Web.Common.AspNetCore; using Umbraco.Web.Common.Profiler; using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; +using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Extensions { @@ -93,6 +95,28 @@ namespace Umbraco.Extensions return services; } + /// + /// Adds the Umbraco Back Core requirements + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static IServiceCollection AddUmbracoCore( + this IServiceCollection services, + IWebHostEnvironment webHostEnvironment, + IRegister umbContainer, + Assembly entryAssembly, + AppCaches appCaches, + ILoggingConfiguration loggingConfiguration, + out IFactory factory) + => services.AddUmbracoCore(webHostEnvironment, umbContainer, entryAssembly, appCaches, loggingConfiguration, GetCoreRuntime, out factory); + /// /// Adds the Umbraco Configuration requirements /// @@ -184,6 +208,7 @@ namespace Umbraco.Extensions Assembly.GetEntryAssembly(), appCaches, loggingConfig, + GetCoreRuntime, out factory); return services; @@ -196,9 +221,10 @@ namespace Umbraco.Extensions /// /// /// - /// + /// /// /// + /// Delegate to create ana /// /// public static IServiceCollection AddUmbracoCore( @@ -206,34 +232,10 @@ namespace Umbraco.Extensions IWebHostEnvironment webHostEnvironment, IRegister umbContainer, Assembly entryAssembly, - AppCaches appCaches, + AppCaches appCaches, ILoggingConfiguration loggingConfiguration, - out IFactory factory) - => services.AddUmbracoCore(webHostEnvironment, umbContainer, entryAssembly, appCaches, loggingConfiguration, GetCoreRuntime, out factory); - - - /// - /// Adds the Umbraco Back Core requirements - /// - /// - /// - /// - /// - /// - /// - /// - /// Delegate to create an - /// - /// - public static IServiceCollection AddUmbracoCore( - this IServiceCollection services, - IWebHostEnvironment webHostEnvironment, - IRegister umbContainer, - Assembly entryAssembly, - AppCaches appCaches, - ILoggingConfiguration loggingConfiguration, - // TODO: Yep that's extremely ugly - Func getRuntime, + //TODO: Yep that's extremely ugly + Func getRuntime, out IFactory factory) { if (services is null) throw new ArgumentNullException(nameof(services)); @@ -267,7 +269,6 @@ namespace Umbraco.Extensions var typeFinderSettings = serviceProvider.GetService>(); var dbProviderFactoryCreator = serviceProvider.GetRequiredService(); - var configs = serviceProvider.GetRequiredService(); CreateCompositionRoot(services, globalSettings, @@ -279,7 +280,8 @@ namespace Umbraco.Extensions var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); - var runtime = getRuntime( + var configs = serviceProvider.GetService(); + var coreRuntime = getRuntime( configs, globalSettings.CurrentValue, connectionStrings.Value, @@ -293,7 +295,14 @@ namespace Umbraco.Extensions appCaches, dbProviderFactoryCreator); - factory = runtime.Configure(container); + factory = coreRuntime.Configure(container); + + + services.Configure(hostingSettings => + { + hostingSettings.Debug = false; + }); + return services; } diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs index 72e0d792f3..aa141b2624 100644 --- a/src/Umbraco.Web.UI.NetCore/Startup.cs +++ b/src/Umbraco.Web.UI.NetCore/Startup.cs @@ -34,6 +34,7 @@ namespace Umbraco.Web.UI.NetCore { var umbracoBuilder = services.AddUmbraco(_env, _config); umbracoBuilder.BuildWithAllBackOfficeComponents(); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index 3e1518abdd..c9421d2cb8 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -17,7 +17,7 @@ - + From e079bd5a50d3648d2a193caeddbe079df72874f3 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 8 Sep 2020 13:03:43 +0200 Subject: [PATCH 36/58] Cleanup usages of Configs --- src/Umbraco.Core/Composing/Composition.cs | 11 +----- src/Umbraco.Core/Composing/Current.cs | 16 ++++++--- .../Configuration/ConfigsExtensions.cs | 24 ------------- .../UmbracoServiceProviderFactory.cs | 5 ++- .../ConfigModelConversionsFromLegacy.cs | 16 +++++++++ .../Models/ContentEditing/UserInvite.cs | 2 +- .../Runtime/CoreRuntime.cs | 5 +-- src/Umbraco.Infrastructure/Trees/TreeNode.cs | 4 +-- .../ContainerTests.cs | 6 ++-- src/Umbraco.Tests.Integration/RuntimeTests.cs | 5 ++- .../UmbracoBuilderExtensions.cs | 3 +- .../Testing/IntegrationTestComposer.cs | 6 ++-- .../Testing/UmbracoIntegrationTest.cs | 7 +--- .../PublishedContentCacheTests.cs | 4 ++- .../Components/ComponentTests.cs | 28 +++++++-------- .../Composing/CollectionBuildersTests.cs | 4 +-- .../Composing/CompositionTests.cs | 2 +- .../Composing/LazyCollectionBuilderTests.cs | 10 +++--- .../Composing/PackageActionCollectionTests.cs | 2 +- src/Umbraco.Tests/IO/FileSystemsTests.cs | 6 +--- .../PublishedContentCache.cs | 5 +-- .../XmlPublishedSnapshotService.cs | 7 ++-- .../PropertyEditorValueEditorTests.cs | 2 +- .../Published/ConvertersTests.cs | 2 +- .../Routing/BaseUrlProviderTest.cs | 4 --- .../ContentFinderByUrlAndTemplateTests.cs | 7 ++-- .../Routing/ContentFinderByUrlTests.cs | 31 ++++++++-------- .../ContentFinderByUrlWithDomainsTests.cs | 11 +++--- .../Routing/DomainsAndCulturesTests.cs | 17 +++++---- .../Routing/RenderRouteHandlerTests.cs | 4 +-- .../Routing/RoutableDocumentFilterTests.cs | 16 +++++---- .../Routing/UmbracoModuleTests.cs | 2 +- ...oviderWithHideTopLevelNodeFromPathTests.cs | 7 ++-- ...derWithoutHideTopLevelNodeFromPathTests.cs | 14 ++++---- src/Umbraco.Tests/Routing/UrlRoutesTests.cs | 36 +++++++++---------- .../Routing/UrlsProviderWithDomainsTests.cs | 14 ++++---- .../Routing/UrlsWithNestedDomains.cs | 2 +- .../Runtimes/CoreRuntimeTests.cs | 19 ++++++---- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 8 ++--- .../Scoping/ScopeEventDispatcherTests.cs | 5 +-- .../Scoping/ScopedNuCacheTests.cs | 6 ++-- src/Umbraco.Tests/Scoping/ScopedXmlTests.cs | 4 --- .../ContentTypeServiceVariantsTests.cs | 6 ++-- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- .../TestControllerActivatorBase.cs | 3 +- .../TestHelpers/TestObjects-Mocks.cs | 6 ++-- .../TestHelpers/TestWithDatabaseBase.cs | 10 +++--- .../Objects/TestUmbracoContextFactory.cs | 6 ++-- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 14 ++------ .../UmbracoCoreServiceCollectionExtensions.cs | 14 ++------ .../Mvc/AreaRegistrationExtensions.cs | 5 +-- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 7 ++-- src/Umbraco.Web/Mvc/PluginControllerArea.cs | 5 +-- src/Umbraco.Web/RoutableDocumentFilter.cs | 5 +-- .../Runtime/WebInitialComponent.cs | 13 +++---- src/Umbraco.Web/UmbracoApplication.cs | 11 +++--- src/Umbraco.Web/UmbracoApplicationBase.cs | 32 ++++++++++++----- src/Umbraco.Web/UmbracoContext.cs | 7 ++-- src/Umbraco.Web/UmbracoContextFactory.cs | 5 +-- 59 files changed, 265 insertions(+), 275 deletions(-) diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index c7842565f0..998f42a2dc 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -31,13 +31,12 @@ namespace Umbraco.Core.Composing /// Optional configs. /// An IOHelper /// - public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs, IIOHelper ioHelper, AppCaches appCaches) + public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, IIOHelper ioHelper, AppCaches appCaches) { _register = register ?? throw new ArgumentNullException(nameof(register)); TypeLoader = typeLoader ?? throw new ArgumentNullException(nameof(typeLoader)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); RuntimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); - Configs = configs ?? throw new ArgumentNullException(nameof(configs)); IOHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); AppCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); } @@ -62,12 +61,6 @@ namespace Umbraco.Core.Composing /// public IRuntimeState RuntimeState { get; } - // TODO: remove this once no longer required for functionality in Umbraco.Web. - /// - /// Gets the configurations. - /// - public Configs Configs { get; } - #endregion #region IRegister @@ -136,8 +129,6 @@ namespace Umbraco.Core.Composing IFactory factory = null; - Configs.RegisterWith(_register); - // ReSharper disable once AccessToModifiedClosure -- on purpose _register.Register(_ => factory, Lifetime.Singleton); factory = _register.CreateFactory(); diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 055a29228a..856be9f414 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -1,7 +1,9 @@ using System; using System.Runtime.CompilerServices; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -11,18 +13,21 @@ namespace Umbraco.Composing public static class Current { private static ILogger _logger = new NullLogger(); - private static Configs _configs; private static IIOHelper _ioHelper; private static IHostingEnvironment _hostingEnvironment; private static IBackOfficeInfo _backOfficeInfo; private static IProfiler _profiler; + private static SecuritySettings _securitySettings; + private static GlobalSettings _globalSettings; public static ILogger Logger => EnsureInitialized(_logger); - public static Configs Configs => EnsureInitialized(_configs); + public static IIOHelper IOHelper => EnsureInitialized(_ioHelper); public static IHostingEnvironment HostingEnvironment => EnsureInitialized(_hostingEnvironment); public static IBackOfficeInfo BackOfficeInfo => EnsureInitialized(_backOfficeInfo); public static IProfiler Profiler => EnsureInitialized(_profiler); + public static SecuritySettings SecuritySettings => EnsureInitialized(_securitySettings); + public static GlobalSettings GlobalSettings => EnsureInitialized(_globalSettings); public static bool IsInitialized { get; internal set; } @@ -37,7 +42,8 @@ namespace Umbraco.Composing public static void Initialize( ILogger logger, - Configs configs, + SecuritySettings securitySettings, + GlobalSettings globalSettings, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, @@ -49,13 +55,15 @@ namespace Umbraco.Composing } _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _configs = configs ?? throw new ArgumentNullException(nameof(configs)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _backOfficeInfo = backOfficeInfo ?? throw new ArgumentNullException(nameof(backOfficeInfo)); _profiler = profiler ?? throw new ArgumentNullException(nameof(profiler)); + _securitySettings = securitySettings ?? throw new ArgumentNullException(nameof(securitySettings)); + _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); IsInitialized = true; } + } } diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs index a4bdb5c55f..0f63903320 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -11,42 +11,18 @@ namespace Umbraco.Core public static class ConfigsExtensions { - public static IImagingSettings Imaging(this Configs configs) - => configs.GetConfig(); public static IGlobalSettings Global(this Configs configs) => configs.GetConfig(); - public static IHostingSettings Hosting(this Configs configs) - => configs.GetConfig(); public static IConnectionStrings ConnectionStrings(this Configs configs) => configs.GetConfig(); - public static IContentSettings Content(this Configs configs) - => configs.GetConfig(); - public static ISecuritySettings Security(this Configs configs) => configs.GetConfig(); - public static ITypeFinderSettings TypeFinder(this Configs configs) - => configs.GetConfig(); - - - public static IUserPasswordConfiguration UserPasswordConfiguration(this Configs configs) - => configs.GetConfig(); - public static IMemberPasswordConfiguration MemberPasswordConfiguration(this Configs configs) - => configs.GetConfig(); - - public static IRequestHandlerSettings RequestHandler(this Configs configs) - => configs.GetConfig(); - public static IWebRoutingSettings WebRouting(this Configs configs) => configs.GetConfig(); - public static IHealthChecksSettings HealthChecks(this Configs configs) - => configs.GetConfig(); - public static ICoreDebugSettings CoreDebug(this Configs configs) - => configs.GetConfig(); - } } diff --git a/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs b/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs index 56a972a64b..51bd5e7b14 100644 --- a/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs +++ b/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs @@ -2,9 +2,11 @@ using LightInject.Microsoft.DependencyInjection; using Microsoft.Extensions.DependencyInjection; using System; +using Microsoft.Extensions.Options; using Umbraco.Composing; using Umbraco.Core.Composing.LightInject; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.Core.Composing @@ -86,7 +88,8 @@ namespace Umbraco.Core.Composing // after cross wiring, configure "Current" Current.Initialize( _container.GetInstance(), - _container.GetInstance(), + _container.GetInstance(), + _container.GetInstance(), _container.GetInstance(), _container.GetInstance(), _container.GetInstance(), diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index 44223f68a4..d4a34d72d8 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -1,6 +1,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Infrastructure.Configuration { @@ -69,5 +70,20 @@ namespace Umbraco.Infrastructure.Configuration RequireUppercase = passwordConfiguration.RequireUppercase, }; } + + public static SecuritySettings ConvertSecuritySettings(ISecuritySettings securitySettings) + { + return new SecuritySettings + { + MemberPassword = new MemberPasswordConfigurationSettings(), + UserPassword = new UserPasswordConfigurationSettings(), + AllowPasswordReset = securitySettings.AllowPasswordReset, + AuthCookieDomain = securitySettings.AuthCookieDomain, + AuthCookieName = securitySettings.AuthCookieDomain, + UsernameIsEmail = securitySettings.UsernameIsEmail, + KeepUserLoggedIn = securitySettings.KeepUserLoggedIn, + HideDisabledUsersInBackoffice = securitySettings.HideDisabledUsersInBackoffice, + }; + } } } diff --git a/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs b/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs index 428f85937b..68a7a9bd3f 100644 --- a/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs +++ b/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs @@ -34,7 +34,7 @@ namespace Umbraco.Web.Models.ContentEditing yield return new ValidationResult("A user must be assigned to at least one group", new[] { nameof(UserGroups) }); // TODO: this will need another way of retrieving this setting if and when Configs are removed from Current. - if (Current.Configs.Security().UsernameIsEmail == false && Username.IsNullOrWhiteSpace()) + if (Current.SecuritySettings.UsernameIsEmail == false && Username.IsNullOrWhiteSpace()) yield return new ValidationResult("A username cannot be empty", new[] { nameof(Username) }); } } diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index 7d02152a57..e4b724089c 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -29,12 +29,10 @@ namespace Umbraco.Core.Runtime // runtime state, this instance will get replaced again once the essential services are available to run the check private RuntimeState _state = RuntimeState.Booting(); private readonly IUmbracoBootPermissionChecker _umbracoBootPermissionChecker; - private readonly Configs _configs; private readonly GlobalSettings _globalSettings; private readonly ConnectionStrings _connectionStrings; public CoreRuntime( - Configs configs, // TODO: remove this parameter with legacy configuraiton no longer needed in Umbraco.Web and Umbraco.Tests GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, @@ -49,7 +47,6 @@ namespace Umbraco.Core.Runtime ITypeFinder typeFinder, AppCaches appCaches) { - _configs = configs; _globalSettings = globalSettings; _connectionStrings = connectionStrings; @@ -179,7 +176,7 @@ namespace Umbraco.Core.Runtime _state = new RuntimeState(_globalSettings, UmbracoVersion, databaseFactory, Logger); // create the composition - composition = new Composition(register, typeLoader, ProfilingLogger, _state, _configs, IOHelper, AppCaches); + composition = new Composition(register, typeLoader, ProfilingLogger, _state, IOHelper, AppCaches); composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, MainDom, AppCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, UmbracoVersion, DbProviderFactoryCreator, HostingEnvironment, BackOfficeInfo); diff --git a/src/Umbraco.Infrastructure/Trees/TreeNode.cs b/src/Umbraco.Infrastructure/Trees/TreeNode.cs index 585929c0e1..5cf1054fc8 100644 --- a/src/Umbraco.Infrastructure/Trees/TreeNode.cs +++ b/src/Umbraco.Infrastructure/Trees/TreeNode.cs @@ -116,8 +116,8 @@ namespace Umbraco.Web.Models.Trees //legacy icon path // TODO: replace this when we have something other than Current.Configs available - //var backOfficePath = Current.Configs.Global().GetUmbracoMvcArea(Current.HostingEnvironment); - var backOfficePath = new GlobalSettings().GetUmbracoMvcArea(Current.HostingEnvironment); + var backOfficePath = Current.GlobalSettings.GetUmbracoMvcArea(Current.HostingEnvironment); + return string.Format("{0}images/umbraco/{1}", backOfficePath.EnsureEndsWith("/"), Icon); } diff --git a/src/Umbraco.Tests.Integration/ContainerTests.cs b/src/Umbraco.Tests.Integration/ContainerTests.cs index 3ba3c31d03..00d6c14be3 100644 --- a/src/Umbraco.Tests.Integration/ContainerTests.cs +++ b/src/Umbraco.Tests.Integration/ContainerTests.cs @@ -36,15 +36,15 @@ namespace Umbraco.Tests.Integration serviceProviderFactory.CreateBuilder(services); // called during Host Builder, needed to capture services // Dependencies needed for creating composition/register essentials - var testHelper = new TestHelper(); + var testHelper = new TestHelper(); var runtimeState = Mock.Of(); var umbracoDatabaseFactory = Mock.Of(); - var dbProviderFactoryCreator = Mock.Of(); + var dbProviderFactoryCreator = Mock.Of(); var typeLoader = testHelper.GetMockedTypeLoader(); // Register in the container var composition = new Composition(umbracoContainer, typeLoader, - testHelper.Logger, runtimeState, testHelper.GetConfigs(), testHelper.IOHelper, testHelper.AppCaches); + testHelper.Logger, runtimeState, testHelper.IOHelper, testHelper.AppCaches); composition.RegisterEssentials(testHelper.Logger, testHelper.Profiler, testHelper.Logger, testHelper.MainDom, testHelper.AppCaches, umbracoDatabaseFactory, typeLoader, runtimeState, testHelper.GetTypeFinder(), testHelper.IOHelper, testHelper.GetUmbracoVersion(), dbProviderFactoryCreator, diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index c081caedc1..a5b421fcd3 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -56,12 +56,11 @@ namespace Umbraco.Tests.Integration var testHelper = new TestHelper(); - var configs = testHelper.GetConfigs(); var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); // Create the core runtime - var coreRuntime = new CoreRuntime(configs, globalSettings, connectionStrings, testHelper.GetUmbracoVersion(), + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, testHelper.GetUmbracoVersion(), testHelper.IOHelper, testHelper.Logger, testHelper.Profiler, testHelper.UmbracoBootPermissionChecker, testHelper.GetHostingEnvironment(), testHelper.GetBackOfficeInfo(), testHelper.DbProviderFactoryCreator, testHelper.MainDom, testHelper.GetTypeFinder(), AppCaches.NoCache); @@ -92,7 +91,7 @@ namespace Umbraco.Tests.Integration umbracoContainer.Register(x => Options.Create(requestHandlerSettings)); umbracoContainer.Register(x => Options.Create(userPasswordConfigurationSettings)); umbracoContainer.Register(x => Options.Create(webRoutingSettings)); - + coreRuntime.Start(); Assert.IsTrue(MyComponent.IsInit); diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs index 3514a8557c..0fa81d7de5 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs @@ -31,11 +31,10 @@ namespace Umbraco.Tests.Integration.TestServerTest AppCaches.NoCache, // Disable caches in integration tests testHelper.GetLoggingConfiguration(), // TODO: Yep that's extremely ugly - (configs, globalSettings, connectionStrings, umbVersion, ioHelper, logger, profiler, hostingEnv, + (globalSettings, connectionStrings, umbVersion, ioHelper, logger, profiler, hostingEnv, backOfficeInfo, typeFinder, appCaches, dbProviderFactoryCreator) => { var runtime = UmbracoIntegrationTest.CreateTestRuntime( - configs, globalSettings, connectionStrings, umbVersion, diff --git a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs index e9b38741e2..ebbfb0be25 100644 --- a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs +++ b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs @@ -3,10 +3,12 @@ using NUnit.Framework; using System; using System.IO; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -57,7 +59,7 @@ namespace Umbraco.Tests.Integration.Testing /// private ILocalizedTextService GetLocalizedTextService(IFactory factory) { - var configs = factory.GetInstance(); + var globalSettings = factory.GetInstance>(); var logger = factory.GetInstance(); var appCaches = factory.GetInstance(); @@ -71,7 +73,7 @@ namespace Umbraco.Tests.Integration.Testing currFolder = currFolder.Parent; } var netcoreUI = currFolder.GetDirectories("Umbraco.Web.UI.NetCore", SearchOption.TopDirectoryOnly).First(); - var mainLangFolder = new DirectoryInfo(Path.Combine(netcoreUI.FullName, configs.Global().UmbracoPath.TrimStart("~/"), "config", "lang")); + var mainLangFolder = new DirectoryInfo(Path.Combine(netcoreUI.FullName, globalSettings.Value.UmbracoPath.TrimStart("~/"), "config", "lang")); return new LocalizedTextServiceFileSources( logger, diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 975710f460..a8f3b51e37 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -123,7 +123,6 @@ namespace Umbraco.Tests.Integration.Testing /// /// Creates a instance for testing and registers an event handler for database install /// - /// /// /// /// @@ -137,14 +136,13 @@ namespace Umbraco.Tests.Integration.Testing /// /// public CoreRuntime CreateTestRuntime( - Configs configs, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, Core.Hosting.IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, ITypeFinder typeFinder, AppCaches appCaches, IDbProviderFactoryCreator dbProviderFactoryCreator) { - var runtime = CreateTestRuntime(configs, + var runtime = CreateTestRuntime( globalSettings, connectionStrings, umbracoVersion, @@ -166,7 +164,6 @@ namespace Umbraco.Tests.Integration.Testing /// /// Creates a instance for testing and registers an event handler for database install /// - /// /// /// /// @@ -182,7 +179,6 @@ namespace Umbraco.Tests.Integration.Testing /// /// public static CoreRuntime CreateTestRuntime( - Configs configs, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, @@ -191,7 +187,6 @@ namespace Umbraco.Tests.Integration.Testing IMainDom mainDom, Action eventHandler) { var runtime = new CoreRuntime( - configs, globalSettings, connectionStrings, umbracoVersion, diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index 932a974b75..13f58f8021 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -5,9 +5,11 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Services; using Umbraco.Tests.Common; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -58,7 +60,7 @@ namespace Umbraco.Tests.Cache.PublishedCache _httpContextFactory = new FakeHttpContextFactory("~/Home"); - var globalSettings = Factory.GetInstance(); + var globalSettings = new GlobalSettingsBuilder().Build(); var umbracoContextAccessor = Factory.GetInstance(); _xml = new XmlDocument(); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 4b8ee755d2..de99ba445f 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -75,7 +75,7 @@ namespace Umbraco.Tests.Components { var register = MockRegister(); var typeLoader = MockTypeLoader(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -114,7 +114,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -130,7 +130,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -145,7 +145,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -162,7 +162,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -185,7 +185,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -221,7 +221,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -247,7 +247,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -262,7 +262,7 @@ namespace Umbraco.Tests.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -280,7 +280,7 @@ namespace Umbraco.Tests.Components var register = MockRegister(); var typeLoader = MockTypeLoader(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -299,7 +299,7 @@ namespace Umbraco.Tests.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -338,7 +338,7 @@ namespace Umbraco.Tests.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of()); @@ -353,7 +353,7 @@ namespace Umbraco.Tests.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer26) }; var enableDisableAttributes = new[] { new DisableComposerAttribute(typeof(Composer26)) }; @@ -380,7 +380,7 @@ namespace Umbraco.Tests.Components var register = MockRegister(); var composition = new Composition(register, typeLoader, Mock.Of(), - MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var allComposers = typeLoader.GetTypes().ToList(); var types = allComposers.Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")).ToList(); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 2d977e89c7..4986c3ac53 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.Composing Current.Reset(); var register = TestHelper.GetRegister(); - _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); } [TearDown] @@ -490,7 +490,7 @@ namespace Umbraco.Tests.Composing for (var i = 0; i < col1A.Length; i++) { Assert.AreNotSame(col1A[i], col2A[i]); - } + } } #endregion diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 380511eaaa..229ba1102b 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing var typeFinder = TestHelper.GetTypeFinder(); var ioHelper = TestHelper.IOHelper; var typeLoader = new TypeLoader(typeFinder, Mock.Of(), new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), logger); - var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); // create the factory, ensure it is the mocked factory var factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index 4d0135d6c4..c17e80a34a 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -67,7 +67,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -118,7 +118,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -140,7 +140,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 390997173b..118eaab41a 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Composing { var container = TestHelper.GetRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var expectedPackageActions = TypeLoader.GetPackageActions(); composition.WithCollectionBuilder() diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index eabd331a02..b474da872f 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -31,7 +31,7 @@ namespace Umbraco.Tests.IO { _register = TestHelper.GetRegister(); - var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); @@ -42,15 +42,11 @@ namespace Umbraco.Tests.IO composition.RegisterUnique(TestHelper.IOHelper); composition.RegisterUnique(TestHelper.GetHostingEnvironment()); - composition.Configs.Add(() => SettingsForTests.DefaultGlobalSettings); - var globalSettings = new GlobalSettingsBuilder().Build(); composition.Register(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); composition.ComposeFileSystems(); - composition.Configs.Add(SettingsForTests.GenerateMockContentSettings); - _factory = composition.CreateFactory(); Current.Reset(); diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs index afdb71c28e..fe02e6fa48 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs @@ -7,6 +7,7 @@ using System.Xml.XPath; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Xml; using Umbraco.Tests.TestHelpers; @@ -18,7 +19,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache internal class PublishedContentCache : PublishedCacheBase, IPublishedContentCache { private readonly IAppCache _appCache; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly RoutesCache _routesCache; private readonly IVariationContextAccessor _variationContextAccessor; private readonly IDomainCache _domainCache; @@ -33,7 +34,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache XmlStore xmlStore, // an XmlStore containing the master xml IDomainCache domainCache, // an IDomainCache implementation IAppCache appCache, // an IAppCache that should be at request-level - IGlobalSettings globalSettings, + GlobalSettings globalSettings, PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache RoutesCache routesCache, // a RoutesCache IVariationContextAccessor variationContextAccessor, diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs index bf7cbe40c4..a913ba06bd 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs @@ -3,6 +3,7 @@ using System.Linq; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -35,7 +36,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache private readonly IMediaService _mediaService; private readonly IUserService _userService; private readonly IAppCache _requestCache; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IDefaultCultureAccessor _defaultCultureAccessor; private readonly ISiteDomainHelper _siteDomainHelper; private readonly IEntityXmlSerializer _entitySerializer; @@ -56,7 +57,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, ILogger logger, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IShortStringHelper shortStringHelper, @@ -84,7 +85,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, ILogger logger, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IShortStringHelper shortStringHelper, diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index d2d8cb952b..439036fa16 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.PropertyEditors Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); register.Register(_ diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 3ecae51ea8..2ae4c238cc 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -182,7 +182,7 @@ namespace Umbraco.Tests.Published // Current.Reset(); var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs b/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs index 999748bc73..a4f472898e 100644 --- a/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs +++ b/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs @@ -29,10 +29,6 @@ namespace Umbraco.Tests.Routing Composition.Register(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); Composition.Register(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); - - // TODO: remove this once legacy config is fully extracted. - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockGlobalSettings); } protected IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) diff --git a/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs index 2c991ce455..14a7ec3ab1 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs @@ -31,12 +31,13 @@ namespace Umbraco.Tests.Routing [TestCase("/home/Sub1.aspx/blah")] public void Match_Document_By_Url_With_Template(string urlAsString) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder() + .WithHideTopLevelNodeFromPath(false) + .Build(); var template1 = CreateTemplate("test"); var template2 = CreateTemplate("blah"); - var umbracoContext = GetUmbracoContext(urlAsString, template1.Id, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext(urlAsString, template1.Id, globalSettings: globalSettings); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); diff --git a/src/Umbraco.Tests/Routing/ContentFinderByUrlTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByUrlTests.cs index f7b6762774..0614d4a2bb 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByUrlTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByUrlTests.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Web.Composing; using Umbraco.Core.Configuration; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Web.Routing; @@ -28,15 +29,15 @@ namespace Umbraco.Tests.Routing [TestCase("/test-page", 1172)] public void Match_Document_By_Url_Hide_Top_Level(string urlString, int expectedId) { - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(true); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(true).Build(); - var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettingsMock.Object); + var snapshotService = CreatePublishedSnapshotService(globalSettings); + var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettings, snapshotService: snapshotService); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); var lookup = new ContentFinderByUrl(Logger); - Assert.IsTrue(Current.Configs.Global().HideTopLevelNodeFromPath); + Assert.IsTrue(globalSettings.HideTopLevelNodeFromPath); // FIXME: debugging - going further down, the routes cache is NOT empty?! if (urlString == "/home/sub1") @@ -63,15 +64,14 @@ namespace Umbraco.Tests.Routing [TestCase("/home/Sub1.aspx", 1173)] public void Match_Document_By_Url(string urlString, int expectedId) { - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettingsMock.Object); + var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); var lookup = new ContentFinderByUrl(Logger); - Assert.IsFalse(Current.Configs.Global().HideTopLevelNodeFromPath); + Assert.IsFalse(globalSettings.HideTopLevelNodeFromPath); var result = lookup.TryFindContent(frequest); @@ -88,10 +88,9 @@ namespace Umbraco.Tests.Routing [TestCase("/home/sub1/custom-sub-4-with-æøå", 1180)] public void Match_Document_By_Url_With_Special_Characters(string urlString, int expectedId) { - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettingsMock.Object); + var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); var lookup = new ContentFinderByUrl(Logger); @@ -115,10 +114,9 @@ namespace Umbraco.Tests.Routing [TestCase("/home/sub1/custom-sub-4-with-æøå", 1180)] public void Match_Document_By_Url_With_Special_Characters_Using_Hostname(string urlString, int expectedId) { - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettingsMock.Object); + var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); frequest.Domain = new DomainAndUri(new Domain(1, "mysite", -1, CultureInfo.CurrentCulture, false), new Uri("http://mysite/")); @@ -144,10 +142,9 @@ namespace Umbraco.Tests.Routing [TestCase("/æøå/home/sub1/custom-sub-4-with-æøå", 1180)] public void Match_Document_By_Url_With_Special_Characters_In_Hostname(string urlString, int expectedId) { - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettingsMock.Object); + var umbracoContext = GetUmbracoContext(urlString, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(); var frequest = publishedRouter.CreateRequest(umbracoContext); frequest.Domain = new DomainAndUri(new Domain(1, "mysite/æøå", -1, CultureInfo.CurrentCulture, false), new Uri("http://mysite/æøå")); diff --git a/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs index ac2e62b1ef..622df53d9e 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs @@ -4,6 +4,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Models; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Routing; @@ -127,10 +128,9 @@ namespace Umbraco.Tests.Routing { SetDomains3(); - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(true); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(true).Build(); - var umbracoContext = GetUmbracoContext(url, globalSettings:globalSettingsMock.Object); + var umbracoContext = GetUmbracoContext(url, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(Factory); var frequest = publishedRouter.CreateRequest(umbracoContext); @@ -169,10 +169,9 @@ namespace Umbraco.Tests.Routing // defaults depend on test environment expectedCulture = expectedCulture ?? System.Threading.Thread.CurrentThread.CurrentUICulture.Name; - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(true); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(true).Build(); - var umbracoContext = GetUmbracoContext(url, globalSettings:globalSettingsMock.Object); + var umbracoContext = GetUmbracoContext(url, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(Factory); var frequest = publishedRouter.CreateRequest(umbracoContext); diff --git a/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs b/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs index a81f345e38..0d39092b88 100644 --- a/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs +++ b/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs @@ -6,6 +6,7 @@ using Umbraco.Web.Routing; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Routing { @@ -266,10 +267,10 @@ namespace Umbraco.Tests.Routing { SetDomains1(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); - var umbracoContext = GetUmbracoContext(inputUrl, globalSettings:globalSettings.Object); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + + var umbracoContext = GetUmbracoContext(inputUrl, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(Factory); var frequest = publishedRouter.CreateRequest(umbracoContext); @@ -315,10 +316,9 @@ namespace Umbraco.Tests.Routing // defaults depend on test environment expectedCulture = expectedCulture ?? System.Threading.Thread.CurrentThread.CurrentUICulture.Name; - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext(inputUrl, globalSettings:globalSettings.Object); + var umbracoContext = GetUmbracoContext(inputUrl, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(Factory); var frequest = publishedRouter.CreateRequest(umbracoContext); @@ -370,9 +370,8 @@ namespace Umbraco.Tests.Routing { SetDomains3(); - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); - var umbracoContext = GetUmbracoContext(inputUrl, globalSettings:globalSettings.Object); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); + var umbracoContext = GetUmbracoContext(inputUrl, globalSettings:globalSettings); var publishedRouter = CreatePublishedRouter(Factory); var frequest = publishedRouter.CreateRequest(umbracoContext); diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 3f97f1a4a3..3328114576 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -52,8 +52,8 @@ namespace Umbraco.Tests.Routing public class TestRuntime : CoreRuntime { - public TestRuntime(Configs configs, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - : base(configs, globalSettings, connectionStrings,umbracoVersion, ioHelper, Mock.Of(), Mock.Of(), new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), AppCaches.NoCache) + public TestRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + : base(globalSettings, connectionStrings,umbracoVersion, ioHelper, Mock.Of(), Mock.Of(), new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), AppCaches.NoCache) { } diff --git a/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs b/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs index a78459fa39..9bf85d61be 100644 --- a/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs +++ b/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs @@ -1,9 +1,12 @@ -using System.Web.Mvc; +using System; +using System.Web.Mvc; using System.Web.Routing; using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Infrastructure.Configuration; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -51,12 +54,13 @@ namespace Umbraco.Tests.Routing public void Is_Reserved_By_Route(string url, bool shouldMatch) { //reset the app config, we only want to test routes not the hard coded paths - // TODO: Why are we using and modifying the global IGlobalSettings and not just a custom one? - var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.ReservedPaths).Returns(""); - globalSettingsMock.Setup(x => x.ReservedUrls).Returns(""); - var routableDocFilter = new RoutableDocumentFilter(globalSettingsMock.Object, IOHelper); + var globalSettings = new GlobalSettingsBuilder() + .WithReservedPaths(string.Empty) + .WithReservedUrls(String.Empty) + .Build(); + + var routableDocFilter = new RoutableDocumentFilter(globalSettings, IOHelper); var routes = new RouteCollection(); diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 993b0a112b..a2b3ce62e4 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Routing logger, null, // FIXME: PublishedRouter complexities... Mock.Of(), - new RoutableDocumentFilter(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper), + new RoutableDocumentFilter(globalSettings, IOHelper), UriUtility, AppCaches.RequestCache, ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs index b38e7b5fc9..a5bbdd1f7c 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Routing base.ComposeSettings(); Composition.RegisterUnique(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); } - + [TestCase(1046, "/")] [TestCase(1173, "/sub1/")] [TestCase(1174, "/sub1/sub2/")] @@ -40,11 +40,10 @@ namespace Umbraco.Tests.Routing [TestCase(1172, "/test-page/")] // not hidden because not first root public void Get_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(true); var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + var snapshotService = CreatePublishedSnapshotService(_globalSettings); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings,snapshotService:snapshotService); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs index e4275fe391..bb25635d6f 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Routing { var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -107,7 +107,7 @@ namespace Umbraco.Tests.Routing { var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -147,7 +147,7 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings), + globalSettings: _globalSettings, snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( @@ -202,7 +202,7 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings), + globalSettings: _globalSettings, snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( @@ -257,7 +257,7 @@ namespace Umbraco.Tests.Routing .Returns(snapshot); var umbracoContext = GetUmbracoContext(currentUri, - globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings), + globalSettings: _globalSettings, snapshotService: snapshotService.Object); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( @@ -279,7 +279,7 @@ namespace Umbraco.Tests.Routing { var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: _globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -303,7 +303,7 @@ namespace Umbraco.Tests.Routing Logger, Microsoft.Extensions.Options.Options.Create(_globalSettings), new SiteDomainHelper(), UmbracoContextAccessor, UriUtility); - var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(_globalSettings)); + var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: _globalSettings); var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider); //mock the Umbraco settings that we need diff --git a/src/Umbraco.Tests/Routing/UrlRoutesTests.cs b/src/Umbraco.Tests/Routing/UrlRoutesTests.cs index 0c608d3e94..d0dd708561 100644 --- a/src/Umbraco.Tests/Routing/UrlRoutesTests.cs +++ b/src/Umbraco.Tests/Routing/UrlRoutesTests.cs @@ -5,6 +5,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Models; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -196,10 +197,9 @@ DetermineRouteById(id): [TestCase(2006, false, "/x/b/e")] public void GetRouteByIdNoHide(int id, bool hide, string expected) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(hide); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(hide).Build(); - var umbracoContext = GetUmbracoContext("/test", 0, globalSettings: globalSettings.Object); + var umbracoContext = GetUmbracoContext("/test", 0, globalSettings: globalSettings); var cache = umbracoContext.Content as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); @@ -220,10 +220,10 @@ DetermineRouteById(id): [TestCase(2006, true, "/b/e")] // risky! public void GetRouteByIdHide(int id, bool hide, string expected) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(hide); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(hide).Build(); - var umbracoContext = GetUmbracoContext("/test", 0, globalSettings: globalSettings.Object); + var snapshotService = CreatePublishedSnapshotService(globalSettings); + var umbracoContext = GetUmbracoContext("/test", 0, globalSettings: globalSettings, snapshotService: snapshotService); var cache = umbracoContext.Content as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); @@ -234,10 +234,10 @@ DetermineRouteById(id): [Test] public void GetRouteByIdCache() { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings.Object); + var snapshotService = CreatePublishedSnapshotService(globalSettings); + var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings, snapshotService: snapshotService); var cache = umbracoContext.Content as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); @@ -265,10 +265,10 @@ DetermineRouteById(id): [TestCase("/x", false, 2000)] public void GetByRouteNoHide(string route, bool hide, int expected) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(hide); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(hide).Build(); - var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings.Object); + var snapshotService = CreatePublishedSnapshotService(globalSettings); + var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings, snapshotService: snapshotService); var cache = umbracoContext.Content as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); @@ -296,10 +296,10 @@ DetermineRouteById(id): [TestCase("/b/c", true, 1002)] // (hence the 2005 collision) public void GetByRouteHide(string route, bool hide, int expected) { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(hide); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(hide).Build(); - var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings.Object); + var snapshotService = CreatePublishedSnapshotService(globalSettings); + var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings, snapshotService: snapshotService); var cache = umbracoContext.Content as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); @@ -319,10 +319,10 @@ DetermineRouteById(id): [Test] public void GetByRouteCache() { - var globalSettings = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); + var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings.Object); + var snapshotService = CreatePublishedSnapshotService(globalSettings); + var umbracoContext = GetUmbracoContext("/test", 0, globalSettings:globalSettings, snapshotService:snapshotService); var cache = umbracoContext.Content as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); diff --git a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs index 3e7fb611df..c566e742cb 100644 --- a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs @@ -182,7 +182,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, @@ -216,7 +216,7 @@ namespace Umbraco.Tests.Routing var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, @@ -243,7 +243,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), Logger, @@ -276,7 +276,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -300,7 +300,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -366,7 +366,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), @@ -393,7 +393,7 @@ namespace Umbraco.Tests.Routing var globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(false).Build(); - var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index fdd891bda6..d5b98c402f 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -43,7 +43,7 @@ namespace Umbraco.Tests.Routing const string url = "http://domain1.com/1001-1/1001-1-1"; // get the nice url for 100111 - var umbracoContext = GetUmbracoContext(url, 9999, globalSettings: ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoContext = GetUmbracoContext(url, 9999, globalSettings: globalSettings); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 531102ae59..4de83eed4e 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; @@ -21,6 +22,7 @@ using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Web; using Umbraco.Web.Hosting; using Umbraco.Web.Runtime; +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Tests.Runtimes @@ -82,18 +84,21 @@ namespace Umbraco.Tests.Runtimes // test application public class TestUmbracoApplication : UmbracoApplicationBase { - public TestUmbracoApplication() : base(_logger, _configs, _ioHelper, _profiler, new AspNetHostingEnvironment(_hostingSettings), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _logger, _settings)) + public TestUmbracoApplication() : base(_logger, + ConfigModelConversionsFromLegacy.ConvertSecuritySettings(SettingsForTests.GenerateMockSecuritySettings()), + ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.DefaultGlobalSettings), + new ConnectionStrings(), + _ioHelper, _profiler, new AspNetHostingEnvironment(_hostingSettings), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _logger, _settings)) { } private static readonly DebugDiagnosticsLogger _logger = new DebugDiagnosticsLogger(new MessageTemplates()); private static readonly IIOHelper _ioHelper = TestHelper.IOHelper; private static readonly IProfiler _profiler = new TestProfiler(); - private static readonly Configs _configs = GetConfigs(); private static readonly IGlobalSettings _globalSettings = SettingsForTests.DefaultGlobalSettings; private static readonly IHostingSettings _hostingSettings = SettingsForTests.DefaultHostingSettings; private static readonly IContentSettings _contentSettings = SettingsForTests.GenerateMockContentSettings(); - private static readonly IWebRoutingSettings _settings = _configs.WebRouting(); + private static readonly IWebRoutingSettings _settings = SettingsForTests.GenerateMockWebRoutingSettings(); private static Configs GetConfigs() { @@ -106,17 +111,17 @@ namespace Umbraco.Tests.Runtimes public IRuntime Runtime { get; private set; } - protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + protected override IRuntime GetRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { - return Runtime = new TestRuntime(configs, umbracoVersion, ioHelper, logger, profiler, hostingEnvironment, backOfficeInfo); + return Runtime = new TestRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, hostingEnvironment, backOfficeInfo); } } // test runtime public class TestRuntime : CoreRuntime { - public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - :base(configs, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(configs.Global()), ConfigModelConversionsFromLegacy.ConvertConnectionStrings(configs.ConnectionStrings()),umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), AppCaches.NoCache) + public TestRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + :base(globalSettings, connectionStrings,umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), AppCaches.NoCache) { } diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 2231633a10..5f0fc607c6 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -81,11 +81,11 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, ioHelper, appCaches); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); // create the core runtime and have it compose itself - var coreRuntime = new CoreRuntime(configs, globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, AppCaches.NoCache); + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, AppCaches.NoCache); // determine actual runtime level runtimeState.DetermineRuntimeLevel(); @@ -289,7 +289,7 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, ioHelper, appCaches); var umbracoVersion = TestHelper.GetUmbracoVersion(); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion, TestHelper.DbProviderFactoryCreator, hostingEnvironment, backOfficeInfo); @@ -297,7 +297,7 @@ namespace Umbraco.Tests.Runtimes var globalSettings = new GlobalSettingsBuilder().Build(); var connectionStrings = new ConnectionStringsBuilder().Build(); - var coreRuntime = new CoreRuntime(configs, globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, AppCaches.NoCache); + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, typeFinder, AppCaches.NoCache); // get the components // all of them? diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index a0c954e7bb..d775b0d8d3 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Scoping var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); _testObjects = new TestObjects(register); @@ -43,9 +43,6 @@ namespace Umbraco.Tests.Scoping composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance(), TestHelper.IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings), TestHelper.GetHostingEnvironment())); composition.WithCollectionBuilder(); - composition.Configs.Add(() => SettingsForTests.DefaultGlobalSettings); - composition.Configs.Add(SettingsForTests.GenerateMockContentSettings); - Current.Reset(); Current.Factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 35f4f421bd..243ad50eef 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.Install; @@ -74,7 +75,7 @@ namespace Umbraco.Tests.Scoping private Action _onPublishedAssertAction; - protected override IPublishedSnapshotService CreatePublishedSnapshotService() + protected override IPublishedSnapshotService CreatePublishedSnapshotService(GlobalSettings globalSettings = null) { var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Umbraco.Web.Composing.Current.UmbracoContextAccessor); @@ -89,7 +90,6 @@ namespace Umbraco.Tests.Scoping var typeFinder = TestHelper.GetTypeFinder(); - var globalSettings = new GlobalSettingsBuilder().Build(); var nuCacheSettings = new NuCacheSettingsBuilder().Build(); return new PublishedSnapshotService( @@ -105,7 +105,7 @@ namespace Umbraco.Tests.Scoping documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, new DatabaseDataSource(Mock.Of()), - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(globalSettings ?? new GlobalSettingsBuilder().Build()), Factory.GetInstance(), new NoopPublishedModelFactory(), new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(ShortStringHelper) }), diff --git a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs index 72c6438324..59610e43bd 100644 --- a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs @@ -51,10 +51,6 @@ namespace Umbraco.Tests.Scoping Composition.Register(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); Composition.Register(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); Composition.Register(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); - - // TODO: remove this once legacy config is fully extracted. - Composition.Configs.Add(SettingsForTests.GenerateMockContentSettings); - Composition.Configs.Add(SettingsForTests.GenerateMockGlobalSettings); } [TearDown] diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index 5830513fbd..bef6fde816 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Install; using Umbraco.Core.Logging; @@ -46,7 +47,7 @@ namespace Umbraco.Tests.Services .Add(() => Composition.TypeLoader.GetCacheRefreshers()); } - protected override IPublishedSnapshotService CreatePublishedSnapshotService() + protected override IPublishedSnapshotService CreatePublishedSnapshotService(GlobalSettings globalSettings = null) { var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Umbraco.Web.Composing.Current.UmbracoContextAccessor); @@ -61,7 +62,6 @@ namespace Umbraco.Tests.Services var typeFinder = TestHelper.GetTypeFinder(); - var globalSettings = new GlobalSettingsBuilder().Build(); var nuCacheSettings = new NuCacheSettingsBuilder().Build(); return new PublishedSnapshotService( @@ -77,7 +77,7 @@ namespace Umbraco.Tests.Services documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, new DatabaseDataSource(Mock.Of()), - Microsoft.Extensions.Options.Options.Create(globalSettings), + Microsoft.Extensions.Options.Options.Create(globalSettings ?? new GlobalSettingsBuilder().Build()), Factory.GetInstance(), Mock.Of(), new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(ShortStringHelper) }), diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 6bc228bf83..3faea42f01 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), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index 641691e853..27aa9a832c 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -23,6 +23,7 @@ using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi; using Umbraco.Core.Logging; +using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Testing.Objects.Accessors; using Umbraco.Web.Security.Providers; using Umbraco.Tests.Strings; @@ -67,7 +68,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting contentTypeService: mockedContentTypeService, localizedTextService:Mock.Of()); - var globalSettings = SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.GenerateMockGlobalSettings()); // FIXME: v8? ////new app context diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 1b63bcc98d..1ed2bce83e 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -8,12 +8,14 @@ using Moq; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Configuration; using Umbraco.Persistance.SqlCe; using Umbraco.Tests.Common; using Umbraco.Web; @@ -136,9 +138,9 @@ namespace Umbraco.Tests.TestHelpers return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext; } - public IGlobalSettings GetGlobalSettings() + public GlobalSettings GetGlobalSettings() { - return SettingsForTests.DefaultGlobalSettings; + return ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.DefaultGlobalSettings); } public IFileSystems GetFileSystemsMock() { diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 3c88f710bc..6e133778bb 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -11,6 +11,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -29,6 +30,7 @@ using Umbraco.Tests.Testing; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence.Repositories; +using Umbraco.Infrastructure.Configuration; using Umbraco.Persistance.SqlCe; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Web.WebApi; @@ -238,7 +240,7 @@ namespace Umbraco.Tests.TestHelpers } } - protected virtual IPublishedSnapshotService CreatePublishedSnapshotService() + protected virtual IPublishedSnapshotService CreatePublishedSnapshotService(GlobalSettings globalSettings = null) { var cache = NoAppCache.Instance; @@ -262,7 +264,7 @@ namespace Umbraco.Tests.TestHelpers Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), DefaultCultureAccessor, Logger, - Factory.GetInstance(), + globalSettings ?? TestObjects.GetGlobalSettings(), HostingEnvironment, HostingLifetime, ShortStringHelper, @@ -352,7 +354,7 @@ namespace Umbraco.Tests.TestHelpers } } - protected IUmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null) + protected IUmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, GlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null) { // ensure we have a PublishedCachesService var service = snapshotService ?? PublishedSnapshotService as XmlPublishedSnapshotService; @@ -376,7 +378,7 @@ namespace Umbraco.Tests.TestHelpers httpContextAccessor, service, Mock.Of(), - globalSettings ?? Factory.GetInstance(), + globalSettings ?? new GlobalSettingsBuilder().Build(), HostingEnvironment, new TestVariationContextAccessor(), UriUtility, diff --git a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs index cb20c56d6d..595185c271 100644 --- a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs +++ b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs @@ -1,8 +1,10 @@ using Moq; using NUnit.Framework.Internal; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -16,12 +18,12 @@ namespace Umbraco.Tests.Testing.Objects /// public class TestUmbracoContextFactory { - public static IUmbracoContextFactory Create(IGlobalSettings globalSettings = null, + public static IUmbracoContextFactory Create(GlobalSettings globalSettings = null, IUmbracoContextAccessor umbracoContextAccessor = null, IHttpContextAccessor httpContextAccessor = null, IPublishedUrlProvider publishedUrlProvider = null) { - if (globalSettings == null) globalSettings = TestHelpers.SettingsForTests.GenerateMockGlobalSettings(); + if (globalSettings == null) globalSettings = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(TestHelpers.SettingsForTests.GenerateMockGlobalSettings()); if (umbracoContextAccessor == null) umbracoContextAccessor = new TestUmbracoContextAccessor(); if (httpContextAccessor == null) httpContextAccessor = TestHelper.GetHttpContextAccessor(); if (publishedUrlProvider == null) publishedUrlProvider = TestHelper.GetPublishedUrlProvider(); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index affce75c20..3d2a4496a6 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -188,9 +188,11 @@ namespace Umbraco.Tests.Testing - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); + TestHelper.GetConfigs().RegisterWith(register); + Composition.RegisterUnique(IOHelper); Composition.RegisterUnique(UriUtility); @@ -427,16 +429,6 @@ namespace Umbraco.Tests.Testing Composition.Register(x => Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); Composition.Register(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); Composition.Register(x => Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); - - // TODO: remove this once legacy config is fully extracted. - Composition.Configs.Add(() => TestHelpers.SettingsForTests.DefaultGlobalSettings); - Composition.Configs.Add(() => TestHelpers.SettingsForTests.DefaultHostingSettings); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockRequestHandlerSettings); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockSecuritySettings); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockUserPasswordConfiguration); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockMemberPasswordConfiguration); - Composition.Configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings); } protected virtual void ComposeApplication(bool withApplication) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 06b2d7b421..1bec3d04f1 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -156,11 +156,6 @@ namespace Umbraco.Extensions settings.EnableTours = false; }); - // TODO: remove this once no longer requred in Umbraco.Web. - var configsFactory = new AspNetCoreConfigsFactory(configuration); - var configs = configsFactory.Create(); - services.AddSingleton(configs); - return services; } @@ -235,7 +230,7 @@ namespace Umbraco.Extensions AppCaches appCaches, ILoggingConfiguration loggingConfiguration, //TODO: Yep that's extremely ugly - Func getRuntime, + Func getRuntime, out IFactory factory) { if (services is null) throw new ArgumentNullException(nameof(services)); @@ -280,9 +275,7 @@ namespace Umbraco.Extensions var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); - var configs = serviceProvider.GetService(); var coreRuntime = getRuntime( - configs, globalSettings.CurrentValue, connectionStrings.Value, umbracoVersion, @@ -316,8 +309,8 @@ namespace Umbraco.Extensions } private static IRuntime GetCoreRuntime( - Configs configs, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, Core.Logging.ILogger logger, - IProfiler profiler, Core.Hosting.IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, + GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, + IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, ITypeFinder typeFinder, AppCaches appCaches, IDbProviderFactoryCreator dbProviderFactoryCreator) { // Determine if we should use the sql main dom or the default @@ -331,7 +324,6 @@ namespace Umbraco.Extensions var mainDom = new MainDom(logger, mainDomLock); var coreRuntime = new CoreRuntime( - configs, globalSettings, connectionStrings, umbracoVersion, diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 679fb7987c..6d177651dc 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -6,6 +6,7 @@ using System.Web.Routing; using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Infrastructure.Configuration; using Umbraco.Web.WebApi; @@ -42,7 +43,7 @@ namespace Umbraco.Web.Mvc /// /// internal static Route RouteControllerPlugin(this AreaRegistration area, - IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, string controllerName, Type controllerType, RouteCollection routes, string controllerSuffixName, string defaultAction, object defaultId, string umbracoTokenValue = "backoffice", @@ -58,7 +59,7 @@ namespace Umbraco.Web.Mvc if (routes == null) throw new ArgumentNullException(nameof(routes)); if (defaultId == null) throw new ArgumentNullException(nameof(defaultId)); - var umbracoArea = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoArea = globalSettings.GetUmbracoMvcArea(hostingEnvironment); //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 677ae18a1e..bbb2078b10 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,5 +1,6 @@ using System.Web.Mvc; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Editors; @@ -9,10 +10,10 @@ namespace Umbraco.Web.Mvc // TODO: This has been ported to netcore, can be removed internal class BackOfficeArea : AreaRegistration { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - public BackOfficeArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public BackOfficeArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; @@ -49,6 +50,6 @@ namespace Umbraco.Web.Mvc new[] {typeof (BackOfficeController).Namespace}); } - public override string AreaName => ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetUmbracoMvcArea(_hostingEnvironment); + public override string AreaName => _globalSettings.GetUmbracoMvcArea(_hostingEnvironment); } } diff --git a/src/Umbraco.Web/Mvc/PluginControllerArea.cs b/src/Umbraco.Web/Mvc/PluginControllerArea.cs index 838e304847..a4440ec4a6 100644 --- a/src/Umbraco.Web/Mvc/PluginControllerArea.cs +++ b/src/Umbraco.Web/Mvc/PluginControllerArea.cs @@ -6,6 +6,7 @@ using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Web.WebApi; @@ -17,7 +18,7 @@ namespace Umbraco.Web.Mvc /// internal class PluginControllerArea : AreaRegistration { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IEnumerable _surfaceControllers; private readonly IEnumerable _apiControllers; @@ -30,7 +31,7 @@ namespace Umbraco.Web.Mvc /// /// /// - public PluginControllerArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) + public PluginControllerArea(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable pluginControllers) { _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; diff --git a/src/Umbraco.Web/RoutableDocumentFilter.cs b/src/Umbraco.Web/RoutableDocumentFilter.cs index 43e47a39b3..3580e25c78 100644 --- a/src/Umbraco.Web/RoutableDocumentFilter.cs +++ b/src/Umbraco.Web/RoutableDocumentFilter.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Collections.Concurrent; using Umbraco.Core.Collections; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Composing; @@ -22,14 +23,14 @@ namespace Umbraco.Web /// public sealed class RoutableDocumentFilter { - public RoutableDocumentFilter(IGlobalSettings globalSettings, IIOHelper ioHelper) + public RoutableDocumentFilter(GlobalSettings globalSettings, IIOHelper ioHelper) { _globalSettings = globalSettings; _ioHelper = ioHelper; } private static readonly ConcurrentDictionary RouteChecks = new ConcurrentDictionary(); - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private object _locker = new object(); private bool _isInit = false; diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index 4c66322cde..15261a2d6f 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -8,6 +8,7 @@ using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Strings; using Umbraco.Infrastructure.Configuration; @@ -23,7 +24,7 @@ namespace Umbraco.Web.Runtime private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly SurfaceControllerTypeCollection _surfaceControllerTypes; private readonly UmbracoApiControllerTypeCollection _apiControllerTypes; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; @@ -31,7 +32,7 @@ namespace Umbraco.Web.Runtime IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper) { @@ -109,13 +110,13 @@ namespace Umbraco.Web.Runtime // internal for tests internal static void CreateRoutes( IUmbracoContextAccessor umbracoContextAccessor, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IShortStringHelper shortStringHelper, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) { - var umbracoPath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); // create the front-end route var defaultRoute = RouteTable.Routes.MapRoute( @@ -147,12 +148,12 @@ namespace Umbraco.Web.Runtime } private static void RoutePluginControllers( - IGlobalSettings globalSettings, + GlobalSettings globalSettings, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IHostingEnvironment hostingEnvironment) { - var umbracoPath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); // need to find the plugin controllers and route them var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray(); diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 37e2522d43..989dcfaf83 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -3,12 +3,13 @@ using System.Web; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Runtime; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Runtime; +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; namespace Umbraco.Web { @@ -17,14 +18,10 @@ namespace Umbraco.Web /// public class UmbracoApplication : UmbracoApplicationBase { - protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + protected override IRuntime GetRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { - var connectionStringConfig = configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; - var dbProviderFactoryCreator = new UmbracoDbProviderFactoryCreator(); - var globalSettings = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(configs.Global()); - var connectionStrings = ConfigModelConversionsFromLegacy.ConvertConnectionStrings(configs.ConnectionStrings()); // Determine if we should use the sql main dom or the default var appSettingMainDomLock = globalSettings.MainDomLock; @@ -43,7 +40,7 @@ namespace Umbraco.Web new IsolatedCaches(type => new DeepCloneAppCache(new ObjectCacheAppCache()))); var umbracoBootPermissionChecker = new AspNetUmbracoBootPermissionChecker(); - return new CoreRuntime(configs, globalSettings, connectionStrings,umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, + return new CoreRuntime(globalSettings, connectionStrings,umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, GetTypeFinder(hostingEnvironment, logger, profiler), appCaches); } diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 8599464bd1..330f64cced 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -4,11 +4,13 @@ using System.Reflection; using System.Threading; using System.Web; using System.Web.Hosting; +using Microsoft.Extensions.Options; using Serilog.Context; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -18,6 +20,7 @@ using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Web.Hosting; using Umbraco.Web.Logging; +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Web @@ -27,6 +30,9 @@ namespace Umbraco.Web /// public abstract class UmbracoApplicationBase : HttpApplication { + private readonly SecuritySettings _securitySettings; + private readonly GlobalSettings _globalSettings; + private readonly ConnectionStrings _connectionStrings; private IRuntime _runtime; private IFactory _factory; @@ -38,6 +44,7 @@ namespace Umbraco.Web var hostingSettings = configFactory.HostingSettings; var globalSettings = configFactory.GlobalSettings; + var securitySettings = configFactory.SecuritySettings; var hostingEnvironment = new AspNetHostingEnvironment(hostingSettings); var loggingConfiguration = new LoggingConfiguration( @@ -49,9 +56,13 @@ namespace Umbraco.Web var configs = configFactory.Create(); + var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, configFactory.WebRoutingSettings); var profiler = GetWebProfiler(hostingEnvironment); - Umbraco.Composing.Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler); + Umbraco.Composing.Current.Initialize(logger, + ConfigModelConversionsFromLegacy.ConvertSecuritySettings(securitySettings), + ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings), + ioHelper, hostingEnvironment, backOfficeInfo, profiler); Logger = logger; } } @@ -72,12 +83,16 @@ namespace Umbraco.Web return webProfiler; } - protected UmbracoApplicationBase(ILogger logger, Configs configs, IIOHelper ioHelper, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + protected UmbracoApplicationBase(ILogger logger, SecuritySettings securitySettings, GlobalSettings globalSettings, ConnectionStrings connectionStrings, IIOHelper ioHelper, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { + _securitySettings = securitySettings; + _globalSettings = globalSettings; + _connectionStrings = connectionStrings; + if (!Umbraco.Composing.Current.IsInitialized) { Logger = logger; - Umbraco.Composing.Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler); + Umbraco.Composing.Current.Initialize(logger, securitySettings, globalSettings, ioHelper, hostingEnvironment, backOfficeInfo, profiler); } } @@ -120,14 +135,14 @@ namespace Umbraco.Web /// /// Gets a runtime. /// - protected abstract IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo); + protected abstract IRuntime GetRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo); /// /// Gets the application register. /// - protected virtual IRegister GetRegister(IGlobalSettings globalSettings) + protected virtual IRegister GetRegister(GlobalSettings globalSettings) { - return RegisterFactory.Create(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)); + return RegisterFactory.Create(globalSettings); } // events - in the order they trigger @@ -159,14 +174,15 @@ namespace Umbraco.Web // ******** THIS IS WHERE EVERYTHING BEGINS ******** - var globalSettings = Umbraco.Composing.Current.Configs.Global(); + var globalSettings = _globalSettings; var umbracoVersion = new UmbracoVersion(); // create the register for the application, and boot // the boot manager is responsible for registrations var register = GetRegister(globalSettings); _runtime = GetRuntime( - Umbraco.Composing.Current.Configs, + _globalSettings, + _connectionStrings, umbracoVersion, Umbraco.Composing.Current.IOHelper, Umbraco.Composing.Current.Logger, diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 73ee4a377e..563435e9f9 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -2,6 +2,7 @@ using System; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Infrastructure.Configuration; @@ -18,7 +19,7 @@ namespace Umbraco.Web public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd, IUmbracoContext { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly ICookieManager _cookieManager; private readonly Lazy _publishedSnapshot; @@ -32,7 +33,7 @@ namespace Umbraco.Web internal UmbracoContext(IHttpContextAccessor httpContextAccessor, IPublishedSnapshotService publishedSnapshotService, IWebSecurity webSecurity, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IVariationContextAccessor variationContextAccessor, UriUtility uriUtility, @@ -182,7 +183,7 @@ namespace Umbraco.Web { var request = GetRequestFromContext(); if (request?.Url != null - && request.Url.IsBackOfficeRequest(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings), _hostingEnvironment) == false + && request.Url.IsBackOfficeRequest(_globalSettings, _hostingEnvironment) == false && Security.CurrentUser != null) { var previewToken = _cookieManager.GetPreviewCookieValue(); // may be null or empty diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index bfb4dd627d..4eba56c36f 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -20,7 +21,7 @@ namespace Umbraco.Web private readonly IVariationContextAccessor _variationContextAccessor; private readonly IDefaultCultureAccessor _defaultCultureAccessor; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUserService _userService; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; @@ -35,7 +36,7 @@ namespace Umbraco.Web IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IUserService userService, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, From 7f892991500fa0fd98425d3d1d347eb3ae41903c Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 10 Sep 2020 09:04:17 +0200 Subject: [PATCH 37/58] Fixed tests --- .../UrlProviderWithHideTopLevelNodeFromPathTests.cs | 13 +++++++++---- .../TestHelpers/TestWithDatabaseBase.cs | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs index a5bbdd1f7c..e6774076bf 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs @@ -7,6 +7,7 @@ using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Testing; +using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; namespace Umbraco.Tests.Routing @@ -15,11 +16,15 @@ namespace Umbraco.Tests.Routing [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] public class UrlProviderWithHideTopLevelNodeFromPathTests : BaseUrlProviderTest { - private readonly GlobalSettings _globalSettings; + private GlobalSettings _globalSettings; - public UrlProviderWithHideTopLevelNodeFromPathTests() + public override void SetUp() { _globalSettings = new GlobalSettingsBuilder().WithHideTopLevelNodeFromPath(HideTopLevelNodeFromPath).Build(); + base.SetUp(); + PublishedSnapshotService = CreatePublishedSnapshotService(_globalSettings); + + } protected override bool HideTopLevelNodeFromPath => true; @@ -42,8 +47,8 @@ namespace Umbraco.Tests.Routing { var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(true).Build(); - var snapshotService = CreatePublishedSnapshotService(_globalSettings); - var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings,snapshotService:snapshotService); + + var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings, snapshotService:PublishedSnapshotService); var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var urlProvider = new DefaultUrlProvider( Microsoft.Extensions.Options.Options.Create(requestHandlerSettings), diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 6e133778bb..54123ad78b 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -244,7 +244,7 @@ namespace Umbraco.Tests.TestHelpers { var cache = NoAppCache.Instance; - ContentTypesCache = new PublishedContentTypeCache( + ContentTypesCache ??= new PublishedContentTypeCache( Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), From a4e5029912611383f75a4380b27db8313d1e004f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 10 Sep 2020 13:51:59 +0200 Subject: [PATCH 38/58] Refactored to remove Configs --- .../AspNetCoreConfigsFactory.cs | 48 ------ src/Umbraco.Configuration/ConfigsFactory.cs | 126 +++++++------- src/Umbraco.Core/Configuration/Configs.cs | 65 -------- .../Configuration/ConfigsExtensions.cs | 28 ---- .../Configuration/IConfigsFactory.cs | 10 -- .../LuceneFileSystemDirectoryFactory.cs | 8 +- .../UmbracoServiceProviderFactory.cs | 4 +- .../ConfigsExtensions.cs | 19 --- .../Umbraco.ModelsBuilder.Embedded.csproj | 1 - src/Umbraco.Tests.Common/TestHelperBase.cs | 4 +- .../Components/ComponentTests.cs | 1 - src/Umbraco.Tests/Models/VariationTests.cs | 8 +- .../Routing/RenderRouteHandlerTests.cs | 5 +- .../Runtimes/CoreRuntimeTests.cs | 9 - src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 2 - src/Umbraco.Tests/TestHelpers/TestHelper.cs | 4 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- .../Controllers/BackOfficeController.cs | 5 +- .../UmbracoAuthorizedApiController.cs | 2 +- .../CheckIfUserTicketDataIsStaleAttribute.cs | 155 ++++++++++++++++++ .../SetAngularAntiForgeryTokensAttribute.cs | 43 +++-- .../Filters/HttpResponseExceptionFilter.cs | 1 - .../Filters/JsonExceptionFilterAttribute.cs | 2 +- .../AspNet/AspNetRequestAccessor.cs | 8 +- src/Umbraco.Web/Composing/Current.cs | 2 - .../Editors/AuthenticationController.cs | 6 +- .../Editors/BackOfficeController.cs | 9 +- src/Umbraco.Web/Mvc/RenderMvcController.cs | 4 +- .../Mvc/StatusCodeFilterAttribute.cs | 29 ---- .../Mvc/UmbracoAuthorizeAttribute.cs | 2 +- .../Mvc/UmbracoAuthorizedController.cs | 6 +- src/Umbraco.Web/Mvc/UmbracoController.cs | 8 +- .../Mvc/UmbracoRequireHttpsAttribute.cs | 4 +- .../Mvc/UmbracoViewPageOfTModel.cs | 16 +- src/Umbraco.Web/PublishedContentExtensions.cs | 10 +- .../Security/AppBuilderExtensions.cs | 3 +- .../Security/AuthenticationExtensions.cs | 13 +- .../Security/ExternalSignInAutoLinkOptions.cs | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 3 - src/Umbraco.Web/UmbracoApplicationBase.cs | 17 +- src/Umbraco.Web/UmbracoModule.cs | 2 +- src/Umbraco.Web/UmbracoWebService.cs | 3 +- .../CheckIfUserTicketDataIsStaleAttribute.cs | 128 --------------- .../SetAngularAntiForgeryTokensAttribute.cs | 59 ------- .../WebApi/UmbracoAuthorizedApiController.cs | 2 +- 45 files changed, 334 insertions(+), 554 deletions(-) delete mode 100644 src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs delete mode 100644 src/Umbraco.Core/Configuration/Configs.cs delete mode 100644 src/Umbraco.Core/Configuration/ConfigsExtensions.cs delete mode 100644 src/Umbraco.Core/Configuration/IConfigsFactory.cs delete mode 100644 src/Umbraco.ModelsBuilder.Embedded/ConfigsExtensions.cs create mode 100644 src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs delete mode 100644 src/Umbraco.Web/Mvc/StatusCodeFilterAttribute.cs delete mode 100644 src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs delete mode 100644 src/Umbraco.Web/WebApi/Filters/SetAngularAntiForgeryTokensAttribute.cs diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs deleted file mode 100644 index f957074881..0000000000 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Configuration.Models; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; -using CoreDebugSettings = Umbraco.Configuration.Models.CoreDebugSettings; - -namespace Umbraco.Configuration -{ - public class AspNetCoreConfigsFactory : IConfigsFactory - { - private readonly IConfiguration _configuration; - - public AspNetCoreConfigsFactory(IConfiguration configuration) - { - _configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration)); - } - - public Configs Create() - { - var configs = new Configs(); - - configs.Add(() => new TourSettings(_configuration)); - configs.Add(() => new CoreDebugSettings(_configuration)); - configs.Add(() => new RequestHandlerSettings(_configuration)); - configs.Add(() => new SecuritySettings(_configuration)); - configs.Add(() => new UserPasswordConfigurationSettings(_configuration)); - configs.Add(() => new MemberPasswordConfigurationSettings(_configuration)); - configs.Add(() => new KeepAliveSettings(_configuration)); - configs.Add(() => new ContentSettings(_configuration)); - configs.Add(() => new HealthChecksSettings(_configuration)); - configs.Add(() => new LoggingSettings(_configuration)); - configs.Add(() => new ExceptionFilterSettings(_configuration)); - configs.Add(() => new ActiveDirectorySettings(_configuration)); - configs.Add(() => new RuntimeSettings(_configuration)); - configs.Add(() => new TypeFinderSettings(_configuration)); - configs.Add(() => new NuCacheSettings(_configuration)); - configs.Add(() => new WebRoutingSettings(_configuration)); - configs.Add(() => new IndexCreatorSettings(_configuration)); - configs.Add(() => new ModelsBuilderConfig(_configuration)); - configs.Add(() => new HostingSettings(_configuration)); - configs.Add(() => new GlobalSettings(_configuration)); - configs.Add(() => new ImagingSettings(_configuration)); - - return configs; - } - } -} diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs index be6cee2d0c..15378a5860 100644 --- a/src/Umbraco.Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Configuration/ConfigsFactory.cs @@ -1,63 +1,63 @@ -using Umbraco.Configuration; -using Umbraco.Configuration.Implementations; -using Umbraco.Configuration.Legacy; -using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.Legacy; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Core.Configuration -{ - public class ConfigsFactory : IConfigsFactory - { - public IHostingSettings HostingSettings { get; } = new HostingSettings(); - public ICoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); - public IIndexCreatorSettings IndexCreatorSettings { get; } = new IndexCreatorSettings(); - public INuCacheSettings NuCacheSettings { get; } = new NuCacheSettings(); - public ITypeFinderSettings TypeFinderSettings { get; } = new TypeFinderSettings(); - public IRuntimeSettings RuntimeSettings { get; } = new RuntimeSettings(); - public IActiveDirectorySettings ActiveDirectorySettings { get; } = new ActiveDirectorySettings(); - public IExceptionFilterSettings ExceptionFilterSettings { get; } = new ExceptionFilterSettings(); - public ITourSettings TourSettings { get; } = new TourSettings(); - public ILoggingSettings LoggingSettings { get; } = new LoggingSettings(); - public IKeepAliveSettings KeepAliveSettings { get; } = new KeepAliveSettings(); - public IWebRoutingSettings WebRoutingSettings { get; } = new WebRoutingSettings(); - public IRequestHandlerSettings RequestHandlerSettings { get; } = new RequestHandlerSettings(); - public ISecuritySettings SecuritySettings { get; } = new SecuritySettings(); - public IUserPasswordConfiguration UserPasswordConfigurationSettings { get; } = new UserPasswordConfigurationSettings(); - public IMemberPasswordConfiguration MemberPasswordConfigurationSettings { get; } = new MemberPasswordConfigurationSettings(); - public IContentSettings ContentSettings { get; } = new ContentSettings(); - public IGlobalSettings GlobalSettings { get; } = new GlobalSettings(); - public IHealthChecksSettings HealthChecksSettings { get; } = new HealthChecksSettings(); - public IConnectionStrings ConnectionStrings { get; } = new ConnectionStrings(); - public IModelsBuilderConfig ModelsBuilderConfig { get; } = new ModelsBuilderConfig(); - - public Configs Create() - { - var configs = new Configs(); - - configs.Add(() => GlobalSettings); - configs.Add(() => HostingSettings); - configs.Add(() => HealthChecksSettings); - configs.Add(() => CoreDebugSettings); - configs.Add(() => ConnectionStrings); - configs.Add(() => ModelsBuilderConfig); - configs.Add(() => IndexCreatorSettings); - configs.Add(() => NuCacheSettings); - configs.Add(() => TypeFinderSettings); - configs.Add(() => RuntimeSettings); - configs.Add(() => ActiveDirectorySettings); - configs.Add(() => ExceptionFilterSettings); - configs.Add(() => TourSettings); - configs.Add(() => LoggingSettings); - configs.Add(() => KeepAliveSettings); - configs.Add(() => WebRoutingSettings); - configs.Add(() => RequestHandlerSettings); - configs.Add(() => SecuritySettings); - configs.Add(() => UserPasswordConfigurationSettings); - configs.Add(() => MemberPasswordConfigurationSettings); - configs.Add(() => ContentSettings); - - return configs; - } - } -} +// using Umbraco.Configuration; +// using Umbraco.Configuration.Implementations; +// using Umbraco.Configuration.Legacy; +// using Umbraco.Core.Configuration.HealthChecks; +// using Umbraco.Core.Configuration.Legacy; +// using Umbraco.Core.Configuration.UmbracoSettings; +// +// namespace Umbraco.Core.Configuration +// { +// public class ConfigsFactory : IConfigsFactory +// { +// public IHostingSettings HostingSettings { get; } = new HostingSettings(); +// public ICoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); +// public IIndexCreatorSettings IndexCreatorSettings { get; } = new IndexCreatorSettings(); +// public INuCacheSettings NuCacheSettings { get; } = new NuCacheSettings(); +// public ITypeFinderSettings TypeFinderSettings { get; } = new TypeFinderSettings(); +// public IRuntimeSettings RuntimeSettings { get; } = new RuntimeSettings(); +// public IActiveDirectorySettings ActiveDirectorySettings { get; } = new ActiveDirectorySettings(); +// public IExceptionFilterSettings ExceptionFilterSettings { get; } = new ExceptionFilterSettings(); +// public ITourSettings TourSettings { get; } = new TourSettings(); +// public ILoggingSettings LoggingSettings { get; } = new LoggingSettings(); +// public IKeepAliveSettings KeepAliveSettings { get; } = new KeepAliveSettings(); +// public IWebRoutingSettings WebRoutingSettings { get; } = new WebRoutingSettings(); +// public IRequestHandlerSettings RequestHandlerSettings { get; } = new RequestHandlerSettings(); +// public ISecuritySettings SecuritySettings { get; } = new SecuritySettings(); +// public IUserPasswordConfiguration UserPasswordConfigurationSettings { get; } = new UserPasswordConfigurationSettings(); +// public IMemberPasswordConfiguration MemberPasswordConfigurationSettings { get; } = new MemberPasswordConfigurationSettings(); +// public IContentSettings ContentSettings { get; } = new ContentSettings(); +// public IGlobalSettings GlobalSettings { get; } = new GlobalSettings(); +// public IHealthChecksSettings HealthChecksSettings { get; } = new HealthChecksSettings(); +// public IConnectionStrings ConnectionStrings { get; } = new ConnectionStrings(); +// public IModelsBuilderConfig ModelsBuilderConfig { get; } = new ModelsBuilderConfig(); +// +// public Configs Create() +// { +// var configs = new Configs(); +// +// configs.Add(() => GlobalSettings); +// configs.Add(() => HostingSettings); +// configs.Add(() => HealthChecksSettings); +// configs.Add(() => CoreDebugSettings); +// configs.Add(() => ConnectionStrings); +// configs.Add(() => ModelsBuilderConfig); +// configs.Add(() => IndexCreatorSettings); +// configs.Add(() => NuCacheSettings); +// configs.Add(() => TypeFinderSettings); +// configs.Add(() => RuntimeSettings); +// configs.Add(() => ActiveDirectorySettings); +// configs.Add(() => ExceptionFilterSettings); +// configs.Add(() => TourSettings); +// configs.Add(() => LoggingSettings); +// configs.Add(() => KeepAliveSettings); +// configs.Add(() => WebRoutingSettings); +// configs.Add(() => RequestHandlerSettings); +// configs.Add(() => SecuritySettings); +// configs.Add(() => UserPasswordConfigurationSettings); +// configs.Add(() => MemberPasswordConfigurationSettings); +// configs.Add(() => ContentSettings); +// +// return configs; +// } +// } +// } diff --git a/src/Umbraco.Core/Configuration/Configs.cs b/src/Umbraco.Core/Configuration/Configs.cs deleted file mode 100644 index 821ee308f0..0000000000 --- a/src/Umbraco.Core/Configuration/Configs.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using Umbraco.Core.Composing; - -namespace Umbraco.Core.Configuration -{ - /// - /// Represents Umbraco configurations. - /// - /// - /// During composition, use composition.Configs. When running, either inject the required configuration, - /// or use Current.Configs. - /// - public class Configs - { - private readonly Dictionary> _configs = new Dictionary>(); - private Dictionary> _registerings = new Dictionary>(); - - /// - /// Gets a configuration. - /// - public TConfig GetConfig() - where TConfig : class - { - if (!_configs.TryGetValue(typeof(TConfig), out var configFactory)) - throw new InvalidOperationException($"No configuration of type {typeof(TConfig)} has been added."); - - return (TConfig) configFactory.Value; - } - - /// - /// Adds a configuration, provided by a factory. - /// - public void Add(Func configFactory) - where TConfig : class - { - // make sure it is not too late - if (_registerings == null) - throw new InvalidOperationException("Configurations have already been registered."); - - var typeOfConfig = typeof(TConfig); - - var lazyConfigFactory = _configs[typeOfConfig] = new Lazy(configFactory); - _registerings[typeOfConfig] = register => register.Register(_ => (TConfig) lazyConfigFactory.Value, Lifetime.Singleton); - } - - /// - /// Registers configurations in a register. - /// - public void RegisterWith(IRegister register) - { - // do it only once - if (_registerings == null) - throw new InvalidOperationException("Configurations have already been registered."); - - register.Register(this); - - foreach (var registering in _registerings.Values) - registering(register); - - // no need to keep them around - _registerings = null; - } - } -} diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs deleted file mode 100644 index 0f63903320..0000000000 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Core -{ - /// - /// Provides extension methods for the class. - /// - public static class ConfigsExtensions - { - - public static IGlobalSettings Global(this Configs configs) - => configs.GetConfig(); - - - public static IConnectionStrings ConnectionStrings(this Configs configs) - => configs.GetConfig(); - - public static ISecuritySettings Security(this Configs configs) - => configs.GetConfig(); - - public static IWebRoutingSettings WebRouting(this Configs configs) - => configs.GetConfig(); - - } -} diff --git a/src/Umbraco.Core/Configuration/IConfigsFactory.cs b/src/Umbraco.Core/Configuration/IConfigsFactory.cs deleted file mode 100644 index dd2459b88c..0000000000 --- a/src/Umbraco.Core/Configuration/IConfigsFactory.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Umbraco.Core.IO; -using Umbraco.Core.Logging; - -namespace Umbraco.Core.Configuration -{ - public interface IConfigsFactory - { - Configs Create(); - } -} diff --git a/src/Umbraco.Examine.Lucene/LuceneFileSystemDirectoryFactory.cs b/src/Umbraco.Examine.Lucene/LuceneFileSystemDirectoryFactory.cs index 8f3bf8bf69..32c441ab28 100644 --- a/src/Umbraco.Examine.Lucene/LuceneFileSystemDirectoryFactory.cs +++ b/src/Umbraco.Examine.Lucene/LuceneFileSystemDirectoryFactory.cs @@ -6,6 +6,8 @@ using Lucene.Net.Store; using System.IO; using System; using Examine.LuceneEngine.Directories; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Examine { @@ -14,13 +16,13 @@ namespace Umbraco.Examine { private readonly ITypeFinder _typeFinder; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IIndexCreatorSettings _settings; + private readonly IndexCreatorSettings _settings; - public LuceneFileSystemDirectoryFactory(ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IIndexCreatorSettings settings) + public LuceneFileSystemDirectoryFactory(ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IOptions settings) { _typeFinder = typeFinder; _hostingEnvironment = hostingEnvironment; - _settings = settings; + _settings = settings.Value; } public Lucene.Net.Store.Directory CreateDirectory(string indexName) => CreateFileSystemLuceneDirectory(indexName); diff --git a/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs b/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs index 51bd5e7b14..6bd0d796ec 100644 --- a/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs +++ b/src/Umbraco.Infrastructure/Composing/UmbracoServiceProviderFactory.cs @@ -88,8 +88,8 @@ namespace Umbraco.Core.Composing // after cross wiring, configure "Current" Current.Initialize( _container.GetInstance(), - _container.GetInstance(), - _container.GetInstance(), + _container.GetInstance>().Value, + _container.GetInstance>().Value, _container.GetInstance(), _container.GetInstance(), _container.GetInstance(), diff --git a/src/Umbraco.ModelsBuilder.Embedded/ConfigsExtensions.cs b/src/Umbraco.ModelsBuilder.Embedded/ConfigsExtensions.cs deleted file mode 100644 index d625c754c5..0000000000 --- a/src/Umbraco.ModelsBuilder.Embedded/ConfigsExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Umbraco.Core.Configuration; - -namespace Umbraco.ModelsBuilder.Embedded -{ - /// - /// Provides extension methods for the class. - /// - public static class ConfigsExtensions - { - /// - /// Gets the models builder configuration. - /// - /// Getting the models builder configuration freezes its state, - /// and any attempt at modifying the configuration using the Setup method - /// will be ignored. - public static IModelsBuilderConfig ModelsBuilder(this Configs configs) - => configs.GetConfig(); - } -} diff --git a/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj b/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj index 87c20eca72..608770b124 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj +++ b/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj @@ -58,7 +58,6 @@ - diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 803b6c0cae..234767e8af 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -46,11 +46,11 @@ namespace Umbraco.Tests.Common return new TypeLoader(Mock.Of(), Mock.Of(), new DirectoryInfo(IOHelper.MapPath("~/App_Data/TEMP")), Mock.Of()); } - public Configs GetConfigs() => GetConfigsFactory().Create(); + // public Configs GetConfigs() => GetConfigsFactory().Create(); public abstract IBackOfficeInfo GetBackOfficeInfo(); - public IConfigsFactory GetConfigsFactory() => new ConfigsFactory(); + //public IConfigsFactory GetConfigsFactory() => new ConfigsFactory(); /// /// Gets the working directory of the test project. diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index de99ba445f..e74516dab7 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -25,7 +25,6 @@ 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 = TestHelper.GetConfigs(); private static IFactory MockFactory(Action> setup = null) { diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index e67cb10cf1..1c7445a901 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -33,9 +33,9 @@ namespace Umbraco.Tests.Models Current.Reset(); - var configs = TestHelper.GetConfigs(); - configs.Add(() => SettingsForTests.DefaultGlobalSettings); - configs.Add(SettingsForTests.GenerateMockContentSettings); + // var configs = TestHelper.GetConfigs(); + // configs.Add(() => SettingsForTests.DefaultGlobalSettings); + // configs.Add(SettingsForTests.GenerateMockContentSettings); _factory = Mock.Of(); @@ -65,7 +65,7 @@ namespace Umbraco.Tests.Models .Setup(x => x.GetInstance(It.IsAny())) .Returns(x => { - if (x == typeof(Configs)) return configs; + //if (x == typeof(Configs)) return configs; if (x == typeof(PropertyEditorCollection)) return propertyEditors; if (x == typeof(ServiceContext)) return serviceContext; if (x == typeof(ILocalizedTextService)) return serviceContext.LocalizationService; diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 3328114576..5082919dc1 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Web.Mvc; using System.Web.Routing; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -153,7 +154,7 @@ namespace Umbraco.Tests.Routing var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of(), context => { - return new CustomDocumentController(Factory.GetInstance(), + return new CustomDocumentController(Factory.GetInstance>(), umbracoContextAccessor, Factory.GetInstance(), Factory.GetInstance(), @@ -194,7 +195,7 @@ namespace Umbraco.Tests.Routing /// public class CustomDocumentController : RenderMvcController { - public CustomDocumentController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + public CustomDocumentController(IOptions globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { } diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 4de83eed4e..1b58c93534 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -100,15 +100,6 @@ namespace Umbraco.Tests.Runtimes private static readonly IContentSettings _contentSettings = SettingsForTests.GenerateMockContentSettings(); private static readonly IWebRoutingSettings _settings = SettingsForTests.GenerateMockWebRoutingSettings(); - private static Configs GetConfigs() - { - var configs = new ConfigsFactory().Create(); - configs.Add(() => _globalSettings); - configs.Add(() => _contentSettings); - configs.Add(() => _hostingSettings); - return configs; - } - public IRuntime Runtime { get; private set; } protected override IRuntime GetRuntime(GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 5f0fc607c6..7c834d7cf3 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -76,7 +76,6 @@ namespace Umbraco.Tests.Runtimes var umbracoVersion = TestHelper.GetUmbracoVersion(); var backOfficeInfo = TestHelper.GetBackOfficeInfo(); var runtimeState = new RuntimeState(globalSettings, umbracoVersion, databaseFactory, logger); - var configs = TestHelper.GetConfigs(); var variationContextAccessor = TestHelper.VariationContextAccessor; // create the register and the composition @@ -285,7 +284,6 @@ namespace Umbraco.Tests.Runtimes Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run); var mainDom = Mock.Of(); Mock.Get(mainDom).Setup(x => x.IsMainDom).Returns(true); - var configs = TestHelper.GetConfigs(); // create the register and the composition var register = TestHelper.GetRegister(); diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 2131393b85..92767498bc 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -78,11 +78,11 @@ namespace Umbraco.Tests.TestHelpers public static TypeLoader GetMockedTypeLoader() => _testHelperInternal.GetMockedTypeLoader(); - public static Configs GetConfigs() => _testHelperInternal.GetConfigs(); + //public static Configs GetConfigs() => _testHelperInternal.GetConfigs(); public static IBackOfficeInfo GetBackOfficeInfo() => _testHelperInternal.GetBackOfficeInfo(); - public static IConfigsFactory GetConfigsFactory() => _testHelperInternal.GetConfigsFactory(); + // public static IConfigsFactory GetConfigsFactory() => _testHelperInternal.GetConfigsFactory(); /// /// Gets the working directory of the test project. diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 3d2a4496a6..ccac76fc88 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -191,7 +191,7 @@ namespace Umbraco.Tests.Testing Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.IOHelper, AppCaches.NoCache); - TestHelper.GetConfigs().RegisterWith(register); + //TestHelper.GetConfigs().RegisterWith(register); Composition.RegisterUnique(IOHelper); diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index e3480984fd..141578cccd 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -30,7 +30,8 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.BackOffice.Controllers { - + //[UmbracoRequireHttps] //TODO Reintroduce + [DisableBrowserCache] [PluginController(Constants.Web.Mvc.BackOfficeArea)] public class BackOfficeController : Controller { @@ -80,7 +81,7 @@ namespace Umbraco.Web.BackOffice.Controllers { var viewPath = Path.Combine(_globalSettings.UmbracoPath , Constants.Web.Mvc.BackOfficeArea, nameof(Default) + ".cshtml") .Replace("\\", "/"); // convert to forward slashes since it's a virtual path - + return await RenderDefaultOrProcessExternalLoginAsync( () => View(viewPath), () => View(viewPath)); diff --git a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs index c3e1a71b86..85c92d1139 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.BackOffice.Controllers [UmbracoAuthorize] [DisableBrowserCache] [UmbracoWebApiRequireHttps] - //[CheckIfUserTicketDataIsStale] //TODO reintroduce + [CheckIfUserTicketDataIsStale] //[UnhandedExceptionLoggerConfiguration] //TODO reintroduce //[EnableDetailedErrors] //TODO reintroduce public abstract class UmbracoAuthorizedApiController : UmbracoApiController diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs new file mode 100644 index 0000000000..c3bc1a56db --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Options; +using Umbraco.Core; +using Umbraco.Core.BackOffice; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Mapping; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Membership; +using Umbraco.Core.Services; +using Umbraco.Extensions; +using Umbraco.Web.BackOffice.Security; +using Umbraco.Web.Common.Security; + +namespace Umbraco.Web.BackOffice.Filters +{ + internal sealed class CheckIfUserTicketDataIsStaleAttribute : TypeFilterAttribute + { + public CheckIfUserTicketDataIsStaleAttribute() : base(typeof(CheckIfUserTicketDataIsStaleFilter)) + { + } + + private class CheckIfUserTicketDataIsStaleFilter : IAsyncActionFilter + { + private readonly IRequestCache _requestCache; + private readonly UmbracoMapper _umbracoMapper; + private readonly IUserService _userService; + private readonly IEntityService _entityService; + private readonly ILocalizedTextService _localizedTextService; + private readonly IOptions _globalSettings; + private readonly BackOfficeSignInManager _backOfficeSignInManager; + private readonly IBackOfficeAntiforgery _backOfficeAntiforgery; + + public CheckIfUserTicketDataIsStaleFilter( + IRequestCache requestCache, + UmbracoMapper umbracoMapper, + IUserService userService, + IEntityService entityService, + ILocalizedTextService localizedTextService, + IOptions globalSettings, + BackOfficeSignInManager backOfficeSignInManager, + IBackOfficeAntiforgery backOfficeAntiforgery) + { + _requestCache = requestCache; + _umbracoMapper = umbracoMapper; + _userService = userService; + _entityService = entityService; + _localizedTextService = localizedTextService; + _globalSettings = globalSettings; + _backOfficeSignInManager = backOfficeSignInManager; + _backOfficeAntiforgery = backOfficeAntiforgery; + } + + + public async Task OnActionExecutionAsync(ActionExecutingContext actionContext, ActionExecutionDelegate next) + { + await CheckStaleData(actionContext); + + await next(); + + await CheckStaleData(actionContext); + + //we need new tokens and append the custom header if changes have been made + if (!(_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null)) + return; + + var tokenFilter = + new SetAngularAntiForgeryTokensAttribute.SetAngularAntiForgeryTokensFilter(_backOfficeAntiforgery, + _globalSettings); + await tokenFilter.OnActionExecutionAsync(actionContext, () => Task.FromResult(new ActionExecutedContext(actionContext, new List(), null))); + + //add the header + AppendUserModifiedHeaderAttribute.AppendHeader(actionContext); + } + + + + private async Task CheckStaleData(ActionExecutingContext actionContext) + { + if (actionContext == null + || actionContext.HttpContext.Request == null + || actionContext.HttpContext.User == null + || actionContext.HttpContext.User.Identity == null) + { + return; + } + + //don't execute if it's already been done + if (!(_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null)) + return; + + var identity = actionContext.HttpContext.User.Identity as UmbracoBackOfficeIdentity; + if (identity == null) return; + + var userId = identity.Id.TryConvertTo(); + if (userId == false) return; + + var user = _userService.GetUserById(userId.Result); + if (user == null) return; + + //a list of checks to execute, if any of them pass then we resync + var checks = new Func[] + { + () => user.Username != identity.Username, + () => + { + var culture = user.GetUserCulture(_localizedTextService, _globalSettings.Value); + return culture != null && culture.ToString() != identity.Culture; + }, + () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, + () => user.Groups.Select(x => x.Alias).UnsortedSequenceEqual(identity.Roles) == false, + () => + { + var startContentIds = user.CalculateContentStartNodeIds(_entityService); + return startContentIds.UnsortedSequenceEqual(identity.StartContentNodes) == false; + }, + () => + { + var startMediaIds = user.CalculateMediaStartNodeIds(_entityService); + return startMediaIds.UnsortedSequenceEqual(identity.StartMediaNodes) == false; + } + }; + + if (checks.Any(check => check())) + { + await ReSync(user, actionContext); + } + } + + /// + /// This will update the current request IPrincipal to be correct and re-create the auth ticket + /// + /// + /// + /// + private async Task ReSync(IUser user, ActionExecutingContext actionContext) + { + var backOfficeIdentityUser = _umbracoMapper.Map(user); + await _backOfficeSignInManager.SignInAsync(backOfficeIdentityUser, isPersistent: true); + + //ensure the remainder of the request has the correct principal set + actionContext.HttpContext.SetPrincipalForRequest(ClaimsPrincipal.Current); + + //flag that we've made changes + _requestCache.Set(nameof(CheckIfUserTicketDataIsStaleFilter), true); + } + } + } +} diff --git a/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs index c993766a6b..aaf23d1799 100644 --- a/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/SetAngularAntiForgeryTokensAttribute.cs @@ -18,7 +18,7 @@ namespace Umbraco.Extensions { } - private class SetAngularAntiForgeryTokensFilter : IAsyncActionFilter + internal class SetAngularAntiForgeryTokensFilter : IAsyncActionFilter { private readonly IBackOfficeAntiforgery _antiforgery; private readonly GlobalSettings _globalSettings; @@ -55,24 +55,31 @@ namespace Umbraco.Extensions //We need to set 2 cookies: one is the cookie value that angular will use to set a header value on each request, // the 2nd is the validation value generated by the anti-forgery helper that we use to validate the header token against. - context.HttpContext.Response.Cookies.Append( - Constants.Web.AngularCookieName, headerToken, - new Microsoft.AspNetCore.Http.CookieOptions - { - Path = "/", - //must be js readable - HttpOnly = false, - Secure = _globalSettings.UseHttps - }); + if (!(headerToken is null)) + { + context.HttpContext.Response.Cookies.Append( + Constants.Web.AngularCookieName, headerToken, + new Microsoft.AspNetCore.Http.CookieOptions + { + Path = "/", + //must be js readable + HttpOnly = false, + Secure = _globalSettings.UseHttps + }); + } + + if (!(cookieToken is null)) + { + context.HttpContext.Response.Cookies.Append( + Constants.Web.CsrfValidationCookieName, cookieToken, + new Microsoft.AspNetCore.Http.CookieOptions + { + Path = "/", + HttpOnly = true, + Secure = _globalSettings.UseHttps + }); + } - context.HttpContext.Response.Cookies.Append( - Constants.Web.CsrfValidationCookieName, cookieToken, - new Microsoft.AspNetCore.Http.CookieOptions - { - Path = "/", - HttpOnly = true, - Secure = _globalSettings.UseHttps - }); } } diff --git a/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs b/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs index 46bfd6cdfa..6a5f6eaa47 100644 --- a/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs +++ b/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using Umbraco.Core.Exceptions; using Umbraco.Web.Common.Exceptions; namespace Umbraco.Web.Common.Filters diff --git a/src/Umbraco.Web.Common/Filters/JsonExceptionFilterAttribute.cs b/src/Umbraco.Web.Common/Filters/JsonExceptionFilterAttribute.cs index 1ff8ede0ab..3d25016c15 100644 --- a/src/Umbraco.Web.Common/Filters/JsonExceptionFilterAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/JsonExceptionFilterAttribute.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.Common.Filters public void OnException(ExceptionContext filterContext) { - if (filterContext.Exception != null) + if (filterContext.Exception != null && !filterContext.ExceptionHandled) { filterContext.HttpContext.Response.StatusCode = (int) HttpStatusCode.InternalServerError; diff --git a/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs b/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs index aa2cba6949..ae38dc2c05 100644 --- a/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs +++ b/src/Umbraco.Web/AspNet/AspNetRequestAccessor.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Web.Routing; @@ -8,13 +10,13 @@ namespace Umbraco.Web.AspNet public class AspNetRequestAccessor : IRequestAccessor { private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; private readonly ISet _applicationUrls = new HashSet(); private Uri _currentApplicationUrl; - public AspNetRequestAccessor(IHttpContextAccessor httpContextAccessor, IWebRoutingSettings webRoutingSettings) + public AspNetRequestAccessor(IHttpContextAccessor httpContextAccessor, IOptions webRoutingSettings) { _httpContextAccessor = httpContextAccessor; - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; UmbracoModule.EndRequest += OnEndRequest; UmbracoModule.RouteAttempt += OnRouteAttempt; diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index 68120947df..9646a10dc4 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -213,8 +213,6 @@ namespace Umbraco.Web.Composing public static TypeLoader TypeLoader => Factory.GetInstance(); - public static Configs Configs => Factory.GetInstance(); - public static UrlSegmentProviderCollection UrlSegmentProviders => Factory.GetInstance(); public static CacheRefresherCollection CacheRefreshers => Factory.GetInstance(); diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index c3eedaab3b..5254b91672 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -111,7 +111,7 @@ namespace Umbraco.Web.Editors /// Used to retrieve the 2FA providers for code submission /// /// - [SetAngularAntiForgeryTokens] + // [SetAngularAntiForgeryTokens] //TODO reintroduce when migrated to netcore public async Task> Get2FAProviders() { var userId = await SignInManager.GetVerifiedUserIdAsync(); @@ -127,7 +127,7 @@ namespace Umbraco.Web.Editors return userFactors; } - [SetAngularAntiForgeryTokens] + // [SetAngularAntiForgeryTokens] //TODO reintroduce when migrated to netcore public async Task PostSend2FACode([FromBody]string provider) { if (provider.IsNullOrWhiteSpace()) @@ -148,7 +148,7 @@ namespace Umbraco.Web.Editors return Ok(); } - [SetAngularAntiForgeryTokens] + // [SetAngularAntiForgeryTokens] //TODO reintroduce when migrated to netcore public async Task PostVerify2FACode(Verify2FACodeModel model) { if (ModelState.IsValid == false) diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 34d6e49563..7e0cd7062b 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -4,10 +4,12 @@ using System.Threading.Tasks; using System.Web; using System.Web.Mvc; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Web.Mvc; using Umbraco.Core.Services; @@ -40,7 +42,7 @@ namespace Umbraco.Web.Editors public BackOfficeController( UmbracoFeatures features, - IGlobalSettings globalSettings, + IOptions globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, @@ -140,7 +142,7 @@ namespace Umbraco.Web.Editors if (defaultResponse == null) throw new ArgumentNullException("defaultResponse"); if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse"); - ViewData.SetUmbracoPath(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(GlobalSettings).GetUmbracoMvcArea(_hostingEnvironment)); + ViewData.SetUmbracoPath(GlobalSettings.Value.GetUmbracoMvcArea(_hostingEnvironment)); //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) || @@ -254,8 +256,7 @@ namespace Umbraco.Web.Editors var groups = Services.UserService.GetUserGroupsByAlias(autoLinkOptions.GetDefaultUserGroups(UmbracoContext, loginInfo)); - var autoLinkUser = BackOfficeIdentityUser.CreateNew( - ConfigModelConversionsFromLegacy.ConvertGlobalSettings(GlobalSettings), + var autoLinkUser = BackOfficeIdentityUser.CreateNew(GlobalSettings.Value, loginInfo.Email, loginInfo.Email, autoLinkOptions.GetDefaultCulture(UmbracoContext, loginInfo)); diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 7286f52c64..be17bf85c2 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -1,7 +1,9 @@ using System; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -25,7 +27,7 @@ namespace Umbraco.Web.Mvc ActionInvoker = new RenderActionInvoker(); } - public RenderMvcController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + public RenderMvcController(IOptions globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { ActionInvoker = new RenderActionInvoker(); diff --git a/src/Umbraco.Web/Mvc/StatusCodeFilterAttribute.cs b/src/Umbraco.Web/Mvc/StatusCodeFilterAttribute.cs deleted file mode 100644 index 727c29b93c..0000000000 --- a/src/Umbraco.Web/Mvc/StatusCodeFilterAttribute.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Net; -using System.Web.Mvc; -using Umbraco.Core; -using Umbraco.Web.Composing; - -namespace Umbraco.Web.Mvc -{ - /// - /// Forces the response to have a specific http status code - /// - /// Migrated already to .Net Core - internal class StatusCodeResultAttribute : ActionFilterAttribute - { - private readonly HttpStatusCode _statusCode; - - public StatusCodeResultAttribute(HttpStatusCode statusCode) - { - _statusCode = statusCode; - } - - public override void OnActionExecuted(ActionExecutedContext filterContext) - { - base.OnActionExecuted(filterContext); - - filterContext.HttpContext.Response.StatusCode = (int)_statusCode; - filterContext.HttpContext.Response.TrySkipIisCustomErrors = Current.Configs.WebRouting().TrySkipIisCustomErrors; - } - } -} diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index d9baa25823..ee3596b7a5 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -56,7 +56,7 @@ namespace Umbraco.Web.Mvc { if (redirectToUmbracoLogin) { - _redirectUrl = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(Current.Configs.Global()).GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); + _redirectUrl = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(/*Current.Configs.Global()*/ null).GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); } } diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs index 0724cd138d..6471656c42 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs @@ -1,5 +1,7 @@ -using Umbraco.Core.Cache; +using Microsoft.Extensions.Options; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Services; @@ -21,7 +23,7 @@ namespace Umbraco.Web.Mvc { } - protected UmbracoAuthorizedController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + protected UmbracoAuthorizedController(IOptions globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { } diff --git a/src/Umbraco.Web/Mvc/UmbracoController.cs b/src/Umbraco.Web/Mvc/UmbracoController.cs index 9cfd93ba9d..940a9521aa 100644 --- a/src/Umbraco.Web/Mvc/UmbracoController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoController.cs @@ -1,12 +1,14 @@ using System; using System.Web; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Microsoft.Owin; using Umbraco.Core.Cache; using Umbraco.Web.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Services; using Umbraco.Web.Security; @@ -23,7 +25,7 @@ namespace Umbraco.Web.Mvc /// /// Gets or sets the Umbraco context. /// - public IGlobalSettings GlobalSettings { get; } + public IOptions GlobalSettings { get; } /// /// Gets the Umbraco context. @@ -69,7 +71,7 @@ namespace Umbraco.Web.Mvc protected UmbracoController() : this( - Current.Factory.GetInstance(), + Current.Factory.GetInstance>(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), @@ -78,7 +80,7 @@ namespace Umbraco.Web.Mvc { } - protected UmbracoController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) + protected UmbracoController(IOptions globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger) { GlobalSettings = globalSettings; UmbracoContextAccessor = umbracoContextAccessor; diff --git a/src/Umbraco.Web/Mvc/UmbracoRequireHttpsAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoRequireHttpsAttribute.cs index 9a0aa6b600..b88d1c0736 100644 --- a/src/Umbraco.Web/Mvc/UmbracoRequireHttpsAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoRequireHttpsAttribute.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Mvc protected override void HandleNonHttpsRequest(AuthorizationContext filterContext) { // If Umbraco.Core.UseHttps is set, let base method handle redirect. Otherwise, we don't care. - if (Current.Configs.Global().UseHttps) + if (/*Current.Configs.Global().UseHttps*/ false) { base.HandleNonHttpsRequest(filterContext); } @@ -29,7 +29,7 @@ namespace Umbraco.Web.Mvc public override void OnAuthorization(AuthorizationContext filterContext) { // If umbracoSSL is set, let base method handle checking for HTTPS. Otherwise, we don't care. - if (Current.Configs.Global().UseHttps) + if (/*Current.Configs.Global().UseHttps*/ false) { base.OnAuthorization(filterContext); } diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index a687e7c9cd..4a651fd04a 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -3,9 +3,11 @@ using System.Text; using System.Web; using System.Web.Mvc; using System.Web.WebPages; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -22,8 +24,8 @@ namespace Umbraco.Web.Mvc /// public abstract class UmbracoViewPage : WebViewPage { - private readonly IGlobalSettings _globalSettings; - private readonly IContentSettings _contentSettings; + private readonly GlobalSettings _globalSettings; + private readonly ContentSettings _contentSettings; private IUmbracoContext _umbracoContext; private UmbracoHelper _helper; @@ -105,18 +107,18 @@ namespace Umbraco.Web.Mvc : this( Current.Factory.GetInstance(), Current.Factory.GetInstance(), - Current.Factory.GetInstance(), - Current.Factory.GetInstance() + Current.Factory.GetInstance>(), + Current.Factory.GetInstance>() ) { } - protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IGlobalSettings globalSettings, IContentSettings contentSettings) + protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IOptions globalSettings, IOptions contentSettings) { Services = services; AppCaches = appCaches; - _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _globalSettings = globalSettings.Value; + _contentSettings = contentSettings.Value; } // view logic below: diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 1dbe6ac556..e132b8fcdd 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -73,8 +73,10 @@ namespace Umbraco.Web { return content.IsAllowedTemplate( Current.Services.ContentTypeService, - Current.Configs.WebRouting().DisableAlternativeTemplates, + /*Current.Configs.WebRouting().DisableAlternativeTemplates, Current.Configs.WebRouting().ValidateAlternativeTemplates, + TODO*/ + false, false, templateId); } @@ -83,8 +85,10 @@ namespace Umbraco.Web return content.IsAllowedTemplate( Current.Services.FileService, Current.Services.ContentTypeService, - Current.Configs.WebRouting().DisableAlternativeTemplates, - Current.Configs.WebRouting().ValidateAlternativeTemplates, + /*Current.Configs.WebRouting().DisableAlternativeTemplates, + Current.Configs.WebRouting().ValidateAlternativeTemplates, + TODO*/ + false, false, templateAlias); } diff --git a/src/Umbraco.Web/Security/AppBuilderExtensions.cs b/src/Umbraco.Web/Security/AppBuilderExtensions.cs index ac5434aa4e..562c46d5e1 100644 --- a/src/Umbraco.Web/Security/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/Security/AppBuilderExtensions.cs @@ -8,6 +8,7 @@ using Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.Composing; using Constants = Umbraco.Core.Constants; @@ -68,7 +69,7 @@ namespace Umbraco.Web.Security CookiePath = "/", CookieSecure = globalSettings.UseHttps ? CookieSecureOption.Always : CookieSecureOption.SameAsRequest, CookieHttpOnly = true, - CookieDomain = Current.Configs.Security().AuthCookieDomain + CookieDomain = new SecuritySettings().AuthCookieDomain // TODO inject settings }, stage); return app; diff --git a/src/Umbraco.Web/Security/AuthenticationExtensions.cs b/src/Umbraco.Web/Security/AuthenticationExtensions.cs index 2b8ba2ddfb..343579fb11 100644 --- a/src/Umbraco.Web/Security/AuthenticationExtensions.cs +++ b/src/Umbraco.Web/Security/AuthenticationExtensions.cs @@ -13,6 +13,7 @@ using Microsoft.Owin.Security; using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.BackOffice; +using Umbraco.Core.Configuration.Models; using Umbraco.Extensions; using Umbraco.Web.Composing; using Constants = Umbraco.Core.Constants; @@ -68,7 +69,7 @@ namespace Umbraco.Web.Security if (ex is FormatException || ex is JsonReaderException) { // this will occur if the cookie data is invalid - + } else { @@ -104,7 +105,7 @@ namespace Umbraco.Web.Security /// /// This will return the current back office identity. /// - /// + /// /// /// Returns the current back office identity if an admin is authenticated otherwise null /// @@ -151,7 +152,7 @@ namespace Umbraco.Web.Security public static AuthenticationTicket GetUmbracoAuthTicket(this HttpContextBase http) { if (http == null) throw new ArgumentNullException(nameof(http)); - return GetAuthTicket(http, Current.Configs.Security().AuthCookieName); + return GetAuthTicket(http, /*Current.Configs.Security() TODO*/new SecuritySettings().AuthCookieName); } internal static AuthenticationTicket GetUmbracoAuthTicket(this HttpContext http) @@ -163,7 +164,7 @@ namespace Umbraco.Web.Security public static AuthenticationTicket GetUmbracoAuthTicket(this IOwinContext ctx) { if (ctx == null) throw new ArgumentNullException(nameof(ctx)); - return GetAuthTicket(ctx, Current.Configs.Security().AuthCookieName); + return GetAuthTicket(ctx, /*Current.Configs.Security() TODO*/new SecuritySettings().AuthCookieName); } private static AuthenticationTicket GetAuthTicket(this IOwinContext owinCtx, string cookieName) @@ -215,7 +216,7 @@ namespace Umbraco.Web.Security catch (Exception) { // occurs when decryption fails - + return null; } } @@ -236,6 +237,6 @@ namespace Umbraco.Web.Security return secureDataFormat.Unprotect(formsCookie); } - + } } diff --git a/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs b/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs index fc84cd270d..72b3f0abe0 100644 --- a/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs +++ b/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Security { _defaultUserGroups = defaultUserGroups ?? new[] { Constants.Security.EditorGroupAlias }; _autoLinkExternalAccount = autoLinkExternalAccount; - _defaultCulture = defaultCulture ?? Current.Configs.Global().DefaultUILanguage; + _defaultCulture = defaultCulture ?? /*Current.Configs.Global().DefaultUILanguage TODO */ "en-US"; } private readonly string[] _defaultUserGroups; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 5d663b64c2..e6c58770c0 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -176,7 +176,6 @@ - @@ -244,7 +243,6 @@ - @@ -298,7 +296,6 @@ - diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 330f64cced..f40a230ae5 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -10,7 +10,9 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Legacy; using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -22,6 +24,7 @@ using Umbraco.Web.Hosting; using Umbraco.Web.Logging; using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; using Current = Umbraco.Web.Composing.Current; +using GlobalSettings = Umbraco.Core.Configuration.Models.GlobalSettings; namespace Umbraco.Web { @@ -40,11 +43,12 @@ namespace Umbraco.Web { if (!Umbraco.Composing.Current.IsInitialized) { - var configFactory = new ConfigsFactory(); + //var configFactory = new ConfigsFactory(); - var hostingSettings = configFactory.HostingSettings; - var globalSettings = configFactory.GlobalSettings; - var securitySettings = configFactory.SecuritySettings; + IHostingSettings hostingSettings = null; + IGlobalSettings globalSettings = null; + ISecuritySettings securitySettings = null; + IWebRoutingSettings webRoutingSettings = null; var hostingEnvironment = new AspNetHostingEnvironment(hostingSettings); var loggingConfiguration = new LoggingConfiguration( @@ -54,10 +58,7 @@ namespace Umbraco.Web var ioHelper = new IOHelper(hostingEnvironment); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration); - var configs = configFactory.Create(); - - - var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, configFactory.WebRoutingSettings); + var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, webRoutingSettings); var profiler = GetWebProfiler(hostingEnvironment); Umbraco.Composing.Current.Initialize(logger, ConfigModelConversionsFromLegacy.ConvertSecuritySettings(securitySettings), diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 2dffe13851..98b6feb9b1 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web else if (pcr.Is404) { response.StatusCode = 404; - response.TrySkipIisCustomErrors = Current.Configs.WebRouting().TrySkipIisCustomErrors; + response.TrySkipIisCustomErrors = /*Current.Configs.WebRouting().TrySkipIisCustomErrors; TODO */ false; if (response.TrySkipIisCustomErrors == false) logger.Warn("Status code is 404 yet TrySkipIisCustomErrors is false - IIS will take over."); diff --git a/src/Umbraco.Web/UmbracoWebService.cs b/src/Umbraco.Web/UmbracoWebService.cs index 916ab5ad8e..b8d69f5b62 100644 --- a/src/Umbraco.Web/UmbracoWebService.cs +++ b/src/Umbraco.Web/UmbracoWebService.cs @@ -6,6 +6,7 @@ using System.Web.Services; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Legacy; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Services; @@ -31,7 +32,7 @@ namespace Umbraco.Web } protected UmbracoWebService() - : this(Current.ProfilingLogger, Current.UmbracoContextAccessor, Current.Services, Current.Configs.Global()) + : this(Current.ProfilingLogger, Current.UmbracoContextAccessor, Current.Services, new GlobalSettings()) { } diff --git a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs deleted file mode 100644 index ee057408e9..0000000000 --- a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using System.Web.Http.Controllers; -using System.Web.Http.Filters; -using Umbraco.Core; -using Umbraco.Core.BackOffice; -using Umbraco.Core.Mapping; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; -using Umbraco.Infrastructure.Configuration; -using Umbraco.Web.Composing; -using Umbraco.Web.Security; - -namespace Umbraco.Web.WebApi.Filters -{ - /// - /// This filter will check if the current Principal/Identity assigned to the request has stale data in it compared - /// to what is persisted for the current user and will update the current auth ticket with the correct data if required and output - /// a custom response header for the UI to be notified of it. - /// - /// - /// This could/should be created as a filter on the BackOfficeCookieAuthenticationProvider just like the SecurityStampValidator does - /// - public sealed class CheckIfUserTicketDataIsStaleAttribute : ActionFilterAttribute - { - // this is an attribute - no choice - private UmbracoMapper Mapper => Current.Mapper; - - public override async Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken) - { - await CheckStaleData(actionContext); - } - - public override async Task OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken) - { - await CheckStaleData(actionExecutedContext.ActionContext); - - //we need new tokens and append the custom header if changes have been made - if (actionExecutedContext.ActionContext.Request.Properties.ContainsKey(typeof(CheckIfUserTicketDataIsStaleAttribute).Name)) - { - var tokenFilter = new SetAngularAntiForgeryTokensAttribute(); - tokenFilter.OnActionExecuted(actionExecutedContext); - - //add the header - AppendUserModifiedHeaderAttribute.AppendHeader(actionExecutedContext); - } - } - - private async Task CheckStaleData(HttpActionContext actionContext) - { - if (actionContext == null - || actionContext.Request == null - || actionContext.RequestContext == null - || actionContext.RequestContext.Principal == null - || actionContext.RequestContext.Principal.Identity == null) - { - return; - } - - //don't execute if it's already been done - if (actionContext.Request.Properties.ContainsKey(typeof(CheckIfUserTicketDataIsStaleAttribute).Name)) - return; - - var identity = actionContext.RequestContext.Principal.Identity as UmbracoBackOfficeIdentity; - if (identity == null) return; - - var userId = identity.Id.TryConvertTo(); - if (userId == false) return; - - var user = Current.Services.UserService.GetUserById(userId.Result); - if (user == null) return; - - //a list of checks to execute, if any of them pass then we resync - var checks = new Func[] - { - () => user.Username != identity.Username, - () => - { - var culture = user.GetUserCulture(Current.Services.TextService, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(Current.Configs.Global())); - return culture != null && culture.ToString() != identity.Culture; - }, - () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, - () => user.Groups.Select(x => x.Alias).UnsortedSequenceEqual(identity.Roles) == false, - () => - { - var startContentIds = user.CalculateContentStartNodeIds(Current.Services.EntityService); - return startContentIds.UnsortedSequenceEqual(identity.StartContentNodes) == false; - }, - () => - { - var startMediaIds = user.CalculateMediaStartNodeIds(Current.Services.EntityService); - return startMediaIds.UnsortedSequenceEqual(identity.StartMediaNodes) == false; - } - }; - - if (checks.Any(check => check())) - { - await ReSync(user, actionContext); - } - } - - /// - /// This will update the current request IPrincipal to be correct and re-create the auth ticket - /// - /// - /// - /// - private async Task ReSync(IUser user, HttpActionContext actionContext) - { - var owinCtx = actionContext.Request.TryGetOwinContext(); - if (owinCtx) - { - var signInManager = owinCtx.Result.GetBackOfficeSignInManager(); - - var backOfficeIdentityUser = Mapper.Map(user); - await signInManager.SignInAsync(backOfficeIdentityUser, isPersistent: true, rememberBrowser: false); - - //ensure the remainder of the request has the correct principal set - actionContext.Request.SetPrincipalForRequest(owinCtx.Result.Request.User); - - //flag that we've made changes - actionContext.Request.Properties[typeof(CheckIfUserTicketDataIsStaleAttribute).Name] = true; - } - } - } -} diff --git a/src/Umbraco.Web/WebApi/Filters/SetAngularAntiForgeryTokensAttribute.cs b/src/Umbraco.Web/WebApi/Filters/SetAngularAntiForgeryTokensAttribute.cs deleted file mode 100644 index dadf2367b6..0000000000 --- a/src/Umbraco.Web/WebApi/Filters/SetAngularAntiForgeryTokensAttribute.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Web.Http.Filters; -using Umbraco.Core; -using Umbraco.Web.Composing; - -namespace Umbraco.Web.WebApi.Filters -{ - /// - /// A filter to set the csrf cookie token based on angular conventions - /// - public sealed class SetAngularAntiForgeryTokensAttribute : ActionFilterAttribute - { - public override void OnActionExecuted(HttpActionExecutedContext context) - { - if (context.Response == null) return; - - //DO not set the token cookies if the request has failed!! - if (context.Response.StatusCode != HttpStatusCode.OK) return; - - //don't need to set the cookie if they already exist and they are valid - if (context.Request.Headers.GetCookies(Constants.Web.AngularCookieName).Any() - && context.Request.Headers.GetCookies(Constants.Web.CsrfValidationCookieName).Any()) - { - //if they are not valid for some strange reason - we need to continue setting valid ones - string failedReason; - if (AngularAntiForgeryHelper.ValidateHeaders(context.Request.Headers, out failedReason)) - { - return; - } - } - - string cookieToken, headerToken; - AngularAntiForgeryHelper.GetTokens(out cookieToken, out headerToken); - - //We need to set 2 cookies: one is the cookie value that angular will use to set a header value on each request, - // the 2nd is the validation value generated by the anti-forgery helper that we use to validate the header token against. - - var angularCookie = new CookieHeaderValue(Constants.Web.AngularCookieName, headerToken) - { - Path = "/", - //must be js readable - HttpOnly = false, - Secure = Current.Configs.Global().UseHttps - }; - - var validationCookie = new CookieHeaderValue(Constants.Web.CsrfValidationCookieName, cookieToken) - { - Path = "/", - HttpOnly = true, - Secure = Current.Configs.Global().UseHttps - }; - - context.Response.Headers.AddCookies(new[] { angularCookie, validationCookie }); - } - } -} diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 48b3de44fd..015cb3c6bc 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.WebApi [UmbracoAuthorize] [DisableBrowserCache] // [UmbracoWebApiRequireHttps] - [CheckIfUserTicketDataIsStale] + // [CheckIfUserTicketDataIsStale] [UnhandedExceptionLoggerConfiguration] [EnableDetailedErrors] public abstract class UmbracoAuthorizedApiController : UmbracoApiController From 2eee6d7386e5c676f2b66abfc012178b11f4bbe7 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 11 Sep 2020 21:13:18 +0200 Subject: [PATCH 39/58] Removed some of the old legacy configs Signed-off-by: Bjarke Berg --- .../Legacy/ActiveDirectorySettings.cs | 15 ---- .../Legacy/ConnectionStrings.cs | 17 ----- .../Models/ActiveDirectorySettings.cs | 19 ----- .../Models/ConnectionStrings.cs | 69 ------------------ .../Configuration/IActiveDirectorySettings.cs | 7 -- .../Configuration/IConnectionStrings.cs | 10 --- .../ConfigModelConversionsFromLegacy.cs | 8 --- .../ConfigModelConversionsToLegacy.cs | 19 ----- .../Compose/ModelsBuilderComponent.cs | 10 +-- .../Compose/ModelsBuilderComposer.cs | 72 +++++++++---------- .../OutOfDateModelsStatus.cs | 5 +- .../Testing/UmbracoIntegrationTest.cs | 2 + .../Views/template1.cshtml | 4 -- .../Views/template2.cshtml | 4 -- .../Views/test.cshtml | 4 -- .../AutoFixture/AutoMoqDataAttribute.cs | 14 ++-- .../Models/ConnectionStringsTests.cs | 13 ++-- .../Umbraco.Web.Common/FileNameTests.cs | 6 +- ...eDirectoryBackOfficeUserPasswordChecker.cs | 10 +-- 19 files changed, 66 insertions(+), 242 deletions(-) delete mode 100644 src/Umbraco.Configuration/Legacy/ActiveDirectorySettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/ConnectionStrings.cs delete mode 100644 src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs delete mode 100644 src/Umbraco.Configuration/Models/ConnectionStrings.cs delete mode 100644 src/Umbraco.Core/Configuration/IActiveDirectorySettings.cs delete mode 100644 src/Umbraco.Core/Configuration/IConnectionStrings.cs delete mode 100644 src/Umbraco.Tests.Integration/Views/template1.cshtml delete mode 100644 src/Umbraco.Tests.Integration/Views/template2.cshtml delete mode 100644 src/Umbraco.Tests.Integration/Views/test.cshtml diff --git a/src/Umbraco.Configuration/Legacy/ActiveDirectorySettings.cs b/src/Umbraco.Configuration/Legacy/ActiveDirectorySettings.cs deleted file mode 100644 index ef100afed6..0000000000 --- a/src/Umbraco.Configuration/Legacy/ActiveDirectorySettings.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Legacy -{ - public class ActiveDirectorySettings : IActiveDirectorySettings - { - public ActiveDirectorySettings() - { - ActiveDirectoryDomain = ConfigurationManager.AppSettings["ActiveDirectoryDomain"]; - } - - public string ActiveDirectoryDomain { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/ConnectionStrings.cs b/src/Umbraco.Configuration/Legacy/ConnectionStrings.cs deleted file mode 100644 index a02c351118..0000000000 --- a/src/Umbraco.Configuration/Legacy/ConnectionStrings.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - public class ConnectionStrings : IConnectionStrings - { - public ConfigConnectionString this[string key] - { - get - { - var settings = ConfigurationManager.ConnectionStrings[key]; - if (settings == null) return null; - return new ConfigConnectionString(settings.ConnectionString, settings.ProviderName, settings.Name); - } - } - } -} diff --git a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs deleted file mode 100644 index 015fb17a8e..0000000000 --- a/src/Umbraco.Configuration/Models/ActiveDirectorySettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class ActiveDirectorySettings : IActiveDirectorySettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "ActiveDirectory:"; - private readonly IConfiguration _configuration; - - public ActiveDirectorySettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string ActiveDirectoryDomain => _configuration.GetValue(Prefix+"Domain"); - } -} diff --git a/src/Umbraco.Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Configuration/Models/ConnectionStrings.cs deleted file mode 100644 index 586765714c..0000000000 --- a/src/Umbraco.Configuration/Models/ConnectionStrings.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Data.Common; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - public class ConnectionStrings : IConnectionStrings - { - private readonly IConfiguration _configuration; - - public ConnectionStrings(IConfiguration configuration) - { - _configuration = configuration; - } - - public ConfigConnectionString this[string key] - { - get - { - var connectionString = _configuration.GetConnectionString(key); - var provider = ParseProvider(connectionString); - return new ConfigConnectionString(connectionString, provider, key); - } - set => throw new NotImplementedException(); - } - - private string ParseProvider(string connectionString) - { - if (string.IsNullOrEmpty(connectionString)) - { - return null; - } - - var builder = new DbConnectionStringBuilder(); - - builder.ConnectionString = connectionString; - - if (builder.TryGetValue("Data Source", out var ds) && ds is string dataSource) - { - if (dataSource.EndsWith(".sdf")) - { - return Constants.DbProviderNames.SqlCe; - } - } - - if (builder.TryGetValue("Server", out var s) && s is string server && !string.IsNullOrEmpty(server)) - { - if (builder.TryGetValue("Database", out var db) && db is string database && !string.IsNullOrEmpty(database)) - { - return Constants.DbProviderNames.SqlServer; - } - - if (builder.TryGetValue("AttachDbFileName", out var a) && a is string attachDbFileName && !string.IsNullOrEmpty(attachDbFileName)) - { - return Constants.DbProviderNames.SqlServer; - } - - if (builder.TryGetValue("Initial Catalog", out var i) && i is string initialCatalog && !string.IsNullOrEmpty(initialCatalog)) - { - return Constants.DbProviderNames.SqlServer; - } - } - - throw new ArgumentException("Cannot determine provider name from connection string", nameof(connectionString)); - } - } -} diff --git a/src/Umbraco.Core/Configuration/IActiveDirectorySettings.cs b/src/Umbraco.Core/Configuration/IActiveDirectorySettings.cs deleted file mode 100644 index e6b9202c06..0000000000 --- a/src/Umbraco.Core/Configuration/IActiveDirectorySettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IActiveDirectorySettings - { - string ActiveDirectoryDomain { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/IConnectionStrings.cs b/src/Umbraco.Core/Configuration/IConnectionStrings.cs deleted file mode 100644 index 0d33378669..0000000000 --- a/src/Umbraco.Core/Configuration/IConnectionStrings.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IConnectionStrings - { - ConfigConnectionString this[string key] - { - get; - } - } -} diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index d4a34d72d8..fd03610bb4 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -50,14 +50,6 @@ namespace Umbraco.Infrastructure.Configuration }; } - public static ConnectionStrings ConvertConnectionStrings(IConnectionStrings connectionStrings) - { - return new ConnectionStrings - { - UmbracoConnectionString = connectionStrings[Constants.System.UmbracoConnectionName].ConnectionString - }; - } - public static UserPasswordConfigurationSettings ConvertUserPasswordConfiguration(IUserPasswordConfiguration passwordConfiguration) { return new UserPasswordConfigurationSettings diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs index 60478aaee3..b2b6a3928d 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs @@ -49,13 +49,6 @@ namespace Umbraco.Infrastructure.Configuration }; } - public static IConnectionStrings ConvertConnectionStrings(ConnectionStrings connectionStrings) - { - var result = new TestConnectionStrings(); - result.AddEntry(Constants.System.UmbracoConnectionName, connectionStrings.UmbracoConnectionString); - return result; - } - public static IUserPasswordConfiguration ConvertUserPasswordConfiguration(UserPasswordConfigurationSettings passwordConfiguration) { return new TestUserPasswordConfiguration @@ -133,18 +126,6 @@ namespace Umbraco.Infrastructure.Configuration public string Password { get; set; } } - private class TestConnectionStrings : IConnectionStrings - { - private IDictionary _dictionary = new Dictionary(); - - public ConfigConnectionString this[string key] => _dictionary[key]; - - public void AddEntry(string key, string connectionString) - { - _dictionary.Add(key, new ConfigConnectionString(connectionString, string.Empty, key)); - } - } - private class TestUserPasswordConfiguration : IUserPasswordConfiguration { public int RequiredLength { get; set; } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs index ae2cbf6dde..192849aa86 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Reflection; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using Umbraco.Configuration; +using Umbraco.Configuration.Legacy; using Umbraco.Core.Configuration; using Umbraco.Core.Composing; using Umbraco.Core.IO; @@ -20,7 +22,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose { internal class ModelsBuilderComponent : IComponent { - private readonly IModelsBuilderConfig _config; + private readonly ModelsBuilderConfig _config; private readonly IShortStringHelper _shortStringHelper; private readonly LiveModelsProvider _liveModelsProvider; private readonly OutOfDateModelsStatus _outOfDateModels; @@ -28,11 +30,11 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; private readonly IUmbracoRequestLifetime _umbracoRequestLifetime; - public ModelsBuilderComponent(IModelsBuilderConfig config, IShortStringHelper shortStringHelper, + public ModelsBuilderComponent(IOptions config, IShortStringHelper shortStringHelper, LiveModelsProvider liveModelsProvider, OutOfDateModelsStatus outOfDateModels, LinkGenerator linkGenerator, IUmbracoRequestLifetime umbracoRequestLifetime, IUmbracoApplicationLifetime umbracoApplicationLifetime) { - _config = config; + _config = config.Value; _shortStringHelper = shortStringHelper; _liveModelsProvider = liveModelsProvider; _outOfDateModels = outOfDateModels; @@ -76,7 +78,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose private void InstallServerVars() { // register our url - for the backoffice api - ServerVariablesParser.Parsing += ServerVariablesParser_Parsing; + ServerVariablesParser.Parsing += ServerVariablesParser_Parsing; } private void ServerVariablesParser_Parsing(object sender, Dictionary serverVars) diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs index 951e9b6d41..fd5472b223 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs @@ -15,13 +15,6 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose [RuntimeLevel(MinLevel = RuntimeLevel.Run)] public sealed class ModelsBuilderComposer : ICoreComposer { - private readonly ModelsBuilderConfig _config; - - public ModelsBuilderComposer(IOptions config) - { - _config = config.Value; - } - public void Compose(Composition composition) { composition.Components().Append(); @@ -31,44 +24,43 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose composition.RegisterUnique(); composition.RegisterUnique(); - if (_config.ModelsMode == ModelsMode.PureLive) - ComposeForLiveModels(composition); - else if (_config.EnableFactory) - ComposeForDefaultModelsFactory(composition); - } - private void ComposeForDefaultModelsFactory(Composition composition) - { composition.RegisterUnique(factory => { - var typeLoader = factory.GetInstance(); - var publishedValueFallback = factory.GetInstance(); - var types = typeLoader - .GetTypes() // element models - .Concat(typeLoader.GetTypes()); // content models - return new PublishedModelFactory(types, publishedValueFallback); + var config = factory.GetInstance>().Value; + if (config.ModelsMode == ModelsMode.PureLive) + { + composition.RegisterUnique(); + + // the following would add @using statement in every view so user's don't + // have to do it - however, then noone understands where the @using statement + // comes from, and it cannot be avoided / removed --- DISABLED + // + /* + // no need for @using in views + // note: + // we are NOT using the in-code attribute here, config is required + // because that would require parsing the code... and what if it changes? + // we can AddGlobalImport not sure we can remove one anyways + var modelsNamespace = Configuration.Config.ModelsNamespace; + if (string.IsNullOrWhiteSpace(modelsNamespace)) + modelsNamespace = Configuration.Config.DefaultModelsNamespace; + System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(modelsNamespace); + */ + } + else if (config.EnableFactory) + { + var typeLoader = factory.GetInstance(); + var publishedValueFallback = factory.GetInstance(); + var types = typeLoader + .GetTypes() // element models + .Concat(typeLoader.GetTypes()); // content models + return new PublishedModelFactory(types, publishedValueFallback); + } + + return null; }); - } - private void ComposeForLiveModels(Composition composition) - { - composition.RegisterUnique(); - - // the following would add @using statement in every view so user's don't - // have to do it - however, then noone understands where the @using statement - // comes from, and it cannot be avoided / removed --- DISABLED - // - /* - // no need for @using in views - // note: - // we are NOT using the in-code attribute here, config is required - // because that would require parsing the code... and what if it changes? - // we can AddGlobalImport not sure we can remove one anyways - var modelsNamespace = Configuration.Config.ModelsNamespace; - if (string.IsNullOrWhiteSpace(modelsNamespace)) - modelsNamespace = Configuration.Config.DefaultModelsNamespace; - System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(modelsNamespace); - */ } } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs index 781dc40a02..85d08ee975 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs @@ -1,4 +1,5 @@ using System.IO; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Configuration.Models; @@ -11,9 +12,9 @@ namespace Umbraco.ModelsBuilder.Embedded private readonly ModelsBuilderConfig _config; private readonly IHostingEnvironment _hostingEnvironment; - public OutOfDateModelsStatus(ModelsBuilderConfig config, IHostingEnvironment hostingEnvironment) + public OutOfDateModelsStatus(IOptions config, IHostingEnvironment hostingEnvironment) { - _config = config; + _config = config.Value; _hostingEnvironment = hostingEnvironment; } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index a8f3b51e37..b21de325cc 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -87,6 +87,8 @@ namespace Umbraco.Tests.Integration.Testing Services = host.Services; var app = new ApplicationBuilder(host.Services); Configure(app); + + OnFixtureTearDown(() => host.Dispose()); } #region Generic Host Builder and Runtime diff --git a/src/Umbraco.Tests.Integration/Views/template1.cshtml b/src/Umbraco.Tests.Integration/Views/template1.cshtml deleted file mode 100644 index 3fa17ab54c..0000000000 --- a/src/Umbraco.Tests.Integration/Views/template1.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Tests.Integration/Views/template2.cshtml b/src/Umbraco.Tests.Integration/Views/template2.cshtml deleted file mode 100644 index 3fa17ab54c..0000000000 --- a/src/Umbraco.Tests.Integration/Views/template2.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Tests.Integration/Views/test.cshtml b/src/Umbraco.Tests.Integration/Views/test.cshtml deleted file mode 100644 index 3fa17ab54c..0000000000 --- a/src/Umbraco.Tests.Integration/Views/test.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index de9d8bb98a..c2ef2b4f04 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -1,13 +1,17 @@ using System; +using System.Linq; +using System.Reflection; using AutoFixture; using AutoFixture.AutoMoq; using AutoFixture.Kernel; using AutoFixture.NUnit3; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Moq; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Tests.Common.Builders; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Common.Install; @@ -42,9 +46,9 @@ namespace Umbraco.Tests.UnitTests.AutoFixture .Customize(new ConstructorCustomization(typeof(InstallController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(PreviewController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(BackOfficeController), new GreedyConstructorQuery())) - .Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery())) - .Customize(new AutoMoqCustomization()); + .Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery())); + fixture.Customize(new AutoMoqCustomization()); // When requesting an IUserStore ensure we actually uses a IUserLockoutStore fixture.Customize>(cc => cc.FromFactory(() => Mock.Of>())); @@ -56,9 +60,9 @@ namespace Umbraco.Tests.UnitTests.AutoFixture u => u.FromFactory( () => new UmbracoVersion())); - var connectionStrings = Mock.Of(); - Mock.Get(connectionStrings).Setup(x => x[Constants.System.UmbracoConnectionName]).Returns((ConfigConnectionString)new ConfigConnectionString(string.Empty, string.Empty, string.Empty)); - fixture.Customize(x => x.FromFactory(() => connectionStrings )); + var connectionStrings = new ConnectionStrings(); + fixture.Customize(x => x.FromFactory(() => connectionStrings )); + diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs index c5acba362b..24917aba15 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs @@ -3,6 +3,7 @@ using Moq; using NUnit.Framework; using Umbraco.Configuration.Models; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.UnitTests.Umbraco.Configuration.Models { @@ -16,17 +17,11 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Configuration.Models public string ParseProviderName(string connectionString) { var key = Constants.System.UmbracoConnectionName; - var configuration = new Mock(); - - //This is the underlying method that is called by Configuration.GetConnectionString(string) - if (connectionString != null) + var connectionStrings = new ConnectionStrings { - configuration.Setup(x => x.GetSection("ConnectionStrings")[key]).Returns(connectionString); - } - - - var connectionStrings = new ConnectionStrings(configuration.Object); + UmbracoConnectionString = connectionString + }; var actual = connectionStrings[key]; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs index c1c331903e..2669d74b11 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs @@ -5,9 +5,11 @@ using System.Threading.Tasks; using AutoFixture.NUnit3; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Tests.UnitTests.AutoFixture; using Umbraco.Web.BackOffice.Controllers; @@ -69,12 +71,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common [Test] [AutoMoqData] public async Task BackOfficeDefaultExists( - [Frozen] IGlobalSettings globalSettings, + [Frozen] IOptions globalSettings, [Frozen] IHostingEnvironment hostingEnvironment, [Frozen] ITempDataDictionary tempDataDictionary, BackOfficeController sut) { - Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); + globalSettings.Value.UmbracoPath = "/"; Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/"); Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/"); diff --git a/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs b/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs index 930cabeee3..82c9cb8496 100644 --- a/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs +++ b/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs @@ -1,22 +1,24 @@ using System; using System.DirectoryServices.AccountManagement; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Security { // TODO: This relies on an assembly that is not .NET Standard (at least not at the time of implementation) :( public class ActiveDirectoryBackOfficeUserPasswordChecker : IBackOfficeUserPasswordChecker { - private readonly IActiveDirectorySettings _settings; + private readonly IOptions _activeDirectorySettings; - public ActiveDirectoryBackOfficeUserPasswordChecker(IActiveDirectorySettings settings) + public ActiveDirectoryBackOfficeUserPasswordChecker(IOptions activeDirectorySettings) { - _settings = settings; + _activeDirectorySettings = activeDirectorySettings; } - public virtual string ActiveDirectoryDomain => _settings.ActiveDirectoryDomain; + public virtual string ActiveDirectoryDomain => _activeDirectorySettings.Value.Domain; public Task CheckPasswordAsync(BackOfficeIdentityUser user, string password) { From 5b90a469e9c729b4ed77d0ca4f13eab3810a1ed3 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 09:01:57 +0200 Subject: [PATCH 40/58] More clean up of old configs --- src/Umbraco.Configuration/ConfigsFactory.cs | 63 ------------------- .../Legacy/IndexCreatorSettings.cs | 15 ----- .../Legacy/KeepAliveSettings.cs | 10 --- .../Legacy/NuCacheSettings.cs | 14 ----- .../Legacy/TourSettings.cs | 9 --- .../Models/IndexCreatorSettings.cs | 20 ------ .../Models/KeepAliveSettings.cs | 23 ------- .../Models/NuCacheSettings.cs | 19 ------ .../Models/TourSettings.cs | 21 ------- .../UmbracoSettings/BackOfficeElement.cs | 12 ---- .../UmbracoSettings/KeepAliveElement.cs | 13 ---- .../UmbracoSettings/TourConfigElement.cs | 14 ----- .../UmbracoSettings/UmbracoSettingsSection.cs | 4 -- .../Configuration/IIndexCreatorSettings.cs | 7 --- .../Configuration/INuCacheSettings.cs | 7 --- .../Configuration/Models/KeepAliveSettings.cs | 8 +-- .../UmbracoSettings/IBackOfficeSection.cs | 7 --- .../UmbracoSettings/IKeepAliveSettings.cs | 8 --- .../UmbracoSettings/ITourSettings.cs | 7 --- .../UmbracoCoreServiceCollectionExtensions.cs | 1 - 20 files changed, 3 insertions(+), 279 deletions(-) delete mode 100644 src/Umbraco.Configuration/ConfigsFactory.cs delete mode 100644 src/Umbraco.Configuration/Legacy/IndexCreatorSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/KeepAliveSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/NuCacheSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/TourSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/IndexCreatorSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/KeepAliveSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/NuCacheSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/TourSettings.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/KeepAliveElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs delete mode 100644 src/Umbraco.Core/Configuration/IIndexCreatorSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/INuCacheSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/IBackOfficeSection.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/IKeepAliveSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/ITourSettings.cs diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs deleted file mode 100644 index 15378a5860..0000000000 --- a/src/Umbraco.Configuration/ConfigsFactory.cs +++ /dev/null @@ -1,63 +0,0 @@ -// using Umbraco.Configuration; -// using Umbraco.Configuration.Implementations; -// using Umbraco.Configuration.Legacy; -// using Umbraco.Core.Configuration.HealthChecks; -// using Umbraco.Core.Configuration.Legacy; -// using Umbraco.Core.Configuration.UmbracoSettings; -// -// namespace Umbraco.Core.Configuration -// { -// public class ConfigsFactory : IConfigsFactory -// { -// public IHostingSettings HostingSettings { get; } = new HostingSettings(); -// public ICoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); -// public IIndexCreatorSettings IndexCreatorSettings { get; } = new IndexCreatorSettings(); -// public INuCacheSettings NuCacheSettings { get; } = new NuCacheSettings(); -// public ITypeFinderSettings TypeFinderSettings { get; } = new TypeFinderSettings(); -// public IRuntimeSettings RuntimeSettings { get; } = new RuntimeSettings(); -// public IActiveDirectorySettings ActiveDirectorySettings { get; } = new ActiveDirectorySettings(); -// public IExceptionFilterSettings ExceptionFilterSettings { get; } = new ExceptionFilterSettings(); -// public ITourSettings TourSettings { get; } = new TourSettings(); -// public ILoggingSettings LoggingSettings { get; } = new LoggingSettings(); -// public IKeepAliveSettings KeepAliveSettings { get; } = new KeepAliveSettings(); -// public IWebRoutingSettings WebRoutingSettings { get; } = new WebRoutingSettings(); -// public IRequestHandlerSettings RequestHandlerSettings { get; } = new RequestHandlerSettings(); -// public ISecuritySettings SecuritySettings { get; } = new SecuritySettings(); -// public IUserPasswordConfiguration UserPasswordConfigurationSettings { get; } = new UserPasswordConfigurationSettings(); -// public IMemberPasswordConfiguration MemberPasswordConfigurationSettings { get; } = new MemberPasswordConfigurationSettings(); -// public IContentSettings ContentSettings { get; } = new ContentSettings(); -// public IGlobalSettings GlobalSettings { get; } = new GlobalSettings(); -// public IHealthChecksSettings HealthChecksSettings { get; } = new HealthChecksSettings(); -// public IConnectionStrings ConnectionStrings { get; } = new ConnectionStrings(); -// public IModelsBuilderConfig ModelsBuilderConfig { get; } = new ModelsBuilderConfig(); -// -// public Configs Create() -// { -// var configs = new Configs(); -// -// configs.Add(() => GlobalSettings); -// configs.Add(() => HostingSettings); -// configs.Add(() => HealthChecksSettings); -// configs.Add(() => CoreDebugSettings); -// configs.Add(() => ConnectionStrings); -// configs.Add(() => ModelsBuilderConfig); -// configs.Add(() => IndexCreatorSettings); -// configs.Add(() => NuCacheSettings); -// configs.Add(() => TypeFinderSettings); -// configs.Add(() => RuntimeSettings); -// configs.Add(() => ActiveDirectorySettings); -// configs.Add(() => ExceptionFilterSettings); -// configs.Add(() => TourSettings); -// configs.Add(() => LoggingSettings); -// configs.Add(() => KeepAliveSettings); -// configs.Add(() => WebRoutingSettings); -// configs.Add(() => RequestHandlerSettings); -// configs.Add(() => SecuritySettings); -// configs.Add(() => UserPasswordConfigurationSettings); -// configs.Add(() => MemberPasswordConfigurationSettings); -// configs.Add(() => ContentSettings); -// -// return configs; -// } -// } -// } diff --git a/src/Umbraco.Configuration/Legacy/IndexCreatorSettings.cs b/src/Umbraco.Configuration/Legacy/IndexCreatorSettings.cs deleted file mode 100644 index d023d46246..0000000000 --- a/src/Umbraco.Configuration/Legacy/IndexCreatorSettings.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Legacy -{ - public class IndexCreatorSettings : IIndexCreatorSettings - { - public IndexCreatorSettings() - { - LuceneDirectoryFactory = ConfigurationManager.AppSettings["Umbraco.Examine.LuceneDirectoryFactory"]; - } - - public string LuceneDirectoryFactory { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/KeepAliveSettings.cs b/src/Umbraco.Configuration/Legacy/KeepAliveSettings.cs deleted file mode 100644 index 0b8315d447..0000000000 --- a/src/Umbraco.Configuration/Legacy/KeepAliveSettings.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal class KeepAliveSettings : ConfigurationManagerConfigBase, IKeepAliveSettings - { - public bool DisableKeepAliveTask => UmbracoSettingsSection.KeepAlive.DisableKeepAliveTask; - public string KeepAlivePingUrl => UmbracoSettingsSection.KeepAlive.KeepAlivePingUrl; - } -} diff --git a/src/Umbraco.Configuration/Legacy/NuCacheSettings.cs b/src/Umbraco.Configuration/Legacy/NuCacheSettings.cs deleted file mode 100644 index 25f52a5c7d..0000000000 --- a/src/Umbraco.Configuration/Legacy/NuCacheSettings.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Legacy -{ - public class NuCacheSettings : INuCacheSettings - { - public NuCacheSettings() - { - BTreeBlockSize = ConfigurationManager.AppSettings["Umbraco.Web.PublishedCache.NuCache.BTree.BlockSize"]; - } - public string BTreeBlockSize { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/TourSettings.cs b/src/Umbraco.Configuration/Legacy/TourSettings.cs deleted file mode 100644 index 134c3c48d5..0000000000 --- a/src/Umbraco.Configuration/Legacy/TourSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal class TourSettings : ConfigurationManagerConfigBase, ITourSettings - { - public bool EnableTours => UmbracoSettingsSection.BackOffice.Tours.EnableTours; - } -} diff --git a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs b/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs deleted file mode 100644 index b4bb000552..0000000000 --- a/src/Umbraco.Configuration/Models/IndexCreatorSettings.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class IndexCreatorSettings : IIndexCreatorSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Examine:"; - private readonly IConfiguration _configuration; - - public IndexCreatorSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string LuceneDirectoryFactory => - _configuration.GetValue(Prefix + "LuceneDirectoryFactory"); - } -} diff --git a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs b/src/Umbraco.Configuration/Models/KeepAliveSettings.cs deleted file mode 100644 index 04194e1a3c..0000000000 --- a/src/Umbraco.Configuration/Models/KeepAliveSettings.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models -{ - internal class KeepAliveSettings : IKeepAliveSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "KeepAlive:"; - private readonly IConfiguration _configuration; - - public KeepAliveSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool DisableKeepAliveTask => - _configuration.GetValue(Prefix + "DisableKeepAliveTask", false); - - public string KeepAlivePingUrl => _configuration.GetValue(Prefix + "KeepAlivePingUrl", - "{umbracoApplicationUrl}/api/keepalive/ping"); - } -} diff --git a/src/Umbraco.Configuration/Models/NuCacheSettings.cs b/src/Umbraco.Configuration/Models/NuCacheSettings.cs deleted file mode 100644 index 51b8b1fe08..0000000000 --- a/src/Umbraco.Configuration/Models/NuCacheSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class NuCacheSettings : INuCacheSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "NuCache:"; - private readonly IConfiguration _configuration; - - public NuCacheSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string BTreeBlockSize => _configuration.GetValue(Prefix+"BTreeBlockSize"); - } -} diff --git a/src/Umbraco.Configuration/Models/TourSettings.cs b/src/Umbraco.Configuration/Models/TourSettings.cs deleted file mode 100644 index 9fe1814ff5..0000000000 --- a/src/Umbraco.Configuration/Models/TourSettings.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models -{ - internal class TourSettings : ITourSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Tours:"; - private readonly IConfiguration _configuration; - - public TourSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string Type { get; set; } - - public bool EnableTours => _configuration.GetValue(Prefix+"EnableTours", true); - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs deleted file mode 100644 index 46b9bf32a9..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection - { - [ConfigurationProperty("tours")] - internal TourConfigElement Tours => (TourConfigElement)this["tours"]; - - ITourSettings IBackOfficeSection.Tours => Tours; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/KeepAliveElement.cs b/src/Umbraco.Configuration/UmbracoSettings/KeepAliveElement.cs deleted file mode 100644 index 2297fb4e20..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/KeepAliveElement.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class KeepAliveElement : ConfigurationElement, IKeepAliveSettings - { - [ConfigurationProperty("disableKeepAliveTask", DefaultValue = "false")] - public bool DisableKeepAliveTask => (bool)base["disableKeepAliveTask"]; - - [ConfigurationProperty("keepAlivePingUrl", DefaultValue = "{umbracoApplicationUrl}/api/keepalive/ping")] - public string KeepAlivePingUrl => (string)base["keepAlivePingUrl"]; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs deleted file mode 100644 index f75b71fc57..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class TourConfigElement : UmbracoConfigurationElement, ITourSettings - { - //disabled by default so that upgraders don't get it enabled by default - // TODO: we probably just want to disable the initial one from automatically loading ? - [ConfigurationProperty("enable", DefaultValue = false)] - public bool EnableTours => (bool)this["enable"]; - - // TODO: We could have additional filters, etc... defined here - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs index 781d00b979..944f18c3f1 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -4,8 +4,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { internal class UmbracoSettingsSection : ConfigurationSection { - [ConfigurationProperty("backOffice")] - public BackOfficeElement BackOffice => (BackOfficeElement)this["backOffice"]; [ConfigurationProperty("content")] public ContentElement Content => (ContentElement)this["content"]; @@ -22,7 +20,5 @@ namespace Umbraco.Core.Configuration.UmbracoSettings [ConfigurationProperty("web.routing")] public WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; - [ConfigurationProperty("keepAlive")] - internal KeepAliveElement KeepAlive => (KeepAliveElement)this["keepAlive"]; } } diff --git a/src/Umbraco.Core/Configuration/IIndexCreatorSettings.cs b/src/Umbraco.Core/Configuration/IIndexCreatorSettings.cs deleted file mode 100644 index b3e2854a0d..0000000000 --- a/src/Umbraco.Core/Configuration/IIndexCreatorSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IIndexCreatorSettings - { - string LuceneDirectoryFactory { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/INuCacheSettings.cs b/src/Umbraco.Core/Configuration/INuCacheSettings.cs deleted file mode 100644 index c6524297a6..0000000000 --- a/src/Umbraco.Core/Configuration/INuCacheSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface INuCacheSettings - { - string BTreeBlockSize { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs b/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs index 188c4c5739..01d3b36a5d 100644 --- a/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs @@ -1,11 +1,9 @@ -using Umbraco.Core.Configuration.UmbracoSettings; - namespace Umbraco.Core.Configuration.Models { - public class KeepAliveSettings : IKeepAliveSettings + public class KeepAliveSettings { - public bool DisableKeepAliveTask { get; set; } = false; + public bool DisableKeepAliveTask => false; - public string KeepAlivePingUrl { get; set; } = "{umbracoApplicationUrl}/api/keepalive/ping"; + public string KeepAlivePingUrl => "{umbracoApplicationUrl}/api/keepalive/ping"; } } diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IBackOfficeSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IBackOfficeSection.cs deleted file mode 100644 index 85df4540c0..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IBackOfficeSection.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IBackOfficeSection - { - ITourSettings Tours { get; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IKeepAliveSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IKeepAliveSettings.cs deleted file mode 100644 index 58a8151474..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IKeepAliveSettings.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IKeepAliveSettings : IUmbracoConfigurationSection - { - bool DisableKeepAliveTask { get; } - string KeepAlivePingUrl { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ITourSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/ITourSettings.cs deleted file mode 100644 index d3d8293140..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ITourSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface ITourSettings - { - bool EnableTours { get; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 1bec3d04f1..e1a969e668 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -13,7 +13,6 @@ using Microsoft.Extensions.Options; using Serilog; using Serilog.Extensions.Hosting; using Serilog.Extensions.Logging; -using Umbraco.Configuration; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; From e6ad34da1d1aa5a1f9d8cfb863e5ab12f866f475 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 09:13:53 +0200 Subject: [PATCH 41/58] More clean up of old configs --- .../Legacy/LoggingSettings.cs | 9 --------- .../Models/LoggingSettings.cs | 19 ------------------- .../UmbracoSettings/LoggingElement.cs | 14 -------------- .../UmbracoSettings/UmbracoSettingsSection.cs | 3 --- .../UmbracoSettings/ILoggingSettings.cs | 9 --------- .../LoggingElementDefaultTests.cs | 16 ---------------- .../UmbracoSettings/LoggingElementTests.cs | 17 ----------------- .../UmbracoSettings/UmbracoSettingsTests.cs | 1 - 8 files changed, 88 deletions(-) delete mode 100644 src/Umbraco.Configuration/Legacy/LoggingSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/LoggingSettings.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/ILoggingSettings.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementDefaultTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementTests.cs diff --git a/src/Umbraco.Configuration/Legacy/LoggingSettings.cs b/src/Umbraco.Configuration/Legacy/LoggingSettings.cs deleted file mode 100644 index 020b0c0e64..0000000000 --- a/src/Umbraco.Configuration/Legacy/LoggingSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal class LoggingSettings : ConfigurationManagerConfigBase, ILoggingSettings - { - public int MaxLogAge => UmbracoSettingsSection.Logging.MaxLogAge; - } -} diff --git a/src/Umbraco.Configuration/Models/LoggingSettings.cs b/src/Umbraco.Configuration/Models/LoggingSettings.cs deleted file mode 100644 index b05fe03875..0000000000 --- a/src/Umbraco.Configuration/Models/LoggingSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models -{ - internal class LoggingSettings : ILoggingSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Logging:"; - private readonly IConfiguration _configuration; - - public LoggingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int MaxLogAge => _configuration.GetValue(Prefix + "MaxLogAge", -1); - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs deleted file mode 100644 index 2fdd61e169..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class LoggingElement : UmbracoConfigurationElement, ILoggingSettings - { - - [ConfigurationProperty("maxLogAge")] - internal InnerTextConfigurationElement MaxLogAge => GetOptionalTextElement("maxLogAge", -1); - - int ILoggingSettings.MaxLogAge => MaxLogAge; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs index 944f18c3f1..34e3c9c242 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -14,9 +14,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings [ConfigurationProperty("requestHandler")] public RequestHandlerElement RequestHandler => (RequestHandlerElement)this["requestHandler"]; - [ConfigurationProperty("logging")] - public LoggingElement Logging => (LoggingElement)this["logging"]; - [ConfigurationProperty("web.routing")] public WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ILoggingSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/ILoggingSettings.cs deleted file mode 100644 index ee5647ee27..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ILoggingSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface ILoggingSettings : IUmbracoConfigurationSection - { - int MaxLogAge { get; } - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementDefaultTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementDefaultTests.cs deleted file mode 100644 index 084c649f11..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementDefaultTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using NUnit.Framework; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class LoggingElementDefaultTests : LoggingElementTests - { - protected override bool TestingDefaults => true; - - [Test] - public override void MaxLogAge() - { - Assert.IsTrue(LoggingSettings.MaxLogAge == -1); - } - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementTests.cs deleted file mode 100644 index 3fd8041540..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/LoggingElementTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -using NUnit.Framework; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class LoggingElementTests : UmbracoSettingsTests - { - - [Test] - public virtual void MaxLogAge() - { - Assert.IsTrue(LoggingSettings.MaxLogAge == 1440); - - } - - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs index e869a972f5..7916100396 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs @@ -35,7 +35,6 @@ namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings } private UmbracoSettingsSection Settings { get; set; } - protected ILoggingSettings LoggingSettings => Settings.Logging; protected IWebRoutingSettings WebRoutingSettings => Settings.WebRouting; protected IRequestHandlerSettings RequestHandlerSettings => Settings.RequestHandler; protected ISecuritySettings SecuritySettings => Settings.Security; From 1b4b17cbaefccb8d9a90b090cfb901c9a1918a27 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 09:56:48 +0200 Subject: [PATCH 42/58] More clean up of old configs --- .../DisabledHealthCheckElement.cs | 42 ---- .../DisabledHealthChecksElementCollection.cs | 40 ---- .../HealthCheckNotificationSettingsElement.cs | 85 -------- .../HealthChecks/HealthChecksSection.cs | 24 --- .../HealthChecks/NotificationMethodElement.cs | 85 -------- .../NotificationMethodSettingsElement.cs | 28 --- ...ficationMethodSettingsElementCollection.cs | 80 ------- .../NotificationMethodsElementCollection.cs | 80 ------- .../Legacy/CoreDebugSettings.cs | 21 -- .../Legacy/ExceptionFilterSettings.cs | 18 -- .../Legacy/GlobalSettings.cs | 3 +- .../Legacy/HealthChecksSettings.cs | 26 --- .../Legacy/HostingSettings.cs | 54 ----- .../MemberPasswordConfigurationSettings.cs | 16 -- .../Legacy/ModelsBuilderConfig.cs | 200 ------------------ .../Legacy/RequestHandlerSettings.cs | 15 -- .../Legacy/RuntimeSettings.cs | 29 --- .../Legacy/SecuritySettings.cs | 14 -- .../Legacy/SmtpSettings.cs | 18 -- .../Legacy/TypeFinderSettings.cs | 17 -- .../UserPasswordConfigurationSettings.cs | 15 -- .../Legacy/WebRoutingSettings.cs | 16 -- .../Models/CoreDebugSettings.cs | 23 -- .../Models/ExceptionFilterSettings.cs | 19 -- .../Models/GlobalSettings.cs | 24 +-- .../Models/HealthChecksSettings.cs | 105 --------- .../Models/HostingSettings.cs | 29 --- .../Models/ImagingSettings.cs | 26 --- .../MemberPasswordConfigurationSettings.cs | 38 ---- .../Models/ModelsBuilderConfig.cs | 86 -------- .../Models/RequestHandlerSettings.cs | 87 -------- .../Models/RuntimeSettings.cs | 19 -- .../Models/SecuritySettings.cs | 33 --- .../Models/TypeFinderSettings.cs | 20 -- .../UserPasswordConfigurationSettings.cs | 36 ---- .../Models/WebRoutingSettings.cs | 42 ---- .../UmbracoSettings/RequestHandlerElement.cs | 96 --------- .../UmbracoSettings/SecurityElement.cs | 63 ------ .../UmbracoSettings/UmbracoSettingsSection.cs | 8 - .../UmbracoSettings/WebRoutingElement.cs | 31 --- .../IHealthCheckNotificationSettings.cs | 13 -- .../HealthChecks/IHealthChecksSettings.cs | 10 - .../Configuration/ICoreDebugSettings.cs | 17 -- .../Configuration/IExceptionFilterSettings.cs | 7 - .../Configuration/IGlobalSettings.cs | 6 +- .../Configuration/IHostingSettings.cs | 24 --- .../Configuration/IImagingSettings.cs | 12 -- .../Configuration/IModelsBuilderConfig.cs | 14 -- .../Configuration/IRuntimeSettings.cs | 8 - .../Configuration/ISmtpSettings.cs | 15 -- .../IRequestHandlerSettings.cs | 15 -- .../UmbracoSettings/ISecuritySettings.cs | 27 --- .../UmbracoSettings/IWebRoutingSettings.cs | 21 -- .../ConfigModelConversionsFromLegacy.cs | 15 -- .../ConfigModelConversionsToLegacy.cs | 20 +- .../HealthCheck/HealthCheckResults.cs | 2 +- .../Compose/ModelsBuilderComponent.cs | 3 +- src/Umbraco.Tests.Common/SettingsForTests.cs | 44 ---- src/Umbraco.Tests.Common/TestHelperBase.cs | 5 +- .../ContentElementDefaultTests.cs | 70 ------ .../UmbracoSettings/ContentElementTests.cs | 117 ---------- .../RequestHandlerElementDefaultTests.cs | 10 - .../RequestHandlerElementTests.cs | 33 --- .../SecurityElementDefaultTests.cs | 10 - .../UmbracoSettings/SecurityElementTests.cs | 123 ----------- .../UmbracoSettings/UmbracoSettingsTests.cs | 45 ---- .../WebRoutingElementDefaultTests.cs | 40 ---- .../UmbracoSettings/WebRoutingElementTests.cs | 26 --- .../Umbraco.Core/Routing/UriUtilityTests.cs | 2 - .../ModelsBuilder/ConfigTests.cs | 51 ----- .../Configurations/GlobalSettingsTests.cs | 9 +- .../Runtimes/CoreRuntimeTests.cs | 8 +- .../TestHelpers/SettingsForTests.cs | 11 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 9 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 7 +- .../AspNet/AspNetBackOfficeInfo.cs | 8 +- .../AspNet/AspNetHostingEnvironment.cs | 12 +- .../Editors/AuthenticationController.cs | 8 +- .../Editors/BackOfficeController.cs | 12 +- .../Editors/BackOfficeServerVariables.cs | 14 +- .../Mvc/ModelBindingExceptionFilter.cs | 4 +- .../BackOfficeCookieAuthenticationProvider.cs | 10 +- .../Security/GetUserSecondsMiddleWare.cs | 8 +- src/Umbraco.Web/UmbracoApplicationBase.cs | 12 +- src/Umbraco.Web/UmbracoDefaultOwinStartup.cs | 4 +- .../CDF/ClientDependencyComponent.cs | 14 +- 86 files changed, 93 insertions(+), 2573 deletions(-) delete mode 100644 src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs delete mode 100644 src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs delete mode 100644 src/Umbraco.Configuration/Legacy/CoreDebugSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/ExceptionFilterSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/HealthChecksSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/HostingSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/MemberPasswordConfigurationSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/ModelsBuilderConfig.cs delete mode 100644 src/Umbraco.Configuration/Legacy/RequestHandlerSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/RuntimeSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/SecuritySettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/SmtpSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/TypeFinderSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/UserPasswordConfigurationSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/WebRoutingSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/CoreDebugSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/HealthChecksSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/HostingSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/ImagingSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs delete mode 100644 src/Umbraco.Configuration/Models/RequestHandlerSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/RuntimeSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/SecuritySettings.cs delete mode 100644 src/Umbraco.Configuration/Models/TypeFinderSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/WebRoutingSettings.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs delete mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/ICoreDebugSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/IExceptionFilterSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/IHostingSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/IImagingSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/IModelsBuilderConfig.cs delete mode 100644 src/Umbraco.Core/Configuration/IRuntimeSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/ISmtpSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/IRequestHandlerSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/ISecuritySettings.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSettings.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementDefaultTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementDefaultTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementDefaultTests.cs delete mode 100644 src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementTests.cs delete mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/ModelsBuilder/ConfigTests.cs diff --git a/src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs b/src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs deleted file mode 100644 index 01392da614..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Text; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public class DisabledHealthCheckElement : ConfigurationElement, IDisabledHealthCheck - { - private const string IdKey = "id"; - private const string DisabledOnKey = "disabledOn"; - private const string DisabledByKey = "disabledBy"; - - [ConfigurationProperty(IdKey, IsKey = true, IsRequired = true)] - public Guid Id - { - get - { - return ((Guid)(base[IdKey])); - } - } - - [ConfigurationProperty(DisabledOnKey, IsKey = false, IsRequired = false)] - public DateTime DisabledOn - { - get - { - return ((DateTime)(base[DisabledOnKey])); - } - } - - [ConfigurationProperty(DisabledByKey, IsKey = false, IsRequired = false)] - public int DisabledBy - { - get - { - return ((int)(base[DisabledByKey])); - } - } - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs deleted file mode 100644 index 87600b8ae3..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - [ConfigurationCollection(typeof(DisabledHealthCheckElement), AddItemName = "check")] - public class DisabledHealthChecksElementCollection : ConfigurationElementCollection, IEnumerable - { - protected override ConfigurationElement CreateNewElement() - { - return new DisabledHealthCheckElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((DisabledHealthCheckElement)(element)).Id; - } - - public new DisabledHealthCheckElement this[string key] - { - get - { - return (DisabledHealthCheckElement)BaseGet(key); - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return BaseGet(i) as DisabledHealthCheckElement; - } - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs b/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs deleted file mode 100644 index 1ccf3e357b..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public class HealthCheckNotificationSettingsElement : ConfigurationElement, IHealthCheckNotificationSettings - { - private const string EnabledKey = "enabled"; - private const string FirstRunTimeKey = "firstRunTime"; - private const string PeriodKey = "periodInHours"; - private const string NotificationMethodsKey = "notificationMethods"; - private const string DisabledChecksKey = "disabledChecks"; - - [ConfigurationProperty(EnabledKey, IsRequired = true)] - public bool Enabled - { - get - { - return (bool)base[EnabledKey]; - } - } - - [ConfigurationProperty(FirstRunTimeKey, IsRequired = false)] - public string FirstRunTime - { - get - { - return (string)base[FirstRunTimeKey]; - } - } - - [ConfigurationProperty(PeriodKey, IsRequired = true)] - public int PeriodInHours - { - get - { - return (int)base[PeriodKey]; - } - } - - [ConfigurationProperty(NotificationMethodsKey, IsDefaultCollection = true, IsRequired = false)] - public NotificationMethodsElementCollection NotificationMethods - { - get - { - return (NotificationMethodsElementCollection)base[NotificationMethodsKey]; - } - } - - [ConfigurationProperty(DisabledChecksKey, IsDefaultCollection = false, IsRequired = false)] - public DisabledHealthChecksElementCollection DisabledChecks - { - get - { - return (DisabledHealthChecksElementCollection)base[DisabledChecksKey]; - } - } - - bool IHealthCheckNotificationSettings.Enabled - { - get { return Enabled; } - } - - string IHealthCheckNotificationSettings.FirstRunTime - { - get { return FirstRunTime; } - } - - int IHealthCheckNotificationSettings.PeriodInHours - { - get { return PeriodInHours; } - } - - IReadOnlyDictionary IHealthCheckNotificationSettings.NotificationMethods - { - get { return NotificationMethods; } - } - - IEnumerable IHealthCheckNotificationSettings.DisabledChecks - { - get { return DisabledChecks; } - } - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs b/src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs deleted file mode 100644 index 373d846567..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Configuration; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public class HealthChecksSection : ConfigurationSection - { - private const string DisabledChecksKey = "disabledChecks"; - private const string NotificationSettingsKey = "notificationSettings"; - - [ConfigurationProperty(DisabledChecksKey)] - public DisabledHealthChecksElementCollection DisabledChecks - { - get { return ((DisabledHealthChecksElementCollection)(base[DisabledChecksKey])); } - } - - [ConfigurationProperty(NotificationSettingsKey, IsRequired = true)] - public HealthCheckNotificationSettingsElement NotificationSettings - { - get { return ((HealthCheckNotificationSettingsElement)(base[NotificationSettingsKey])); } - } - - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs deleted file mode 100644 index cbbe5e8b02..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public class NotificationMethodElement : ConfigurationElement, INotificationMethod - { - private const string AliasKey = "alias"; - private const string EnabledKey = "enabled"; - private const string VerbosityKey = "verbosity"; - private const string FailureonlyKey = "failureOnly"; - private const string SettingsKey = "settings"; - - [ConfigurationProperty(AliasKey, IsKey = true, IsRequired = true)] - public string Alias - { - get - { - return (string)base[AliasKey]; - } - } - - [ConfigurationProperty(EnabledKey, IsKey = true, IsRequired = true)] - public bool Enabled - { - get - { - return (bool)base[EnabledKey]; - } - } - - [ConfigurationProperty(VerbosityKey, IsRequired = true)] - public HealthCheckNotificationVerbosity Verbosity - { - get - { - return (HealthCheckNotificationVerbosity)base[VerbosityKey]; - } - } - - [ConfigurationProperty(FailureonlyKey, IsRequired = false)] - public bool FailureOnly - { - get - { - return (bool)base[FailureonlyKey]; - } - } - - [ConfigurationProperty(SettingsKey, IsDefaultCollection = true, IsRequired = false)] - public NotificationMethodSettingsElementCollection Settings - { - get - { - return (NotificationMethodSettingsElementCollection)base[SettingsKey]; - } - } - - string INotificationMethod.Alias - { - get { return Alias; } - } - - bool INotificationMethod.Enabled - { - get { return Enabled; } - } - - HealthCheckNotificationVerbosity INotificationMethod.Verbosity - { - get { return Verbosity; } - } - - bool INotificationMethod.FailureOnly - { - get { return FailureOnly; } - } - - IReadOnlyDictionary INotificationMethod.Settings - { - get { return Settings; } - } - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs deleted file mode 100644 index ed42eb7221..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public class NotificationMethodSettingsElement : ConfigurationElement, INotificationMethodSettings - { - private const string KeyKey = "key"; - private const string ValueKey = "value"; - - [ConfigurationProperty(KeyKey, IsKey = true, IsRequired = true)] - public string Key - { - get - { - return (string)base[KeyKey]; - } - } - - [ConfigurationProperty(ValueKey, IsRequired = true)] - public string Value - { - get - { - return (string)base[ValueKey]; - } - } - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs deleted file mode 100644 index 226278ab61..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - [ConfigurationCollection(typeof(NotificationMethodSettingsElement), AddItemName = "add")] - public class NotificationMethodSettingsElementCollection : ConfigurationElementCollection, IEnumerable, IReadOnlyDictionary - { - protected override ConfigurationElement CreateNewElement() - { - return new NotificationMethodSettingsElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((NotificationMethodSettingsElement)(element)).Key; - } - - IEnumerator> IEnumerable>.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - var val = (NotificationMethodSettingsElement)BaseGet(i); - var key = (string)BaseGetKey(i); - yield return new KeyValuePair(key, val); - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return (NotificationMethodSettingsElement)BaseGet(i); - } - } - - bool IReadOnlyDictionary.ContainsKey(string key) - { - return ((IReadOnlyDictionary)this).Keys.Any(x => x == key); - } - - bool IReadOnlyDictionary.TryGetValue(string key, out INotificationMethodSettings value) - { - try - { - var val = (NotificationMethodSettingsElement)BaseGet(key); - value = val; - return true; - } - catch (Exception) - { - value = null; - return false; - } - } - - INotificationMethodSettings IReadOnlyDictionary.this[string key] - { - get { return (NotificationMethodSettingsElement)BaseGet(key); } - } - - IEnumerable IReadOnlyDictionary.Keys - { - get { return BaseGetAllKeys().Cast(); } - } - - IEnumerable IReadOnlyDictionary.Values - { - get - { - for (var i = 0; i < Count; i++) - { - yield return (NotificationMethodSettingsElement)BaseGet(i); - } - } - } - } -} diff --git a/src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs deleted file mode 100644 index ee7e135961..0000000000 --- a/src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - [ConfigurationCollection(typeof(NotificationMethodElement), AddItemName = "notificationMethod")] - public class NotificationMethodsElementCollection : ConfigurationElementCollection, IEnumerable, IReadOnlyDictionary - { - protected override ConfigurationElement CreateNewElement() - { - return new NotificationMethodElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((NotificationMethodElement)(element)).Alias; - } - - IEnumerator> IEnumerable>.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - var val = (NotificationMethodElement)BaseGet(i); - var key = (string)BaseGetKey(i); - yield return new KeyValuePair(key, val); - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return (NotificationMethodElement)BaseGet(i); - } - } - - bool IReadOnlyDictionary.ContainsKey(string key) - { - return ((IReadOnlyDictionary) this).Keys.Any(x => x == key); - } - - bool IReadOnlyDictionary.TryGetValue(string key, out INotificationMethod value) - { - try - { - var val = (NotificationMethodElement)BaseGet(key); - value = val; - return true; - } - catch (Exception) - { - value = null; - return false; - } - } - - INotificationMethod IReadOnlyDictionary.this[string key] - { - get { return (NotificationMethodElement)BaseGet(key); } - } - - IEnumerable IReadOnlyDictionary.Keys - { - get { return BaseGetAllKeys().Cast(); } - } - - IEnumerable IReadOnlyDictionary.Values - { - get - { - for (var i = 0; i < Count; i++) - { - yield return (NotificationMethodElement)BaseGet(i); - } - } - } - } -} diff --git a/src/Umbraco.Configuration/Legacy/CoreDebugSettings.cs b/src/Umbraco.Configuration/Legacy/CoreDebugSettings.cs deleted file mode 100644 index 4902d4489f..0000000000 --- a/src/Umbraco.Configuration/Legacy/CoreDebugSettings.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - public class CoreDebugSettings : ICoreDebugSettings - { - public CoreDebugSettings() - { - var appSettings = ConfigurationManager.AppSettings; - LogUncompletedScopes = string.Equals("true", appSettings[Constants.AppSettings.Debug.LogUncompletedScopes], StringComparison.OrdinalIgnoreCase); - DumpOnTimeoutThreadAbort = string.Equals("true", appSettings[Constants.AppSettings.Debug.DumpOnTimeoutThreadAbort], StringComparison.OrdinalIgnoreCase); - } - - /// - public bool LogUncompletedScopes { get; } - - /// - public bool DumpOnTimeoutThreadAbort { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/ExceptionFilterSettings.cs b/src/Umbraco.Configuration/Legacy/ExceptionFilterSettings.cs deleted file mode 100644 index 50e2207485..0000000000 --- a/src/Umbraco.Configuration/Legacy/ExceptionFilterSettings.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Legacy -{ - public class ExceptionFilterSettings : IExceptionFilterSettings - { - public ExceptionFilterSettings() - { - if (bool.TryParse(ConfigurationManager.AppSettings["Umbraco.Web.DisableModelBindingExceptionFilter"], - out var disabled)) - { - Disabled = disabled; - } - } - public bool Disabled { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/GlobalSettings.cs b/src/Umbraco.Configuration/Legacy/GlobalSettings.cs index fabe95f5bd..8dee6e79dc 100644 --- a/src/Umbraco.Configuration/Legacy/GlobalSettings.cs +++ b/src/Umbraco.Configuration/Legacy/GlobalSettings.cs @@ -5,6 +5,7 @@ using System.Net.Mail; using System.Xml.Linq; using Umbraco.Composing; using Umbraco.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.Core.Configuration.Legacy @@ -61,7 +62,7 @@ namespace Umbraco.Core.Configuration.Legacy } } - public ISmtpSettings SmtpSettings + public SmtpSettings SmtpSettings { get { diff --git a/src/Umbraco.Configuration/Legacy/HealthChecksSettings.cs b/src/Umbraco.Configuration/Legacy/HealthChecksSettings.cs deleted file mode 100644 index 23385d1378..0000000000 --- a/src/Umbraco.Configuration/Legacy/HealthChecksSettings.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; -using Umbraco.Core.Configuration.HealthChecks; - -namespace Umbraco.Core.Configuration.Legacy -{ - public class HealthChecksSettings : IHealthChecksSettings - { - private HealthChecksSection _healthChecksSection; - - private HealthChecksSection HealthChecksSection - { - get - { - if (_healthChecksSection is null) - { - _healthChecksSection = ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks") as HealthChecksSection; - } - return _healthChecksSection; - } - } - - public IEnumerable DisabledChecks => HealthChecksSection.DisabledChecks; - public IHealthCheckNotificationSettings NotificationSettings => HealthChecksSection.NotificationSettings; - } -} diff --git a/src/Umbraco.Configuration/Legacy/HostingSettings.cs b/src/Umbraco.Configuration/Legacy/HostingSettings.cs deleted file mode 100644 index 1858e8a4a4..0000000000 --- a/src/Umbraco.Configuration/Legacy/HostingSettings.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.Legacy -{ - public class HostingSettings : IHostingSettings - { - private bool? _debugMode; - - /// - public LocalTempStorage LocalTempStorageLocation - { - get - { - var setting = ConfigurationManager.AppSettings[Constants.AppSettings.LocalTempStorage]; - if (!string.IsNullOrWhiteSpace(setting)) - return Enum.Parse(setting); - - return LocalTempStorage.Default; - } - } - - public string ApplicationVirtualPath => null; - - /// - /// Gets a value indicating whether umbraco is running in [debug mode]. - /// - /// true if [debug mode]; otherwise, false. - public bool DebugMode - { - get - { - if (!_debugMode.HasValue) - { - try - { - if (ConfigurationManager.GetSection("system.web/compilation") is ConfigurationSection compilation) - { - var debugElement = compilation.ElementInformation.Properties["debug"]; - - _debugMode = debugElement != null && (debugElement.Value is bool debug && debug); - - } - } - catch - { - _debugMode = false; - } - } - - return _debugMode.GetValueOrDefault(); - } - } - } -} diff --git a/src/Umbraco.Configuration/Legacy/MemberPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Legacy/MemberPasswordConfigurationSettings.cs deleted file mode 100644 index e42b02de73..0000000000 --- a/src/Umbraco.Configuration/Legacy/MemberPasswordConfigurationSettings.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Implementations -{ - internal class MemberPasswordConfigurationSettings : ConfigurationManagerConfigBase, IMemberPasswordConfiguration - { - public int RequiredLength => UmbracoSettingsSection.Security.UserPasswordConfiguration.RequiredLength; - public bool RequireNonLetterOrDigit => UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireNonLetterOrDigit; - public bool RequireDigit => UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireDigit; - public bool RequireLowercase=> UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireLowercase; - public bool RequireUppercase=> UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireUppercase; - public bool UseLegacyEncoding=> UmbracoSettingsSection.Security.UserPasswordConfiguration.UseLegacyEncoding; - public string HashAlgorithmType=> UmbracoSettingsSection.Security.UserPasswordConfiguration.HashAlgorithmType; - public int MaxFailedAccessAttemptsBeforeLockout => UmbracoSettingsSection.Security.UserPasswordConfiguration.MaxFailedAccessAttemptsBeforeLockout; - } -} diff --git a/src/Umbraco.Configuration/Legacy/ModelsBuilderConfig.cs b/src/Umbraco.Configuration/Legacy/ModelsBuilderConfig.cs deleted file mode 100644 index f6395b23b4..0000000000 --- a/src/Umbraco.Configuration/Legacy/ModelsBuilderConfig.cs +++ /dev/null @@ -1,200 +0,0 @@ -using System; -using System.Configuration; -using System.IO; -using System.Threading; -using Umbraco.Core.Configuration; -using Umbraco.Core; -using Umbraco.Core.IO; - -namespace Umbraco.Configuration.Legacy -{ - /// - /// Represents the models builder configuration. - /// - public class ModelsBuilderConfig : IModelsBuilderConfig - { - - private const string Prefix = "Umbraco.ModelsBuilder."; - private object _modelsModelLock; - private bool _modelsModelConfigured; - private ModelsMode _modelsMode; - private object _flagOutOfDateModelsLock; - private bool _flagOutOfDateModelsConfigured; - private bool _flagOutOfDateModels; - - - public string DefaultModelsDirectory => "~/App_Data/Models"; - - /// - /// Initializes a new instance of the class. - /// - public ModelsBuilderConfig() - { - // giant kill switch, default: false - // must be explicitely set to true for anything else to happen - Enable = ConfigurationManager.AppSettings[Prefix + "Enable"] == "true"; - - // ensure defaults are initialized for tests - ModelsNamespace = Constants.ModelsBuilder.DefaultModelsNamespace; - ModelsDirectory = DefaultModelsDirectory; - DebugLevel = 0; - - // stop here, everything is false - if (!Enable) return; - - // default: false - AcceptUnsafeModelsDirectory = ConfigurationManager.AppSettings[Prefix + "AcceptUnsafeModelsDirectory"].InvariantEquals("true"); - - // default: true - EnableFactory = !ConfigurationManager.AppSettings[Prefix + "EnableFactory"].InvariantEquals("false"); - - // default: initialized above with DefaultModelsNamespace const - var value = ConfigurationManager.AppSettings[Prefix + "ModelsNamespace"]; - if (!string.IsNullOrWhiteSpace(value)) - ModelsNamespace = value; - - // default: initialized above with DefaultModelsDirectory const - value = ConfigurationManager.AppSettings[Prefix + "ModelsDirectory"]; - if (!string.IsNullOrWhiteSpace(value)) - { - // GetModelsDirectory will ensure that the path is safe - ModelsDirectory = value; - } - - // default: 0 - value = ConfigurationManager.AppSettings[Prefix + "DebugLevel"]; - if (!string.IsNullOrWhiteSpace(value)) - { - if (!int.TryParse(value, out var debugLevel)) - throw new ConfigurationErrorsException($"Invalid debug level \"{value}\"."); - DebugLevel = debugLevel; - } - - } - - /// - /// Initializes a new instance of the class. - /// - public ModelsBuilderConfig( - bool enable = false, - ModelsMode modelsMode = ModelsMode.Nothing, - string modelsNamespace = null, - bool enableFactory = true, - bool flagOutOfDateModels = true, - string modelsDirectory = null, - bool acceptUnsafeModelsDirectory = false, - int debugLevel = 0) - { - Enable = enable; - _modelsMode = modelsMode; - - ModelsNamespace = string.IsNullOrWhiteSpace(modelsNamespace) ? Constants.ModelsBuilder.DefaultModelsNamespace : modelsNamespace; - EnableFactory = enableFactory; - _flagOutOfDateModels = flagOutOfDateModels; - ModelsDirectory = string.IsNullOrWhiteSpace(modelsDirectory) ? DefaultModelsDirectory : modelsDirectory; - AcceptUnsafeModelsDirectory = acceptUnsafeModelsDirectory; - DebugLevel = debugLevel; - } - - - - /// - /// Gets a value indicating whether the whole models experience is enabled. - /// - /// - /// If this is false then absolutely nothing happens. - /// Default value is false which means that unless we have this setting, nothing happens. - /// - public bool Enable { get; } - - /// - /// Gets the models mode. - /// - public ModelsMode ModelsMode => - LazyInitializer.EnsureInitialized(ref _modelsMode, ref _modelsModelConfigured, ref _modelsModelLock, () => - { - // mode - var modelsMode = ConfigurationManager.AppSettings[Prefix + "ModelsMode"]; - if (string.IsNullOrWhiteSpace(modelsMode)) return ModelsMode.Nothing; //default - switch (modelsMode) - { - case nameof(ModelsMode.Nothing): - return ModelsMode.Nothing; - case nameof(ModelsMode.PureLive): - return ModelsMode.PureLive; - case nameof(ModelsMode.AppData): - return ModelsMode.AppData; - case nameof(ModelsMode.LiveAppData): - return ModelsMode.LiveAppData; - default: - throw new ConfigurationErrorsException($"ModelsMode \"{modelsMode}\" is not a valid mode." + " Note that modes are case-sensitive. Possible values are: " + string.Join(", ", Enum.GetNames(typeof(ModelsMode)))); - } - }); - - /// - /// Gets a value indicating whether system.web/compilation/@debug is true. - /// - public bool IsDebug - { - get - { - if (ConfigurationManager.GetSection("system.web/compilation") is ConfigurationSection section && - bool.TryParse(section.ElementInformation.Properties["debug"].Value.ToString(), out var isDebug)) - { - return isDebug; - } - - return false; - } - } - - /// - /// Gets the models namespace. - /// - /// That value could be overriden by other (attribute in user's code...). Return default if no value was supplied. - public string ModelsNamespace { get; } - - /// - /// Gets a value indicating whether we should enable the models factory. - /// - /// Default value is true because no factory is enabled by default in Umbraco. - public bool EnableFactory { get; } - - /// - /// Gets a value indicating whether we should flag out-of-date models. - /// - /// Models become out-of-date when data types or content types are updated. When this - /// setting is activated the ~/App_Data/Models/ood.txt file is then created. When models are - /// generated through the dashboard, the files is cleared. Default value is false. - public bool FlagOutOfDateModels - => LazyInitializer.EnsureInitialized(ref _flagOutOfDateModels, ref _flagOutOfDateModelsConfigured, ref _flagOutOfDateModelsLock, () => - { - var flagOutOfDateModels = !ConfigurationManager.AppSettings[Prefix + "FlagOutOfDateModels"].InvariantEquals("false"); - if (ModelsMode == ModelsMode.Nothing || ModelsMode.IsLive()) - { - flagOutOfDateModels = false; - } - - return flagOutOfDateModels; - }); - - /// - /// Gets the models directory. - /// - /// Default is ~/App_Data/Models but that can be changed. - public string ModelsDirectory { get; } - - /// - /// Gets a value indicating whether to accept an unsafe value for ModelsDirectory. - /// - /// An unsafe value is an absolute path, or a relative path pointing outside - /// of the website root. - public bool AcceptUnsafeModelsDirectory { get; } - - /// - /// Gets a value indicating the debug log level. - /// - /// 0 means minimal (safe on live site), anything else means more and more details (maybe not safe). - public int DebugLevel { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/RequestHandlerSettings.cs b/src/Umbraco.Configuration/Legacy/RequestHandlerSettings.cs deleted file mode 100644 index 1c54f4d475..0000000000 --- a/src/Umbraco.Configuration/Legacy/RequestHandlerSettings.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal class RequestHandlerSettings : ConfigurationManagerConfigBase, IRequestHandlerSettings - { - public bool AddTrailingSlash => UmbracoSettingsSection?.RequestHandler?.AddTrailingSlash ?? true; - public bool ConvertUrlsToAscii => UmbracoSettingsSection?.RequestHandler?.UrlReplacing?.ConvertUrlsToAscii.InvariantEquals("true") ?? false; - public bool TryConvertUrlsToAscii => UmbracoSettingsSection?.RequestHandler?.UrlReplacing?.ConvertUrlsToAscii.InvariantEquals("try") ?? false; - public IEnumerable CharCollection => UmbracoSettingsSection?.RequestHandler?.UrlReplacing?.CharCollection ?? Enumerable.Empty(); - } -} diff --git a/src/Umbraco.Configuration/Legacy/RuntimeSettings.cs b/src/Umbraco.Configuration/Legacy/RuntimeSettings.cs deleted file mode 100644 index 200642a819..0000000000 --- a/src/Umbraco.Configuration/Legacy/RuntimeSettings.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Legacy -{ - public class RuntimeSettings : IRuntimeSettings - { - public RuntimeSettings() - { - if (ConfigurationManager.GetSection("system.web/httpRuntime") is ConfigurationSection section) - { - var maxRequestLengthProperty = section.ElementInformation.Properties["maxRequestLength"]; - if (maxRequestLengthProperty != null && maxRequestLengthProperty.Value is int requestLength) - { - MaxRequestLength = requestLength; - } - - var maxQueryStringProperty = section.ElementInformation.Properties["maxQueryStringLength"]; - if (maxQueryStringProperty != null && maxQueryStringProperty.Value is int maxQueryStringLength) - { - MaxQueryStringLength = maxQueryStringLength; - } - } - } - public int? MaxQueryStringLength { get; } - public int? MaxRequestLength { get; } - - } -} diff --git a/src/Umbraco.Configuration/Legacy/SecuritySettings.cs b/src/Umbraco.Configuration/Legacy/SecuritySettings.cs deleted file mode 100644 index b7e39b0608..0000000000 --- a/src/Umbraco.Configuration/Legacy/SecuritySettings.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal class SecuritySettings : ConfigurationManagerConfigBase, ISecuritySettings - { - public bool KeepUserLoggedIn => UmbracoSettingsSection.Security.KeepUserLoggedIn; - public bool HideDisabledUsersInBackoffice => UmbracoSettingsSection.Security.HideDisabledUsersInBackoffice; - public bool AllowPasswordReset => UmbracoSettingsSection.Security.AllowPasswordReset; - public string AuthCookieName => UmbracoSettingsSection.Security.AuthCookieName; - public string AuthCookieDomain => UmbracoSettingsSection.Security.AuthCookieDomain; - public bool UsernameIsEmail => UmbracoSettingsSection.Security.UsernameIsEmail; - } -} diff --git a/src/Umbraco.Configuration/Legacy/SmtpSettings.cs b/src/Umbraco.Configuration/Legacy/SmtpSettings.cs deleted file mode 100644 index dce3d85840..0000000000 --- a/src/Umbraco.Configuration/Legacy/SmtpSettings.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Net.Mail; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration -{ - public class SmtpSettings : ISmtpSettings - { - public string From { get; set; } - public string Host { get; set; } - public int Port { get; set; } - public string PickupDirectoryLocation { get; set; } - public SmtpDeliveryMethod DeliveryMethod { get; set; } - - public string Username { get; set; } - - public string Password { get; set; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/TypeFinderSettings.cs b/src/Umbraco.Configuration/Legacy/TypeFinderSettings.cs deleted file mode 100644 index b1009f754b..0000000000 --- a/src/Umbraco.Configuration/Legacy/TypeFinderSettings.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Legacy -{ - public class TypeFinderSettings : ITypeFinderSettings - { - public TypeFinderSettings() - { - AssembliesAcceptingLoadExceptions = ConfigurationManager.AppSettings[ - Constants.AppSettings.AssembliesAcceptingLoadExceptions]; - } - - public string AssembliesAcceptingLoadExceptions { get; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/UserPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Legacy/UserPasswordConfigurationSettings.cs deleted file mode 100644 index 51dd645c42..0000000000 --- a/src/Umbraco.Configuration/Legacy/UserPasswordConfigurationSettings.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Umbraco.Core.Configuration; -namespace Umbraco.Configuration.Implementations -{ - internal class UserPasswordConfigurationSettings : ConfigurationManagerConfigBase, IUserPasswordConfiguration - { - public int RequiredLength => UmbracoSettingsSection.Security.UserPasswordConfiguration.RequiredLength; - public bool RequireNonLetterOrDigit => UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireNonLetterOrDigit; - public bool RequireDigit => UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireDigit; - public bool RequireLowercase=> UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireLowercase; - public bool RequireUppercase=> UmbracoSettingsSection.Security.UserPasswordConfiguration.RequireUppercase; - public bool UseLegacyEncoding=> UmbracoSettingsSection.Security.UserPasswordConfiguration.UseLegacyEncoding; - public string HashAlgorithmType=> UmbracoSettingsSection.Security.UserPasswordConfiguration.HashAlgorithmType; - public int MaxFailedAccessAttemptsBeforeLockout => UmbracoSettingsSection.Security.UserPasswordConfiguration.MaxFailedAccessAttemptsBeforeLockout; - } -} diff --git a/src/Umbraco.Configuration/Legacy/WebRoutingSettings.cs b/src/Umbraco.Configuration/Legacy/WebRoutingSettings.cs deleted file mode 100644 index cfca66822b..0000000000 --- a/src/Umbraco.Configuration/Legacy/WebRoutingSettings.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal class WebRoutingSettings : ConfigurationManagerConfigBase, IWebRoutingSettings - { - public bool TrySkipIisCustomErrors => UmbracoSettingsSection?.WebRouting?.TrySkipIisCustomErrors ?? false; - public bool InternalRedirectPreservesTemplate => UmbracoSettingsSection?.WebRouting?.InternalRedirectPreservesTemplate ?? false; - public bool DisableAlternativeTemplates => UmbracoSettingsSection?.WebRouting?.DisableAlternativeTemplates ?? false; - public bool ValidateAlternativeTemplates => UmbracoSettingsSection?.WebRouting?.ValidateAlternativeTemplates ?? false; - public bool DisableFindContentByIdPath => UmbracoSettingsSection?.WebRouting?.DisableFindContentByIdPath ?? false; - public bool DisableRedirectUrlTracking => UmbracoSettingsSection?.WebRouting?.DisableRedirectUrlTracking ?? false; - public string UrlProviderMode => UmbracoSettingsSection?.WebRouting?.UrlProviderMode ?? "Auto"; - public string UmbracoApplicationUrl => UmbracoSettingsSection?.WebRouting?.UmbracoApplicationUrl; - } -} diff --git a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs b/src/Umbraco.Configuration/Models/CoreDebugSettings.cs deleted file mode 100644 index 6d6c0eaf0d..0000000000 --- a/src/Umbraco.Configuration/Models/CoreDebugSettings.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class CoreDebugSettings : ICoreDebugSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Core:Debug:"; - private readonly IConfiguration _configuration; - - public CoreDebugSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool LogUncompletedScopes => - _configuration.GetValue(Prefix+"LogUncompletedScopes", false); - - public bool DumpOnTimeoutThreadAbort => - _configuration.GetValue(Prefix+"DumpOnTimeoutThreadAbort", false); - } -} diff --git a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs b/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs deleted file mode 100644 index 581daf9f40..0000000000 --- a/src/Umbraco.Configuration/Models/ExceptionFilterSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class ExceptionFilterSettings : IExceptionFilterSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "ExceptionFilter:"; - private readonly IConfiguration _configuration; - - public ExceptionFilterSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool Disabled => _configuration.GetValue(Prefix+"Disabled", false); - } -} diff --git a/src/Umbraco.Configuration/Models/GlobalSettings.cs b/src/Umbraco.Configuration/Models/GlobalSettings.cs index 02b73d1196..5dfac1f8a3 100644 --- a/src/Umbraco.Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Configuration/Models/GlobalSettings.cs @@ -4,6 +4,7 @@ using System.Net.Mail; using Microsoft.Extensions.Configuration; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Configuration.Models { @@ -77,27 +78,6 @@ namespace Umbraco.Configuration.Models public bool IsSmtpServerConfigured => _configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")?.GetChildren().Any() ?? false; - public ISmtpSettings SmtpSettings => - new SmtpSettingsImpl(_configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")); - - private class SmtpSettingsImpl : ISmtpSettings - { - private readonly IConfigurationSection _configurationSection; - - public SmtpSettingsImpl(IConfigurationSection configurationSection) - { - _configurationSection = configurationSection; - } - - public string From => _configurationSection.GetValue("From"); - public string Host => _configurationSection.GetValue("Host"); - public int Port => _configurationSection.GetValue("Port"); - public string PickupDirectoryLocation => _configurationSection.GetValue("PickupDirectoryLocation"); - public SmtpDeliveryMethod DeliveryMethod => _configurationSection.GetValue("DeliveryMethod"); - - public string Username => _configurationSection.GetValue("Username"); - - public string Password => _configurationSection.GetValue("Password"); - } + public SmtpSettings SmtpSettings => new SmtpSettings(); } } diff --git a/src/Umbraco.Configuration/Models/HealthChecksSettings.cs b/src/Umbraco.Configuration/Models/HealthChecksSettings.cs deleted file mode 100644 index 1e3751b6aa..0000000000 --- a/src/Umbraco.Configuration/Models/HealthChecksSettings.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.HealthChecks; - -namespace Umbraco.Configuration.Models -{ - internal class HealthChecksSettings : IHealthChecksSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "HealthChecks:"; - private readonly IConfiguration _configuration; - - public HealthChecksSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public IEnumerable DisabledChecks => _configuration - .GetSection(Prefix+"DisabledChecks") - .GetChildren() - .Select( - x => new DisabledHealthCheck - { - Id = x.GetValue("Id"), - DisabledOn = x.GetValue("DisabledOn"), - DisabledBy = x.GetValue("DisabledBy") - }); - - public IHealthCheckNotificationSettings NotificationSettings => - new HealthCheckNotificationSettings( - _configuration.GetSection(Prefix+"NotificationSettings")); - - private class DisabledHealthCheck : IDisabledHealthCheck - { - public Guid Id { get; set; } - public DateTime DisabledOn { get; set; } - public int DisabledBy { get; set; } - } - - private class HealthCheckNotificationSettings : IHealthCheckNotificationSettings - { - private readonly IConfigurationSection _configurationSection; - - public HealthCheckNotificationSettings(IConfigurationSection configurationSection) - { - _configurationSection = configurationSection; - } - - public bool Enabled => _configurationSection.GetValue("Enabled", false); - public string FirstRunTime => _configurationSection.GetValue("FirstRunTime"); - public int PeriodInHours => _configurationSection.GetValue("PeriodInHours", 24); - - public IReadOnlyDictionary NotificationMethods => _configurationSection - .GetSection("NotificationMethods") - .GetChildren() - .ToDictionary(x => x.Key, x => (INotificationMethod) new NotificationMethod(x.Key, x), StringComparer.InvariantCultureIgnoreCase); - - public IEnumerable DisabledChecks => _configurationSection - .GetSection("DisabledChecks").GetChildren().Select( - x => new DisabledHealthCheck - { - Id = x.GetValue("Id"), - DisabledOn = x.GetValue("DisabledOn"), - DisabledBy = x.GetValue("DisabledBy") - }); - } - - private class NotificationMethod : INotificationMethod - { - private readonly IConfigurationSection _configurationSection; - - public NotificationMethod(string alias, IConfigurationSection configurationSection) - { - Alias = alias; - _configurationSection = configurationSection; - } - - public string Alias { get; } - public bool Enabled => _configurationSection.GetValue("Enabled", false); - - public HealthCheckNotificationVerbosity Verbosity => - _configurationSection.GetValue("Verbosity", HealthCheckNotificationVerbosity.Summary); - - public bool FailureOnly => _configurationSection.GetValue("FailureOnly", true); - - public IReadOnlyDictionary Settings => _configurationSection - .GetSection("Settings").GetChildren().ToDictionary(x => x.Key, - x => (INotificationMethodSettings) new NotificationMethodSettings(x.Key, x.Value), StringComparer.InvariantCultureIgnoreCase); - } - - private class NotificationMethodSettings : INotificationMethodSettings - { - public NotificationMethodSettings(string key, string value) - { - Key = key; - Value = value; - } - - public string Key { get; } - public string Value { get; } - } - } -} diff --git a/src/Umbraco.Configuration/Models/HostingSettings.cs b/src/Umbraco.Configuration/Models/HostingSettings.cs deleted file mode 100644 index f0fbcf4cab..0000000000 --- a/src/Umbraco.Configuration/Models/HostingSettings.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class HostingSettings : IHostingSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Hosting:"; - private readonly IConfiguration _configuration; - - public HostingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - /// - public LocalTempStorage LocalTempStorageLocation => - _configuration.GetValue(Prefix+"LocalTempStorage", LocalTempStorage.Default); - - public string ApplicationVirtualPath => null; - - /// - /// Gets a value indicating whether umbraco is running in [debug mode]. - /// - /// true if [debug mode]; otherwise, false. - public bool DebugMode => _configuration.GetValue(Prefix+"Debug", false); - } -} diff --git a/src/Umbraco.Configuration/Models/ImagingSettings.cs b/src/Umbraco.Configuration/Models/ImagingSettings.cs deleted file mode 100644 index 4a9501b2ba..0000000000 --- a/src/Umbraco.Configuration/Models/ImagingSettings.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class ImagingSettings : IImagingSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Imaging:"; - private const string CachePrefix = Prefix + "Cache:"; - private const string ResizePrefix = Prefix + "Resize:"; - private readonly IConfiguration _configuration; - - public ImagingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int MaxBrowserCacheDays => _configuration.GetValue(CachePrefix + "MaxBrowserCacheDays", 7); - public int MaxCacheDays => _configuration.GetValue(CachePrefix + "MaxCacheDays", 365); - public uint CachedNameLength => _configuration.GetValue(CachePrefix + "CachedNameLength", (uint) 8); - public string CacheFolder => _configuration.GetValue(CachePrefix + "Folder", "../App_Data/Cache"); - public int MaxResizeWidth => _configuration.GetValue(ResizePrefix + "MaxWidth", 5000); - public int MaxResizeHeight => _configuration.GetValue(ResizePrefix + "MaxHeight", 5000); - } -} diff --git a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs deleted file mode 100644 index 5a8313a351..0000000000 --- a/src/Umbraco.Configuration/Models/MemberPasswordConfigurationSettings.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class MemberPasswordConfigurationSettings : IMemberPasswordConfiguration - { - private const string Prefix = Constants.Configuration.ConfigSecurityPrefix + "MemberPassword:"; - private readonly IConfiguration _configuration; - - public MemberPasswordConfigurationSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int RequiredLength => - _configuration.GetValue(Prefix + "RequiredLength", 10); - - public bool RequireNonLetterOrDigit => - _configuration.GetValue(Prefix + "RequireNonLetterOrDigit", false); - - public bool RequireDigit => - _configuration.GetValue(Prefix + "RequireDigit", false); - - public bool RequireLowercase => - _configuration.GetValue(Prefix + "RequireLowercase", false); - - public bool RequireUppercase => - _configuration.GetValue(Prefix + "RequireUppercase", false); - - public string HashAlgorithmType => - _configuration.GetValue(Prefix + "HashAlgorithmType", Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName); // TODO: Need to change to current format when we do members - - public int MaxFailedAccessAttemptsBeforeLockout => - _configuration.GetValue(Prefix + "MaxFailedAccessAttemptsBeforeLockout", 5); - } -} diff --git a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs b/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs deleted file mode 100644 index 4d35e3fa95..0000000000 --- a/src/Umbraco.Configuration/Models/ModelsBuilderConfig.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - /// - /// Represents the models builder configuration. - /// - internal class ModelsBuilderConfig : IModelsBuilderConfig - { - private const string Prefix = Constants.Configuration.ConfigModelsBuilderPrefix; - private readonly IConfiguration _configuration; - - /// - /// Initializes a new instance of the class. - /// - public ModelsBuilderConfig(IConfiguration configuration) - { - _configuration = configuration; - } - - public string DefaultModelsDirectory => "~/Umbraco/Models"; - - /// - /// Gets a value indicating whether the whole models experience is enabled. - /// - /// - /// If this is false then absolutely nothing happens. - /// Default value is false which means that unless we have this setting, nothing happens. - /// - public bool Enable => _configuration.GetValue(Prefix+"Enable", false); - - /// - /// Gets the models mode. - /// - public ModelsMode ModelsMode => - _configuration.GetValue(Prefix+"ModelsMode", ModelsMode.Nothing); - - /// - /// Gets the models namespace. - /// - /// That value could be overriden by other (attribute in user's code...). Return default if no value was supplied. - public string ModelsNamespace => _configuration.GetValue(Prefix+"ModelsNamespace"); - - /// - /// Gets a value indicating whether we should enable the models factory. - /// - /// Default value is true because no factory is enabled by default in Umbraco. - public bool EnableFactory => _configuration.GetValue(Prefix+"EnableFactory", true); - - /// - /// Gets a value indicating whether we should flag out-of-date models. - /// - /// - /// Models become out-of-date when data types or content types are updated. When this - /// setting is activated the ~/App_Data/Models/ood.txt file is then created. When models are - /// generated through the dashboard, the files is cleared. Default value is false. - /// - public bool FlagOutOfDateModels => - _configuration.GetValue(Prefix+"FlagOutOfDateModels", false) && !ModelsMode.IsLive(); - - /// - /// Gets the models directory. - /// - /// Default is ~/App_Data/Models but that can be changed. - public string ModelsDirectory => - _configuration.GetValue(Prefix+"ModelsDirectory", "~/Umbraco/Models"); - - /// - /// Gets a value indicating whether to accept an unsafe value for ModelsDirectory. - /// - /// - /// An unsafe value is an absolute path, or a relative path pointing outside - /// of the website root. - /// - public bool AcceptUnsafeModelsDirectory => - _configuration.GetValue(Prefix+"AcceptUnsafeModelsDirectory", false); - - /// - /// Gets a value indicating the debug log level. - /// - /// 0 means minimal (safe on live site), anything else means more and more details (maybe not safe). - public int DebugLevel => _configuration.GetValue(Prefix+"DebugLevel", 0); - } -} diff --git a/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs deleted file mode 100644 index ce5cd65c20..0000000000 --- a/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models -{ - internal class RequestHandlerSettings : IRequestHandlerSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "RequestHandler:"; - private static readonly CharItem[] DefaultCharCollection = - { - new CharItem { Char = " ", Replacement = "-" }, - new CharItem { Char = "\"", Replacement = "" }, - new CharItem { Char = "'", Replacement = "" }, - new CharItem { Char = "%", Replacement = "" }, - new CharItem { Char = ".", Replacement = "" }, - new CharItem { Char = ";", Replacement = "" }, - new CharItem { Char = "/", Replacement = "" }, - new CharItem { Char = "\\", Replacement = "" }, - new CharItem { Char = ":", Replacement = "" }, - new CharItem { Char = "#", Replacement = "" }, - new CharItem { Char = "+", Replacement = "plus" }, - new CharItem { Char = "*", Replacement = "star" }, - new CharItem { Char = "&", Replacement = "" }, - new CharItem { Char = "?", Replacement = "" }, - new CharItem { Char = "æ", Replacement = "ae" }, - new CharItem { Char = "ä", Replacement = "ae" }, - new CharItem { Char = "ø", Replacement = "oe" }, - new CharItem { Char = "ö", Replacement = "oe" }, - new CharItem { Char = "å", Replacement = "aa" }, - new CharItem { Char = "ü", Replacement = "ue" }, - new CharItem { Char = "ß", Replacement = "ss" }, - new CharItem { Char = "|", Replacement = "-" }, - new CharItem { Char = "<", Replacement = "" }, - new CharItem { Char = ">", Replacement = "" } - }; - - private readonly IConfiguration _configuration; - - public RequestHandlerSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool AddTrailingSlash => - _configuration.GetValue(Prefix+"AddTrailingSlash", true); - - public bool ConvertUrlsToAscii => _configuration - .GetValue(Prefix+"ConvertUrlsToAscii").InvariantEquals("true"); - - public bool TryConvertUrlsToAscii => _configuration - .GetValue(Prefix+"ConvertUrlsToAscii").InvariantEquals("try"); - - - //We need to special handle ":", as this character is special in keys - public IEnumerable CharCollection - { - get - { - var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren() - .Select(x => new CharItem() - { - Char = x.GetValue("Char"), - Replacement = x.GetValue("Replacement"), - }).ToArray(); - - if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x => - x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase))) - { - return collection; - } - - return DefaultCharCollection; - } - } - - - public class CharItem : IChar - { - public string Char { get; set; } - public string Replacement { get; set; } - } - } -} diff --git a/src/Umbraco.Configuration/Models/RuntimeSettings.cs b/src/Umbraco.Configuration/Models/RuntimeSettings.cs deleted file mode 100644 index ef129030b6..0000000000 --- a/src/Umbraco.Configuration/Models/RuntimeSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class RuntimeSettings : IRuntimeSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Runtime:"; - private readonly IConfiguration _configuration; - public RuntimeSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int? MaxQueryStringLength => _configuration.GetValue(Prefix+"MaxRequestLength"); - public int? MaxRequestLength => _configuration.GetValue(Prefix+"MaxRequestLength"); - } -} diff --git a/src/Umbraco.Configuration/Models/SecuritySettings.cs b/src/Umbraco.Configuration/Models/SecuritySettings.cs deleted file mode 100644 index 297c95b1af..0000000000 --- a/src/Umbraco.Configuration/Models/SecuritySettings.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Models -{ - internal class SecuritySettings : ISecuritySettings - { - private const string Prefix = Constants.Configuration.ConfigSecurityPrefix; - private readonly IConfiguration _configuration; - - public SecuritySettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool KeepUserLoggedIn => _configuration.GetValue(Prefix + "KeepUserLoggedIn", false); - - public bool HideDisabledUsersInBackoffice => - _configuration.GetValue(Prefix + "HideDisabledUsersInBackoffice", false); - - public bool AllowPasswordReset => - _configuration.GetValue(Prefix + "AllowPasswordResetAllowPasswordReset", true); - - public string AuthCookieName => - _configuration.GetValue(Prefix + "AuthCookieName", "UMB_UCONTEXT"); - - public string AuthCookieDomain => - _configuration.GetValue(Prefix + "AuthCookieDomain"); - - public bool UsernameIsEmail => _configuration.GetValue(Prefix + "UsernameIsEmail", true); - } -} diff --git a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs b/src/Umbraco.Configuration/Models/TypeFinderSettings.cs deleted file mode 100644 index 8a1f7ac9e0..0000000000 --- a/src/Umbraco.Configuration/Models/TypeFinderSettings.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class TypeFinderSettings : ITypeFinderSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "TypeFinder:"; - private readonly IConfiguration _configuration; - - public TypeFinderSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string AssembliesAcceptingLoadExceptions => - _configuration.GetValue(Prefix+"AssembliesAcceptingLoadExceptions"); - } -} diff --git a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs b/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs deleted file mode 100644 index 25ce3e3d9a..0000000000 --- a/src/Umbraco.Configuration/Models/UserPasswordConfigurationSettings.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Configuration.Models -{ - internal class UserPasswordConfigurationSettings : IUserPasswordConfiguration - { - private const string Prefix = Constants.Configuration.ConfigSecurityPrefix + "UserPassword:"; - private readonly IConfiguration _configuration; - - public UserPasswordConfigurationSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public int RequiredLength => _configuration.GetValue(Prefix + "RequiredLength", 10); - - public bool RequireNonLetterOrDigit => - _configuration.GetValue(Prefix + "RequireNonLetterOrDigit", false); - - public bool RequireDigit => _configuration.GetValue(Prefix + "RequireDigit", false); - - public bool RequireLowercase => - _configuration.GetValue(Prefix + "RequireLowercase", false); - - public bool RequireUppercase => - _configuration.GetValue(Prefix + "RequireUppercase", false); - - public string HashAlgorithmType => - _configuration.GetValue(Prefix + "HashAlgorithmType", Constants.Security.AspNetCoreV3PasswordHashAlgorithmName); - - public int MaxFailedAccessAttemptsBeforeLockout => - _configuration.GetValue(Prefix + "MaxFailedAccessAttemptsBeforeLockout", 5); - } -} diff --git a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs b/src/Umbraco.Configuration/Models/WebRoutingSettings.cs deleted file mode 100644 index 9ac856ca9f..0000000000 --- a/src/Umbraco.Configuration/Models/WebRoutingSettings.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Models.PublishedContent; - -namespace Umbraco.Configuration.Models -{ - internal class WebRoutingSettings : IWebRoutingSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "WebRouting:"; - private readonly IConfiguration _configuration; - - public WebRoutingSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public bool TrySkipIisCustomErrors => - _configuration.GetValue(Prefix + "TrySkipIisCustomErrors", false); - - public bool InternalRedirectPreservesTemplate => - _configuration.GetValue(Prefix + "InternalRedirectPreservesTemplate", false); - - public bool DisableAlternativeTemplates => - _configuration.GetValue(Prefix + "DisableAlternativeTemplates", false); - - public bool ValidateAlternativeTemplates => - _configuration.GetValue(Prefix + "ValidateAlternativeTemplates", false); - - public bool DisableFindContentByIdPath => - _configuration.GetValue(Prefix + "DisableFindContentByIdPath", false); - - public bool DisableRedirectUrlTracking => - _configuration.GetValue(Prefix + "DisableRedirectUrlTracking", false); - - public string UrlProviderMode => - _configuration.GetValue(Prefix + "UrlProviderMode", UrlMode.Auto.ToString()); - - public string UmbracoApplicationUrl => - _configuration.GetValue(Prefix + "UmbracoApplicationUrl"); - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs deleted file mode 100644 index f959a56e71..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Configuration; -using System.Globalization; -using System.Collections.Generic; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSettings - { - [ConfigurationProperty("addTrailingSlash")] - public InnerTextConfigurationElement AddTrailingSlash => GetOptionalTextElement("addTrailingSlash", true); - - private UrlReplacingElement _defaultUrlReplacing; - [ConfigurationProperty("urlReplacing")] - public UrlReplacingElement UrlReplacing - { - get - { - if (_defaultUrlReplacing != null) - { - return _defaultUrlReplacing; - } - - //here we need to check if this element is defined, if it is not then we'll setup the defaults - var prop = Properties["urlReplacing"]; - var urls = this[prop] as ConfigurationElement; - if (urls != null && urls.ElementInformation.IsPresent == false) - { - _defaultUrlReplacing = new UrlReplacingElement() - { - CharCollection = GetDefaultCharReplacements() - }; - - return _defaultUrlReplacing; - } - - return (UrlReplacingElement)this["urlReplacing"]; - } - } - - public static CharCollection GetDefaultCharReplacements() - { - var dictionary = new Dictionary() - { - {' ',"-"}, - {'\"',""}, - {'\'',""}, - {'%',""}, - {'.',""}, - {';',""}, - {'/',""}, - {'\\',""}, - {':',""}, - {'#',""}, - {'+',"plus"}, - {'*',"star"}, - {'&',""}, - {'?',""}, - {'æ',"ae"}, - {'ø',"oe"}, - {'å',"aa"}, - {'ä',"ae"}, - {'ö',"oe"}, - {'ü',"ue"}, - {'ß',"ss"}, - {'Ä',"ae"}, - {'Ö',"oe"}, - {'|',"-"}, - {'<',""}, - {'>',""} - }; - - //const string chars = @" ,"",',%,.,;,/,\,:,#,+,*,&,?,æ,ø,å,ä,ö,ü,ß,Ä,Ö,|,<,>"; - - var collection = new CharCollection(); - foreach (var c in dictionary) - { - collection.Add(new CharElement - { - Char = c.Key.ToString(CultureInfo.InvariantCulture), - Replacement = c.Value.ToString(CultureInfo.InvariantCulture) - }); - } - - return collection; - } - - bool IRequestHandlerSettings.AddTrailingSlash => AddTrailingSlash; - - bool IRequestHandlerSettings.ConvertUrlsToAscii => UrlReplacing.ConvertUrlsToAscii.InvariantEquals("true"); - - bool IRequestHandlerSettings.TryConvertUrlsToAscii => UrlReplacing.ConvertUrlsToAscii.InvariantEquals("try"); - - IEnumerable IRequestHandlerSettings.CharCollection => UrlReplacing.CharCollection; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs deleted file mode 100644 index aec6809298..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class SecurityElement : UmbracoConfigurationElement, ISecuritySettings - { - [ConfigurationProperty("keepUserLoggedIn")] - internal InnerTextConfigurationElement KeepUserLoggedIn => GetOptionalTextElement("keepUserLoggedIn", true); - - [ConfigurationProperty("hideDisabledUsersInBackoffice")] - internal InnerTextConfigurationElement HideDisabledUsersInBackoffice => GetOptionalTextElement("hideDisabledUsersInBackoffice", false); - - /// - /// Used to enable/disable the forgot password functionality on the back office login screen - /// - [ConfigurationProperty("allowPasswordReset")] - internal InnerTextConfigurationElement AllowPasswordReset => GetOptionalTextElement("allowPasswordReset", true); - - /// - /// A boolean indicating that by default the email address will be the username - /// - /// - /// Even if this is true and the username is different from the email in the database, the username field will still be shown. - /// When this is false, the username and email fields will be shown in the user section. - /// - [ConfigurationProperty("usernameIsEmail")] - internal InnerTextConfigurationElement UsernameIsEmail => GetOptionalTextElement("usernameIsEmail", true); - - [ConfigurationProperty("authCookieName")] - internal InnerTextConfigurationElement AuthCookieName => GetOptionalTextElement("authCookieName", "UMB_UCONTEXT"); - - [ConfigurationProperty("authCookieDomain")] - internal InnerTextConfigurationElement AuthCookieDomain => GetOptionalTextElement("authCookieDomain", null); - - [ConfigurationProperty("userPasswordConfiguration")] - public UserPasswordConfigurationElement UserPasswordConfiguration => (UserPasswordConfigurationElement)this["userPasswordConfiguration"]; - - [ConfigurationProperty("memberPasswordConfiguration")] - public MemberPasswordConfigurationElement MemberPasswordConfiguration => (MemberPasswordConfigurationElement)this["memberPasswordConfiguration"]; - - bool ISecuritySettings.KeepUserLoggedIn => KeepUserLoggedIn; - - bool ISecuritySettings.HideDisabledUsersInBackoffice => HideDisabledUsersInBackoffice; - - /// - /// Used to enable/disable the forgot password functionality on the back office login screen - /// - bool ISecuritySettings.AllowPasswordReset => AllowPasswordReset; - - /// - /// A boolean indicating that by default the email address will be the username - /// - /// - /// Even if this is true and the username is different from the email in the database, the username field will still be shown. - /// When this is false, the username and email fields will be shown in the user section. - /// - bool ISecuritySettings.UsernameIsEmail => UsernameIsEmail; - - string ISecuritySettings.AuthCookieName => AuthCookieName; - - string ISecuritySettings.AuthCookieDomain => AuthCookieDomain; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs index 34e3c9c242..e8ab155ef1 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -8,14 +8,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings [ConfigurationProperty("content")] public ContentElement Content => (ContentElement)this["content"]; - [ConfigurationProperty("security")] - public SecurityElement Security => (SecurityElement)this["security"]; - - [ConfigurationProperty("requestHandler")] - public RequestHandlerElement RequestHandler => (RequestHandlerElement)this["requestHandler"]; - - [ConfigurationProperty("web.routing")] - public WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; } } diff --git a/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs deleted file mode 100644 index 206fc213d2..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class WebRoutingElement : ConfigurationElement, IWebRoutingSettings - { - [ConfigurationProperty("trySkipIisCustomErrors", DefaultValue = "false")] - public bool TrySkipIisCustomErrors => (bool) base["trySkipIisCustomErrors"]; - - [ConfigurationProperty("internalRedirectPreservesTemplate", DefaultValue = "false")] - public bool InternalRedirectPreservesTemplate => (bool) base["internalRedirectPreservesTemplate"]; - - [ConfigurationProperty("disableAlternativeTemplates", DefaultValue = "false")] - public bool DisableAlternativeTemplates => (bool) base["disableAlternativeTemplates"]; - - [ConfigurationProperty("validateAlternativeTemplates", DefaultValue = "false")] - public bool ValidateAlternativeTemplates => (bool) base["validateAlternativeTemplates"]; - - [ConfigurationProperty("disableFindContentByIdPath", DefaultValue = "false")] - public bool DisableFindContentByIdPath => (bool) base["disableFindContentByIdPath"]; - - [ConfigurationProperty("disableRedirectUrlTracking", DefaultValue = "false")] - public bool DisableRedirectUrlTracking => (bool) base["disableRedirectUrlTracking"]; - - [ConfigurationProperty("urlProviderMode", DefaultValue = "Auto")] - public string UrlProviderMode => (string) base["urlProviderMode"]; - - [ConfigurationProperty("umbracoApplicationUrl", DefaultValue = null)] - public string UmbracoApplicationUrl => (string)base["umbracoApplicationUrl"]; - } -} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs b/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs deleted file mode 100644 index 4564e87ed6..0000000000 --- a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public interface IHealthCheckNotificationSettings - { - bool Enabled { get; } - string FirstRunTime { get; } - int PeriodInHours { get; } - IReadOnlyDictionary NotificationMethods { get; } - IEnumerable DisabledChecks { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSettings.cs b/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSettings.cs deleted file mode 100644 index 785e8d5651..0000000000 --- a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSettings.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public interface IHealthChecksSettings - { - IEnumerable DisabledChecks { get; } - IHealthCheckNotificationSettings NotificationSettings { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/ICoreDebugSettings.cs b/src/Umbraco.Core/Configuration/ICoreDebugSettings.cs deleted file mode 100644 index 586e4bc3e4..0000000000 --- a/src/Umbraco.Core/Configuration/ICoreDebugSettings.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface ICoreDebugSettings - { - /// - /// When set to true, Scope logs the stack trace for any scope that gets disposed without being completed. - /// this helps troubleshooting rogue scopes that we forget to complete - /// - bool LogUncompletedScopes { get; } - - /// - /// When set to true, the Logger creates a mini dump of w3wp in ~/App_Data/MiniDump whenever it logs - /// an error due to a ThreadAbortException that is due to a timeout. - /// - bool DumpOnTimeoutThreadAbort { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/IExceptionFilterSettings.cs b/src/Umbraco.Core/Configuration/IExceptionFilterSettings.cs deleted file mode 100644 index 169c04da5f..0000000000 --- a/src/Umbraco.Core/Configuration/IExceptionFilterSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IExceptionFilterSettings - { - bool Disabled { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/IGlobalSettings.cs b/src/Umbraco.Core/Configuration/IGlobalSettings.cs index 26d833613f..ac32ea41c6 100644 --- a/src/Umbraco.Core/Configuration/IGlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/IGlobalSettings.cs @@ -1,4 +1,6 @@ -namespace Umbraco.Core.Configuration +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Core.Configuration { /// /// Contains general settings information for the entire Umbraco instance based on information from web.config appsettings @@ -70,7 +72,7 @@ string UmbracoMediaPath { get; } bool IsSmtpServerConfigured { get; } - ISmtpSettings SmtpSettings { get; } + SmtpSettings SmtpSettings { get; } /// /// Gets a value indicating whether the runtime should enter Install level when the database is missing. diff --git a/src/Umbraco.Core/Configuration/IHostingSettings.cs b/src/Umbraco.Core/Configuration/IHostingSettings.cs deleted file mode 100644 index 48ff4f216e..0000000000 --- a/src/Umbraco.Core/Configuration/IHostingSettings.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Umbraco.Core.Hosting; - -namespace Umbraco.Core.Configuration -{ - public interface IHostingSettings - { - bool DebugMode { get; } - - /// - /// Gets the configuration for the location of temporary files. - /// - LocalTempStorage LocalTempStorageLocation { get; } - - /// - /// Optional property to explicitly configure the application's virtual path - /// - /// - /// By default this is null which will mean that the is automatically configured, - /// otherwise this explicitly sets it. - /// If set, this value must begin with a "/" and cannot end with "/". - /// - string ApplicationVirtualPath { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/IImagingSettings.cs b/src/Umbraco.Core/Configuration/IImagingSettings.cs deleted file mode 100644 index 13e1b30389..0000000000 --- a/src/Umbraco.Core/Configuration/IImagingSettings.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IImagingSettings - { - int MaxBrowserCacheDays { get;} - int MaxCacheDays { get; } - uint CachedNameLength { get; } - int MaxResizeWidth { get; } - int MaxResizeHeight { get; } - string CacheFolder { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/IModelsBuilderConfig.cs b/src/Umbraco.Core/Configuration/IModelsBuilderConfig.cs deleted file mode 100644 index 990bde9843..0000000000 --- a/src/Umbraco.Core/Configuration/IModelsBuilderConfig.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IModelsBuilderConfig - { - bool Enable { get; } - bool AcceptUnsafeModelsDirectory { get; } - int DebugLevel { get; } - bool EnableFactory { get; } - bool FlagOutOfDateModels { get; } - string ModelsDirectory { get; } - ModelsMode ModelsMode { get; } - string ModelsNamespace { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/IRuntimeSettings.cs b/src/Umbraco.Core/Configuration/IRuntimeSettings.cs deleted file mode 100644 index 915e774186..0000000000 --- a/src/Umbraco.Core/Configuration/IRuntimeSettings.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - public interface IRuntimeSettings - { - int? MaxQueryStringLength { get; } - int? MaxRequestLength { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/ISmtpSettings.cs b/src/Umbraco.Core/Configuration/ISmtpSettings.cs deleted file mode 100644 index ea42ae5567..0000000000 --- a/src/Umbraco.Core/Configuration/ISmtpSettings.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Net.Mail; - -namespace Umbraco.Core.Configuration -{ - public interface ISmtpSettings - { - string From { get; } - string Host { get; } - int Port{ get; } - string PickupDirectoryLocation { get; } - SmtpDeliveryMethod DeliveryMethod { get; } - string Username { get; } - string Password { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IRequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IRequestHandlerSettings.cs deleted file mode 100644 index 11fdaa8310..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IRequestHandlerSettings.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IRequestHandlerSettings : IUmbracoConfigurationSection - { - bool AddTrailingSlash { get; } - - bool ConvertUrlsToAscii { get; } - - bool TryConvertUrlsToAscii { get; } - - IEnumerable CharCollection { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ISecuritySettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/ISecuritySettings.cs deleted file mode 100644 index 6ab520fefd..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ISecuritySettings.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface ISecuritySettings : IUmbracoConfigurationSection - { - bool KeepUserLoggedIn { get; } - - bool HideDisabledUsersInBackoffice { get; } - - /// - /// Used to enable/disable the forgot password functionality on the back office login screen - /// - bool AllowPasswordReset { get; } - - string AuthCookieName { get; } - - string AuthCookieDomain { get; } - - /// - /// A boolean indicating that by default the email address will be the username - /// - /// - /// Even if this is true and the username is different from the email in the database, the username field will still be shown. - /// When this is false, the username and email fields will be shown in the user section. - /// - bool UsernameIsEmail { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSettings.cs deleted file mode 100644 index f7f6a94d30..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSettings.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IWebRoutingSettings : IUmbracoConfigurationSection - { - bool TrySkipIisCustomErrors { get; } - - bool InternalRedirectPreservesTemplate { get; } - - bool DisableAlternativeTemplates { get; } - - bool ValidateAlternativeTemplates { get; } - - bool DisableFindContentByIdPath { get; } - - bool DisableRedirectUrlTracking { get; } - - string UrlProviderMode { get; } - - string UmbracoApplicationUrl { get; } - } -} diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs index fd03610bb4..278bbcfca2 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs @@ -62,20 +62,5 @@ namespace Umbraco.Infrastructure.Configuration RequireUppercase = passwordConfiguration.RequireUppercase, }; } - - public static SecuritySettings ConvertSecuritySettings(ISecuritySettings securitySettings) - { - return new SecuritySettings - { - MemberPassword = new MemberPasswordConfigurationSettings(), - UserPassword = new UserPasswordConfigurationSettings(), - AllowPasswordReset = securitySettings.AllowPasswordReset, - AuthCookieDomain = securitySettings.AuthCookieDomain, - AuthCookieName = securitySettings.AuthCookieDomain, - UsernameIsEmail = securitySettings.UsernameIsEmail, - KeepUserLoggedIn = securitySettings.KeepUserLoggedIn, - HideDisabledUsersInBackoffice = securitySettings.HideDisabledUsersInBackoffice, - }; - } } } diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs index b2b6a3928d..ca4c1cd29e 100644 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs +++ b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs @@ -28,7 +28,7 @@ namespace Umbraco.Infrastructure.Configuration RegisterType = globalSettings.RegisterType, ReservedPaths = globalSettings.ReservedPaths, ReservedUrls = globalSettings.ReservedUrls, - SmtpSettings = new TestSmtpSettings + SmtpSettings = new SmtpSettings { DeliveryMethod = globalSettings.Smtp.DeliveryMethod, From = globalSettings.Smtp.From, @@ -88,7 +88,7 @@ namespace Umbraco.Infrastructure.Configuration public bool IsSmtpServerConfigured { get; set; } - public ISmtpSettings SmtpSettings { get; set; } + public SmtpSettings SmtpSettings { get; set; } public bool InstallMissingDatabase { get; set; } @@ -109,22 +109,6 @@ namespace Umbraco.Infrastructure.Configuration public string ConfigurationStatus { get; set; } } - private class TestSmtpSettings : ISmtpSettings - { - public string From { get; set; } - - public string Host { get; set; } - - public int Port { get; set; } - - public string PickupDirectoryLocation { get; set; } - - public SmtpDeliveryMethod DeliveryMethod { get; set; } - - public string Username { get; set; } - - public string Password { get; set; } - } private class TestUserPasswordConfiguration : IUserPasswordConfiguration { diff --git a/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs b/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs index 8f3c05f5bd..0b27b34875 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs @@ -71,7 +71,7 @@ namespace Umbraco.Web.HealthCheck foreach (var checkResult in checkResults) { - Logger.Info("Result for {HealthCheckName}: {HealthCheckResult}, Message: '{HealthCheckMessage}'", checkName, checkResult.ResultType, checkResult.Message); + Logger.Info("'Result for {HealthCheckName}: {HealthCheckResult}, Message: '{HealthCheckMessage}'", checkName, checkResult.ResultType, checkResult.Message); } } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs index 192849aa86..1088dfb470 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComponent.cs @@ -4,9 +4,8 @@ using System.Reflection; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Options; using Umbraco.Configuration; -using Umbraco.Configuration.Legacy; -using Umbraco.Core.Configuration; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; diff --git a/src/Umbraco.Tests.Common/SettingsForTests.cs b/src/Umbraco.Tests.Common/SettingsForTests.cs index 1a14dc6bc1..ee46e5c82f 100644 --- a/src/Umbraco.Tests.Common/SettingsForTests.cs +++ b/src/Umbraco.Tests.Common/SettingsForTests.cs @@ -101,11 +101,9 @@ namespace Umbraco.Tests.Common private void ResetSettings() { _defaultGlobalSettings.Clear(); - _defaultHostingSettings = null; } private readonly Dictionary _defaultGlobalSettings = new Dictionary(); - private IHostingSettings _defaultHostingSettings; public IGlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion) { @@ -117,48 +115,6 @@ namespace Umbraco.Tests.Common return settings; } - public IHostingSettings DefaultHostingSettings => _defaultHostingSettings ?? (_defaultHostingSettings = GenerateMockHostingSettings()); - - public IHostingSettings GenerateMockHostingSettings() - { - var config = Mock.Of( - settings => - settings.LocalTempStorageLocation == LocalTempStorage.EnvironmentTemp && - settings.DebugMode == false - ); - return config; - } - - public IWebRoutingSettings GenerateMockWebRoutingSettings() - { - var mock = new Mock(); - - mock.Setup(x => x.DisableRedirectUrlTracking).Returns(false); - mock.Setup(x => x.InternalRedirectPreservesTemplate).Returns(false); - mock.Setup(x => x.UrlProviderMode).Returns(UrlMode.Auto.ToString()); - - return mock.Object; - } - - public IRequestHandlerSettings GenerateMockRequestHandlerSettings() - { - var mock = new Mock(); - - mock.Setup(x => x.AddTrailingSlash).Returns(true); - mock.Setup(x => x.ConvertUrlsToAscii).Returns(false); - mock.Setup(x => x.TryConvertUrlsToAscii).Returns(false); - mock.Setup(x => x.CharCollection).Returns(RequestHandlerElement.GetDefaultCharReplacements); - - return mock.Object; - } - - public ISecuritySettings GenerateMockSecuritySettings() - { - var security = new Mock(); - - return security.Object; - } - public IUserPasswordConfiguration GenerateMockUserPasswordConfiguration() { var mock = new Mock(); diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 234767e8af..65b4002b0d 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Diagnostics; using Umbraco.Core.Hosting; @@ -76,7 +77,7 @@ namespace Umbraco.Tests.Common public abstract IDbProviderFactoryCreator DbProviderFactoryCreator { get; } public abstract IBulkSqlInsertProvider BulkSqlInsertProvider { get; } public abstract IMarchal Marchal { get; } - public ICoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); + public CoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); public IIOHelper IOHelper { @@ -100,8 +101,6 @@ namespace Umbraco.Tests.Common } public SettingsForTests SettingsForTests { get; } - public IWebRoutingSettings WebRoutingSettings => SettingsForTests.GenerateMockWebRoutingSettings(); - /// /// Some test files are copied to the /bin (/bin/debug) on build, this is a utility to return their physical path based on a virtual path name /// diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs deleted file mode 100644 index 31edde3600..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementDefaultTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Linq; -using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class ContentElementDefaultTests : ContentElementTests - { - protected override bool TestingDefaults => true; - - [Test] - public override void DisableHtmlEmail() - { - Assert.IsTrue(ContentSettings.DisableHtmlEmail == false); - } - - [Test] - public override void Can_Set_Multiple() - { - Assert.IsTrue(ContentSettings.Error404Collection.Count() == 1); - Assert.IsTrue(ContentSettings.Error404Collection.ElementAt(0).Culture == null); - Assert.IsTrue(ContentSettings.Error404Collection.ElementAt(0).ContentId == 1); - } - - [Test] - public override void ImageAutoFillProperties() - { - Assert.IsTrue(ContentSettings.ImageAutoFillProperties.Count() == 1); - Assert.IsTrue(ContentSettings.ImageAutoFillProperties.ElementAt(0).Alias == "umbracoFile"); - Assert.IsTrue(ContentSettings.ImageAutoFillProperties.ElementAt(0).WidthFieldAlias == "umbracoWidth"); - Assert.IsTrue(ContentSettings.ImageAutoFillProperties.ElementAt(0).HeightFieldAlias == "umbracoHeight"); - Assert.IsTrue(ContentSettings.ImageAutoFillProperties.ElementAt(0).LengthFieldAlias == "umbracoBytes"); - Assert.IsTrue(ContentSettings.ImageAutoFillProperties.ElementAt(0).ExtensionFieldAlias == "umbracoExtension"); - } - - /// - /// Whitelist is empty in default settings file and is not populated by default, but disallowed is empty and is populated by default - /// - /// - /// - [Test] - [TestCase("png", true)] - [TestCase("jpg", true)] - [TestCase("gif", true)] - [TestCase("bmp", true)] - [TestCase("php", true)] - [TestCase("ashx", false)] - [TestCase("config", false)] - [TestCase("test", true)] - public override void IsFileAllowedForUpload_WithWhitelist(string extension, bool expected) - { - Console.WriteLine("Extension being tested: {0}", extension); - Console.WriteLine("Expected IsAllowed?: {0}", expected); - Console.WriteLine("AllowedUploadFiles: {0}", ContentSettings.AllowedUploadFiles); - Console.WriteLine("DisallowedUploadFiles: {0}", ContentSettings.DisallowedUploadFiles); - - bool allowedContainsExtension = ContentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)); - bool disallowedContainsExtension = ContentSettings.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)); - - Console.WriteLine("AllowedContainsExtension: {0}", allowedContainsExtension); - Console.WriteLine("DisallowedContainsExtension: {0}", disallowedContainsExtension); - - Assert.AreEqual(expected, ContentSettings.IsFileAllowedForUpload(extension)); - } - - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs deleted file mode 100644 index 85dc2f0ea6..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/ContentElementTests.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Linq; -using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Macros; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class ContentElementTests : UmbracoSettingsTests - { - [Test] - public void EmailAddress() - { - Assert.AreEqual(ContentSettings.NotificationEmailAddress, "robot@umbraco.dk"); - } - [Test] - public virtual void DisableHtmlEmail() - { - Assert.IsTrue(ContentSettings.DisableHtmlEmail); - } - - [Test] - public virtual void Can_Set_Multiple() - { - Assert.AreEqual(3, ContentSettings.Error404Collection.Count()); - Assert.AreEqual("default", ContentSettings.Error404Collection.ElementAt(0).Culture); - Assert.AreEqual(1047, ContentSettings.Error404Collection.ElementAt(0).ContentId); - Assert.IsTrue(ContentSettings.Error404Collection.ElementAt(0).HasContentId); - Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(0).HasContentKey); - Assert.AreEqual("en-US", ContentSettings.Error404Collection.ElementAt(1).Culture); - Assert.AreEqual("$site/error [@name = 'error']", ContentSettings.Error404Collection.ElementAt(1).ContentXPath); - Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(1).HasContentId); - Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(1).HasContentKey); - Assert.AreEqual("en-UK", ContentSettings.Error404Collection.ElementAt(2).Culture); - Assert.AreEqual(new Guid("8560867F-B88F-4C74-A9A4-679D8E5B3BFC"), ContentSettings.Error404Collection.ElementAt(2).ContentKey); - Assert.IsTrue(ContentSettings.Error404Collection.ElementAt(2).HasContentKey); - Assert.IsFalse(ContentSettings.Error404Collection.ElementAt(2).HasContentId); - } - - [Test] - public void ImageFileTypes() - { - Assert.IsTrue(ContentSettings.ImageFileTypes.All(x => "jpeg,jpg,gif,bmp,png,tiff,tif".Split(',').Contains(x))); - } - - [Test] - public virtual void ImageAutoFillProperties() - { - Assert.AreEqual(2, ContentSettings.ImageAutoFillProperties.Count()); - Assert.AreEqual("umbracoFile", ContentSettings.ImageAutoFillProperties.ElementAt(0).Alias); - Assert.AreEqual("umbracoWidth", ContentSettings.ImageAutoFillProperties.ElementAt(0).WidthFieldAlias); - Assert.AreEqual("umbracoHeight", ContentSettings.ImageAutoFillProperties.ElementAt(0).HeightFieldAlias); - Assert.AreEqual("umbracoBytes", ContentSettings.ImageAutoFillProperties.ElementAt(0).LengthFieldAlias); - Assert.AreEqual("umbracoExtension", ContentSettings.ImageAutoFillProperties.ElementAt(0).ExtensionFieldAlias); - Assert.AreEqual("umbracoFile2", ContentSettings.ImageAutoFillProperties.ElementAt(1).Alias); - Assert.AreEqual("umbracoWidth2", ContentSettings.ImageAutoFillProperties.ElementAt(1).WidthFieldAlias); - Assert.AreEqual("umbracoHeight2", ContentSettings.ImageAutoFillProperties.ElementAt(1).HeightFieldAlias); - Assert.AreEqual("umbracoBytes2", ContentSettings.ImageAutoFillProperties.ElementAt(1).LengthFieldAlias); - Assert.AreEqual("umbracoExtension2", ContentSettings.ImageAutoFillProperties.ElementAt(1).ExtensionFieldAlias); - } - - [Test] - public void PreviewBadge() - { - Assert.AreEqual(ContentSettings.PreviewBadge, @"
Preview modeClick to end
"); - } - [Test] - public void ResolveUrlsFromTextString() - { - Assert.IsFalse(ContentSettings.ResolveUrlsFromTextString); - } - [Test] - public void MacroErrors() - { - Assert.AreEqual(ContentSettings.MacroErrorBehaviour, MacroErrorBehaviour.Inline); - } - - [Test] - public void DisallowedUploadFiles() - { - Assert.IsTrue(ContentSettings.DisallowedUploadFiles.All(x => "ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd".Split(',').Contains(x))); - } - - [Test] - public void AllowedUploadFiles() - { - Assert.IsTrue(ContentSettings.AllowedUploadFiles.All(x => "jpg,gif,png".Split(',').Contains(x))); - } - - [Test] - [TestCase("png", true)] - [TestCase("jpg", true)] - [TestCase("gif", true)] - [TestCase("bmp", false)] - [TestCase("php", false)] - [TestCase("ashx", false)] - [TestCase("config", false)] - [TestCase("test", false)] - public virtual void IsFileAllowedForUpload_WithWhitelist(string extension, bool expected) - { - Console.WriteLine("Extension being tested: {0}", extension); - Console.WriteLine("Expected IsAllowed?: {0}", expected); - Console.WriteLine("AllowedUploadFiles: {0}", ContentSettings.AllowedUploadFiles); - Console.WriteLine("DisallowedUploadFiles: {0}", ContentSettings.DisallowedUploadFiles); - - bool allowedContainsExtension = ContentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)); - bool disallowedContainsExtension = ContentSettings.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)); - - Console.WriteLine("AllowedContainsExtension: {0}", allowedContainsExtension); - Console.WriteLine("DisallowedContainsExtension: {0}", disallowedContainsExtension); - - Assert.AreEqual(expected, ContentSettings.IsFileAllowedForUpload(extension)); - } - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementDefaultTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementDefaultTests.cs deleted file mode 100644 index c2e21c5e2c..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementDefaultTests.cs +++ /dev/null @@ -1,10 +0,0 @@ -using NUnit.Framework; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class RequestHandlerElementDefaultTests : RequestHandlerElementTests - { - protected override bool TestingDefaults => true; - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementTests.cs deleted file mode 100644 index 01a2b48e16..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/RequestHandlerElementTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Linq; -using NUnit.Framework; -using Umbraco.Core; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class RequestHandlerElementTests : UmbracoSettingsTests - { - [Test] - public void AddTrailingSlash() - { - Assert.IsTrue(RequestHandlerSettings.AddTrailingSlash == true); - } - - [Test] - public void CharCollection() - { - var chars = @" ,"",',%,.,;,/,\,:,#,+,*,&,?,æ,ø,å,ä,ö,ü,ß,Ä,Ö,|,<,>"; - var items = chars.Split(','); - Assert.AreEqual(items.Length, RequestHandlerSettings.CharCollection.Count()); - Assert.IsTrue(RequestHandlerSettings.CharCollection - .All(x => items.Contains(x.Char))); - - var vals = @"-,plus,star,ae,oe,aa,ae,oe,ue,ss,ae,oe,-"; - var splitVals = vals.Split(','); - Assert.AreEqual(splitVals.Length, RequestHandlerSettings.CharCollection.Count(x => x.Replacement.IsNullOrWhiteSpace() == false)); - Assert.IsTrue(RequestHandlerSettings.CharCollection - .All(x => string.IsNullOrEmpty(x.Replacement) || vals.Split(',').Contains(x.Replacement))); - } - - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementDefaultTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementDefaultTests.cs deleted file mode 100644 index f5566df5ed..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementDefaultTests.cs +++ /dev/null @@ -1,10 +0,0 @@ -using NUnit.Framework; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class SecurityElementDefaultTests : SecurityElementTests - { - protected override bool TestingDefaults => true; - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementTests.cs deleted file mode 100644 index 6a8fc854d7..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/SecurityElementTests.cs +++ /dev/null @@ -1,123 +0,0 @@ -using NUnit.Framework; -using Umbraco.Core; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class SecurityElementTests : UmbracoSettingsTests - { - [Test] - public void KeepUserLoggedIn() - { - Assert.IsTrue(SecuritySettings.KeepUserLoggedIn == true); - } - - [Test] - public void HideDisabledUsersInBackoffice() - { - Assert.IsTrue(SecuritySettings.HideDisabledUsersInBackoffice == false); - } - - [Test] - public void AllowPasswordReset() - { - Assert.IsTrue(SecuritySettings.AllowPasswordReset == true); - } - - [Test] - public void AuthCookieDomain() - { - Assert.IsTrue(SecuritySettings.AuthCookieDomain == null); - } - - [Test] - public void AuthCookieName() - { - Assert.IsTrue(SecuritySettings.AuthCookieName == "UMB_UCONTEXT"); - } - - [Test] - public void UserPasswordConfiguration_RequiredLength() - { - Assert.IsTrue(UserPasswordConfiguration.RequiredLength == 12); - } - - [Test] - public void UserPasswordConfiguration_RequireNonLetterOrDigit() - { - Assert.IsTrue(UserPasswordConfiguration.RequireNonLetterOrDigit == false); - } - - [Test] - public void UserPasswordConfiguration_RequireDigit() - { - Assert.IsTrue(UserPasswordConfiguration.RequireDigit == false); - } - - [Test] - public void UserPasswordConfiguration_RequireLowercase() - { - Assert.IsTrue(UserPasswordConfiguration.RequireLowercase == false); - } - - [Test] - public void UserPasswordConfiguration_RequireUppercase() - { - Assert.IsTrue(UserPasswordConfiguration.RequireUppercase == false); - } - - [Test] - public void UserPasswordConfiguration_HashAlgorithmType() - { - Assert.AreEqual(Constants.Security.AspNetCoreV3PasswordHashAlgorithmName, UserPasswordConfiguration.HashAlgorithmType); - } - - [Test] - public void UserPasswordConfiguration_MaxFailedAccessAttemptsBeforeLockout() - { - Assert.IsTrue(UserPasswordConfiguration.MaxFailedAccessAttemptsBeforeLockout == 5); - } - - [Test] - public void MemberPasswordConfiguration_RequiredLength() - { - Assert.IsTrue(MemberPasswordConfiguration.RequiredLength == 12); - } - - [Test] - public void MemberPasswordConfiguration_RequireNonLetterOrDigit() - { - Assert.IsTrue(MemberPasswordConfiguration.RequireNonLetterOrDigit == false); - } - - [Test] - public void MemberPasswordConfiguration_RequireDigit() - { - Assert.IsTrue(MemberPasswordConfiguration.RequireDigit == false); - } - - [Test] - public void MemberPasswordConfiguration_RequireLowercase() - { - Assert.IsTrue(MemberPasswordConfiguration.RequireLowercase == false); - } - - [Test] - public void MemberPasswordConfiguration_RequireUppercase() - { - Assert.IsTrue(MemberPasswordConfiguration.RequireUppercase == false); - } - - [Test] - public void MemberPasswordConfiguration_HashAlgorithmType() - { - Assert.AreEqual(Constants.Security.AspNetCoreV3PasswordHashAlgorithmName, MemberPasswordConfiguration.HashAlgorithmType); - } - - [Test] - public void MemberPasswordConfiguration_MaxFailedAccessAttemptsBeforeLockout() - { - Assert.IsTrue(MemberPasswordConfiguration.MaxFailedAccessAttemptsBeforeLockout == 5); - } - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs deleted file mode 100644 index 7916100396..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Configuration; -using System.Diagnostics; -using System.IO; -using NUnit.Framework; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Tests.Integration.Implementations; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - public abstract class UmbracoSettingsTests - { - protected virtual bool TestingDefaults { get; set; } - - [SetUp] - public void Init() - { - var testHelper = new TestHelper(); - var config = new FileInfo(testHelper.MapPathForTestFiles("~/Umbraco.Configuration/Configurations/web.config")); - - var fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = config.FullName }; - var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); - - Debug.WriteLine("Testing defaults? {0}", TestingDefaults); - if (TestingDefaults) - { - Settings = configuration.GetSection("umbracoConfiguration/defaultSettings") as UmbracoSettingsSection; - } - else - { - Settings = configuration.GetSection("umbracoConfiguration/settings") as UmbracoSettingsSection; - } - - Assert.IsNotNull(Settings); - } - private UmbracoSettingsSection Settings { get; set; } - - protected IWebRoutingSettings WebRoutingSettings => Settings.WebRouting; - protected IRequestHandlerSettings RequestHandlerSettings => Settings.RequestHandler; - protected ISecuritySettings SecuritySettings => Settings.Security; - protected IUserPasswordConfiguration UserPasswordConfiguration => Settings.Security.UserPasswordConfiguration; - protected IMemberPasswordConfiguration MemberPasswordConfiguration => Settings.Security.MemberPasswordConfiguration; - protected IContentSettings ContentSettings => Settings.Content; - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementDefaultTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementDefaultTests.cs deleted file mode 100644 index e85911d559..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementDefaultTests.cs +++ /dev/null @@ -1,40 +0,0 @@ -using NUnit.Framework; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class WebRoutingElementDefaultTests : WebRoutingElementTests - { - protected override bool TestingDefaults => true; - - [Test] - public override void UrlProviderMode() - { - Assert.IsTrue(WebRoutingSettings.UrlProviderMode == "Auto"); - } - - [Test] - public void DisableAlternativeTemplates() - { - Assert.IsTrue(WebRoutingSettings.DisableAlternativeTemplates == false); - } - - [Test] - public void ValidateAlternativeTemplates() - { - Assert.IsTrue(WebRoutingSettings.ValidateAlternativeTemplates == false); - } - - [Test] - public void DisableFindContentByIdPath() - { - Assert.IsTrue(WebRoutingSettings.DisableFindContentByIdPath == false); - } - - [Test] - public void DisableRedirectUrlTracking() - { - Assert.IsTrue(WebRoutingSettings.DisableRedirectUrlTracking == false); - } - } -} diff --git a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementTests.cs deleted file mode 100644 index 532b27494f..0000000000 --- a/src/Umbraco.Tests.Integration/Umbraco.Configuration/UmbracoSettings/WebRoutingElementTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -using NUnit.Framework; - -namespace Umbraco.Tests.Integration.Umbraco.Configuration.UmbracoSettings -{ - [TestFixture] - public class WebRoutingElementTests : UmbracoSettingsTests - { - [Test] - public void TrySkipIisCustomErrors() - { - Assert.IsTrue(WebRoutingSettings.TrySkipIisCustomErrors == false); - } - - [Test] - public void InternalRedirectPreservesTemplate() - { - Assert.IsTrue(WebRoutingSettings.InternalRedirectPreservesTemplate == false); - } - - [Test] - public virtual void UrlProviderMode() - { - Assert.IsTrue(WebRoutingSettings.UrlProviderMode == "Auto"); - } - } -} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs index 4ac125e598..7a2a4c5965 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UriUtilityTests.cs @@ -72,8 +72,6 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Routing // Arrange var sourceUri = new Uri(sourceUrl, UriKind.Relative); var requestHandlerSettings = new RequestHandlerSettingsBuilder().WithAddTrailingSlash(trailingSlash).Build(); - var mockRequestHandlerSettings = new Mock(); - mockRequestHandlerSettings.Setup(x => x.AddTrailingSlash).Returns(trailingSlash); var uriUtility = BuildUriUtility("/"); // Act diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/ModelsBuilder/ConfigTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/ModelsBuilder/ConfigTests.cs deleted file mode 100644 index 2e15381d18..0000000000 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/ModelsBuilder/ConfigTests.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Configuration; -using NUnit.Framework; -using Umbraco.Configuration.Legacy; -using Umbraco.Core; -using Umbraco.Core.Configuration; - -namespace Umbraco.Tests.ModelsBuilder -{ - [TestFixture] - public class ModelsBuilderConfigTests - { - [Test] - public void Test1() - { - var config = new ModelsBuilderConfig(modelsNamespace: "test1"); - Assert.AreEqual("test1", config.ModelsNamespace); - } - - [Test] - public void Test2() - { - var config = new ModelsBuilderConfig(modelsNamespace: "test2"); - Assert.AreEqual("test2", config.ModelsNamespace); - } - - [Test] - public void DefaultModelsNamespace() - { - var config = new ModelsBuilderConfig(); - Assert.AreEqual(Constants.ModelsBuilder.DefaultModelsNamespace, config.ModelsNamespace); - } - - [TestCase("c:/path/to/root", "~/dir/models", false, "c:\\path\\to\\root\\dir\\models")] - [TestCase("c:/path/to/root", "~/../../dir/models", true, "c:\\path\\dir\\models")] - [TestCase("c:/path/to/root", "c:/another/path/to/elsewhere", true, "c:\\another\\path\\to\\elsewhere")] - public void GetModelsDirectoryTests(string root, string config, bool acceptUnsafe, string expected) - { - Assert.AreEqual(expected, ModelsBuilderConfigExtensions.GetModelsDirectory(root, config, acceptUnsafe)); - } - - [TestCase("c:/path/to/root", "~/../../dir/models", false)] - [TestCase("c:/path/to/root", "c:/another/path/to/elsewhere", false)] - public void GetModelsDirectoryThrowsTests(string root, string config, bool acceptUnsafe) - { - Assert.Throws(() => - { - var modelsDirectory = ModelsBuilderConfigExtensions.GetModelsDirectory(root, config, acceptUnsafe); - }); - } - } -} diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index 1eac33b5b9..a7b148c8e5 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -1,6 +1,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Hosting; @@ -18,10 +19,10 @@ namespace Umbraco.Tests.Configurations [TestCase("~/some-wacky/nestedPath", "/MyVirtualDir/NestedVDir/", "some-wacky-nestedpath")] public void Umbraco_Mvc_Area(string path, string rootPath, string outcome) { - var mockHostingSettings = Mock.Get(SettingsForTests.GenerateMockHostingSettings()); - mockHostingSettings.Setup(x => x.ApplicationVirtualPath).Returns(rootPath); - - var hostingEnvironment = new AspNetHostingEnvironment(mockHostingSettings.Object); + var hostingEnvironment = new AspNetHostingEnvironment(Microsoft.Extensions.Options.Options.Create(new HostingSettings() + { + ApplicationVirtualPath = rootPath + })); var globalSettings = new GlobalSettingsBuilder().WithUmbracoPath(path).Build(); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 1b58c93534..5f863c4538 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Examine; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -85,10 +86,10 @@ namespace Umbraco.Tests.Runtimes public class TestUmbracoApplication : UmbracoApplicationBase { public TestUmbracoApplication() : base(_logger, - ConfigModelConversionsFromLegacy.ConvertSecuritySettings(SettingsForTests.GenerateMockSecuritySettings()), + new SecuritySettings(), ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.DefaultGlobalSettings), new ConnectionStrings(), - _ioHelper, _profiler, new AspNetHostingEnvironment(_hostingSettings), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _logger, _settings)) + _ioHelper, _profiler, new AspNetHostingEnvironment(Options.Create(new HostingSettings())), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _logger, Options.Create(new WebRoutingSettings()))) { } @@ -96,9 +97,6 @@ namespace Umbraco.Tests.Runtimes private static readonly IIOHelper _ioHelper = TestHelper.IOHelper; private static readonly IProfiler _profiler = new TestProfiler(); private static readonly IGlobalSettings _globalSettings = SettingsForTests.DefaultGlobalSettings; - private static readonly IHostingSettings _hostingSettings = SettingsForTests.DefaultHostingSettings; - private static readonly IContentSettings _contentSettings = SettingsForTests.GenerateMockContentSettings(); - private static readonly IWebRoutingSettings _settings = SettingsForTests.GenerateMockWebRoutingSettings(); public IRuntime Runtime { get; private set; } diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index b58301287b..09118de5dd 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Tests.TestHelpers @@ -47,16 +48,6 @@ namespace Umbraco.Tests.TestHelpers internal static IGlobalSettings DefaultGlobalSettings => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion()); - internal static IHostingSettings DefaultHostingSettings => _settingsForTests.DefaultHostingSettings; - - public static IHostingSettings GenerateMockHostingSettings() => _settingsForTests.GenerateMockHostingSettings(); - - public static IWebRoutingSettings GenerateMockWebRoutingSettings() => _settingsForTests.GenerateMockWebRoutingSettings(); - - public static IRequestHandlerSettings GenerateMockRequestHandlerSettings() => _settingsForTests.GenerateMockRequestHandlerSettings(); - - public static ISecuritySettings GenerateMockSecuritySettings() => _settingsForTests.GenerateMockSecuritySettings(); - public static IUserPasswordConfiguration GenerateMockUserPasswordConfiguration() => _settingsForTests.GenerateMockUserPasswordConfiguration(); public static IMemberPasswordConfiguration GenerateMockMemberPasswordConfiguration() => _settingsForTests.GenerateMockMemberPasswordConfiguration(); diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 92767498bc..7161e82323 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -35,6 +35,7 @@ using Umbraco.Web.Routing; using File = System.IO.File; using Umbraco.Tests.Common.Builders; using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.TestHelpers { @@ -62,10 +63,10 @@ namespace Umbraco.Tests.TestHelpers public override IBackOfficeInfo GetBackOfficeInfo() => new AspNetBackOfficeInfo( SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion()), - TestHelper.IOHelper, Mock.Of(), SettingsForTests.GenerateMockWebRoutingSettings()); + TestHelper.IOHelper, Mock.Of(), Options.Create(new WebRoutingSettings())); public override IHostingEnvironment GetHostingEnvironment() - => new AspNetHostingEnvironment(SettingsForTests.DefaultHostingSettings); + => new AspNetHostingEnvironment(Options.Create(new HostingSettings())); public override IApplicationShutdownRegistry GetHostingEnvironmentLifetime() => new AspNetApplicationShutdownRegistry(); @@ -96,15 +97,13 @@ namespace Umbraco.Tests.TestHelpers public static IDbProviderFactoryCreator DbProviderFactoryCreator => _testHelperInternal.DbProviderFactoryCreator; public static IBulkSqlInsertProvider BulkSqlInsertProvider => _testHelperInternal.BulkSqlInsertProvider; public static IMarchal Marchal => _testHelperInternal.Marchal; - public static ICoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings; + public static CoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings; public static IIOHelper IOHelper => _testHelperInternal.IOHelper; public static IMainDom MainDom => _testHelperInternal.MainDom; public static UriUtility UriUtility => _testHelperInternal.UriUtility; - public static IWebRoutingSettings WebRoutingSettings => _testHelperInternal.WebRoutingSettings; - public static IEmailSender EmailSender { get; } = new EmailSender(Options.Create(new GlobalSettingsBuilder().Build())); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index ccac76fc88..541021613e 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Dictionary; using Umbraco.Core.Events; using Umbraco.Core.Hosting; @@ -137,7 +138,7 @@ namespace Umbraco.Tests.Testing protected virtual IProfilingLogger ProfilingLogger => Factory.GetInstance(); - protected IHostingEnvironment HostingEnvironment { get; } = new AspNetHostingEnvironment(TestHelpers.SettingsForTests.DefaultHostingSettings); + protected IHostingEnvironment HostingEnvironment { get; } = new AspNetHostingEnvironment(Microsoft.Extensions.Options.Options.Create(new HostingSettings())); protected IApplicationShutdownRegistry HostingLifetime { get; } = new AspNetApplicationShutdownRegistry(); protected IIpResolver IpResolver => Factory.GetInstance(); protected IBackOfficeInfo BackOfficeInfo => Factory.GetInstance(); @@ -174,9 +175,9 @@ namespace Umbraco.Tests.Testing TypeFinder = new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash()); var appCaches = GetAppCaches(); var globalSettings = new GlobalSettingsBuilder().Build(); - var settings = TestHelpers.SettingsForTests.GenerateMockWebRoutingSettings(); + var settings = new WebRoutingSettings(); - IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); + IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, Microsoft.Extensions.Options.Options.Create(settings)); IIpResolver ipResolver = new AspNetIpResolver(); UmbracoVersion = new UmbracoVersion(); diff --git a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs index 1e60fedeea..8992813b73 100644 --- a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs +++ b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs @@ -1,6 +1,8 @@ using System.Web; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -12,14 +14,14 @@ namespace Umbraco.Web private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; - private readonly IWebRoutingSettings _webRoutingSettings; + private readonly WebRoutingSettings _webRoutingSettings; - public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IWebRoutingSettings webRoutingSettings) + public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IOptions webRoutingSettings) { _globalSettings = globalSettings; _ioHelper = ioHelper; _logger = logger; - _webRoutingSettings = webRoutingSettings; + _webRoutingSettings = webRoutingSettings.Value; } /// diff --git a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs index 5e7324236a..2ec6599939 100644 --- a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs @@ -2,8 +2,10 @@ using System; using System.Reflection; using System.Web; using System.Web.Hosting; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; namespace Umbraco.Web.Hosting @@ -11,18 +13,18 @@ namespace Umbraco.Web.Hosting public class AspNetHostingEnvironment : IHostingEnvironment { - private readonly IHostingSettings _hostingSettings; + private readonly HostingSettings _hostingSettings; private string _localTempPath; - public AspNetHostingEnvironment(IHostingSettings hostingSettings) + public AspNetHostingEnvironment(IOptions hostingSettings) { - _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); + _hostingSettings = hostingSettings.Value ?? throw new ArgumentNullException(nameof(hostingSettings)); SiteName = HostingEnvironment.SiteName; ApplicationId = HostingEnvironment.ApplicationID; // when we are not hosted (i.e. unit test or otherwise) we'll need to get the root path from the executing assembly ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath ?? Assembly.GetExecutingAssembly().GetRootDirectorySafe(); - ApplicationVirtualPath = hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') + ApplicationVirtualPath = _hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/') ?? HostingEnvironment.ApplicationVirtualPath?.EnsureStartsWith("/") ?? "/"; IISVersion = HttpRuntime.IISVersion; @@ -34,7 +36,7 @@ namespace Umbraco.Web.Hosting public string ApplicationVirtualPath { get; } - public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _hostingSettings.DebugMode; + public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _hostingSettings.Debug; /// public bool IsHosted => (HttpContext.Current != null || HostingEnvironment.IsHosted); diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 5254b91672..f325ae82da 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -10,6 +10,7 @@ using System.Web; using System.Web.Http; using System.Web.Mvc; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Models; @@ -21,6 +22,7 @@ using Umbraco.Web.Security; using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using IUser = Umbraco.Core.Models.Membership.IUser; @@ -47,7 +49,7 @@ namespace Umbraco.Web.Editors private readonly IUserPasswordConfiguration _passwordConfiguration; private readonly IHostingEnvironment _hostingEnvironment; private readonly IRuntimeState _runtimeState; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; private readonly IRequestAccessor _requestAccessor; private readonly IEmailSender _emailSender; @@ -62,7 +64,7 @@ namespace Umbraco.Web.Editors IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, - ISecuritySettings securitySettings, + IOptions securitySettings, IPublishedUrlProvider publishedUrlProvider, IRequestAccessor requestAccessor, IEmailSender emailSender) @@ -71,7 +73,7 @@ namespace Umbraco.Web.Editors _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); - _securitySettings = securitySettings ?? throw new ArgumentNullException(nameof(securitySettings)); + _securitySettings = securitySettings.Value ?? throw new ArgumentNullException(nameof(securitySettings)); _requestAccessor = requestAccessor ?? throw new ArgumentNullException(nameof(securitySettings)); _emailSender = emailSender; } diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 7e0cd7062b..601956f217 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -37,8 +37,8 @@ namespace Umbraco.Web.Editors private readonly IUmbracoVersion _umbracoVersion; private readonly IContentSettings _contentSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _runtimeSettings; - private readonly ISecuritySettings _securitySettings; + private readonly RuntimeSettings _runtimeSettings; + private readonly SecuritySettings _securitySettings; public BackOfficeController( UmbracoFeatures features, @@ -50,8 +50,8 @@ namespace Umbraco.Web.Editors IUmbracoVersion umbracoVersion, IContentSettings contentSettings, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings, - ISecuritySettings securitySettings) + IOptions settings, + IOptions securitySettings) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger) { @@ -59,8 +59,8 @@ namespace Umbraco.Web.Editors _umbracoVersion = umbracoVersion; _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _hostingEnvironment = hostingEnvironment; - _runtimeSettings = settings; - _securitySettings = securitySettings; + _runtimeSettings = settings.Value; + _securitySettings = securitySettings.Value; } protected BackOfficeSignInManager SignInManager => _signInManager ?? (_signInManager = OwinContext.GetBackOfficeSignInManager()); diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index ce20dcf187..71c4bf1579 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -5,8 +5,10 @@ using System.Linq; using System.Runtime.Serialization; using System.Web; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.WebAssets; @@ -33,8 +35,8 @@ namespace Umbraco.Web.Editors private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _settings; - private readonly ISecuritySettings _securitySettings; + private readonly RuntimeSettings _settings; + private readonly SecuritySettings _securitySettings; private readonly IRuntimeMinifier _runtimeMinifier; internal BackOfficeServerVariables( @@ -46,8 +48,8 @@ namespace Umbraco.Web.Editors IContentSettings contentSettings, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings, - ISecuritySettings securitySettings, + IOptions settings, + IOptions securitySettings, IRuntimeMinifier runtimeMinifier) { _urlHelper = urlHelper; @@ -58,8 +60,8 @@ namespace Umbraco.Web.Editors _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; - _settings = settings; - _securitySettings = securitySettings; + _settings = settings.Value; + _securitySettings = securitySettings.Value; _runtimeMinifier = runtimeMinifier; } diff --git a/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs b/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs index 60ca151ce6..b189867a89 100644 --- a/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs +++ b/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs @@ -3,8 +3,10 @@ using System.Configuration; using System.Net; using System.Text.RegularExpressions; using System.Web.Mvc; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Composing; namespace Umbraco.Web.Mvc @@ -23,7 +25,7 @@ namespace Umbraco.Web.Mvc public void OnException(ExceptionContext filterContext) { - var settings = Current.Factory.GetInstance(); + var settings = Current.Factory.GetInstance>().Value; var disabled = settings?.Disabled ?? false; if (Current.PublishedModelFactory.IsLiveFactory() && !disabled diff --git a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs index 26b85d6c39..4daf695912 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs @@ -1,11 +1,13 @@ using System; using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Services; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; @@ -21,21 +23,21 @@ namespace Umbraco.Web.Security private readonly IRuntimeState _runtimeState; private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly ISecuritySettings _securitySettings; + private readonly SecuritySettings _securitySettings; - public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, ISecuritySettings securitySettings) + public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IOptions securitySettings) { _userService = userService; _runtimeState = runtimeState; _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; - _securitySettings = securitySettings; + _securitySettings = securitySettings.Value; } public override void ResponseSignOut(CookieResponseSignOutContext context) { - + } diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index 5c3ab46101..83b6843a39 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -3,10 +3,12 @@ using System.Diagnostics; using System.Globalization; using System.Threading.Tasks; using System.Web; +using Microsoft.Extensions.Options; using Microsoft.Owin; using Microsoft.Owin.Logging; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Infrastructure.Configuration; @@ -25,7 +27,7 @@ namespace Umbraco.Web.Security { private readonly UmbracoBackOfficeCookieAuthOptions _authOptions; private readonly IGlobalSettings _globalSettings; - private readonly ISecuritySettings _security; + private readonly SecuritySettings _security; private readonly ILogger _logger; private readonly IHostingEnvironment _hostingEnvironment; @@ -33,14 +35,14 @@ namespace Umbraco.Web.Security OwinMiddleware next, UmbracoBackOfficeCookieAuthOptions authOptions, IGlobalSettings globalSettings, - ISecuritySettings security, + IOptions security, ILogger logger, IHostingEnvironment hostingEnvironment) : base(next) { _authOptions = authOptions ?? throw new ArgumentNullException(nameof(authOptions)); _globalSettings = globalSettings; - _security = security; + _security = security.Value; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _hostingEnvironment = hostingEnvironment; } diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index f40a230ae5..93167b76e0 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -45,12 +45,12 @@ namespace Umbraco.Web { //var configFactory = new ConfigsFactory(); - IHostingSettings hostingSettings = null; + HostingSettings hostingSettings = null; IGlobalSettings globalSettings = null; - ISecuritySettings securitySettings = null; - IWebRoutingSettings webRoutingSettings = null; + SecuritySettings securitySettings = null; + WebRoutingSettings webRoutingSettings = null; - var hostingEnvironment = new AspNetHostingEnvironment(hostingSettings); + var hostingEnvironment = new AspNetHostingEnvironment(Options.Create(hostingSettings)); var loggingConfiguration = new LoggingConfiguration( Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "App_Data\\Logs"), Path.Combine(hostingEnvironment.ApplicationPhysicalPath, "config\\serilog.config"), @@ -58,10 +58,10 @@ namespace Umbraco.Web var ioHelper = new IOHelper(hostingEnvironment); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration); - var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, webRoutingSettings); + var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, Options.Create(webRoutingSettings)); var profiler = GetWebProfiler(hostingEnvironment); Umbraco.Composing.Current.Initialize(logger, - ConfigModelConversionsFromLegacy.ConvertSecuritySettings(securitySettings), + securitySettings, ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings), ioHelper, hostingEnvironment, backOfficeInfo, profiler); Logger = logger; diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index 600b58cf06..a9682c25b2 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -1,9 +1,11 @@ using System; +using Microsoft.Extensions.Options; using Microsoft.Owin; using Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -30,7 +32,7 @@ namespace Umbraco.Web protected IUmbracoContextAccessor UmbracoContextAccessor => Current.UmbracoContextAccessor; protected IGlobalSettings GlobalSettings => Current.Factory.GetInstance(); protected IContentSettings ContentSettings => Current.Factory.GetInstance(); - protected ISecuritySettings SecuritySettings => Current.Factory.GetInstance(); + protected SecuritySettings SecuritySettings => Current.Factory.GetInstance>().Value; protected IUserPasswordConfiguration UserPasswordConfig => Current.Factory.GetInstance(); protected IRuntimeState RuntimeState => Current.RuntimeState; protected ServiceContext Services => Current.Services; diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs index 0d8d4b8bf2..47dd0908dd 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComponent.cs @@ -3,9 +3,11 @@ using System.Collections.Specialized; using System.IO; using ClientDependency.Core.CompositeFiles.Providers; using ClientDependency.Core.Config; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.Runtime; @@ -14,18 +16,18 @@ namespace Umbraco.Web.WebAssets.CDF [ComposeAfter(typeof(WebInitialComponent))] public sealed class ClientDependencyComponent : IComponent { - private readonly IHostingSettings _hostingSettings; + private readonly HostingSettings _hostingSettings; private readonly IHostingEnvironment _hostingEnvironment; - private readonly IRuntimeSettings _settings; + private readonly RuntimeSettings _settings; public ClientDependencyComponent( - IHostingSettings hostingSettings, + IOptions hostingSettings, IHostingEnvironment hostingEnvironment, - IRuntimeSettings settings) + IOptions settings) { - _hostingSettings = hostingSettings; + _hostingSettings = hostingSettings.Value; _hostingEnvironment = hostingEnvironment; - _settings = settings; + _settings = settings.Value; } public void Initialize() From acb46119bea06282f20d8e2e322f49ad6822e730 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 12:57:47 +0200 Subject: [PATCH 43/58] More clean up of old configs --- .../Legacy/ConfigurationManagerConfigBase.cs | 22 ---- .../Legacy/ContentSettings.cs | 22 ---- .../Legacy/ContentSettingsExtensions.cs | 21 ---- .../Models/ContentSettings.cs | 119 ------------------ .../Umbraco.Configuration.csproj | 6 +- .../UmbracoSettings/ContentElement.cs | 65 ---------- .../UmbracoSettings/UmbracoSettingsSection.cs | 13 -- .../UmbracoSettings/IContentSettings.cs | 36 ------ src/Umbraco.Core/Umbraco.Core.csproj | 2 +- .../Umbraco.Infrastructure.csproj | 8 +- src/Umbraco.Tests.Common/SettingsForTests.cs | 15 --- .../Umbraco.Tests.Integration.csproj | 2 +- src/Umbraco.Tests/IO/FileSystemsTests.cs | 1 - .../Models/ContentExtensionsTests.cs | 1 - src/Umbraco.Tests/Models/ContentTests.cs | 3 +- .../Runtimes/CoreRuntimeTests.cs | 1 - .../TestHelpers/SettingsForTests.cs | 6 - .../Editors/BackOfficeController.cs | 6 +- .../Editors/BackOfficeServerVariables.cs | 8 +- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 3 +- src/Umbraco.Web/Macros/MacroRenderer.cs | 10 +- src/Umbraco.Web/Umbraco.Web.csproj | 4 +- src/Umbraco.Web/UmbracoDefaultOwinStartup.cs | 1 - 23 files changed, 28 insertions(+), 347 deletions(-) delete mode 100644 src/Umbraco.Configuration/Legacy/ConfigurationManagerConfigBase.cs delete mode 100644 src/Umbraco.Configuration/Legacy/ContentSettings.cs delete mode 100644 src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs delete mode 100644 src/Umbraco.Configuration/Models/ContentSettings.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/IContentSettings.cs diff --git a/src/Umbraco.Configuration/Legacy/ConfigurationManagerConfigBase.cs b/src/Umbraco.Configuration/Legacy/ConfigurationManagerConfigBase.cs deleted file mode 100644 index 0302a7ea31..0000000000 --- a/src/Umbraco.Configuration/Legacy/ConfigurationManagerConfigBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Configuration.Implementations -{ - internal abstract class ConfigurationManagerConfigBase - { - private UmbracoSettingsSection _umbracoSettingsSection; - - protected UmbracoSettingsSection UmbracoSettingsSection - { - get - { - if (_umbracoSettingsSection is null) - { - _umbracoSettingsSection = ConfigurationManager.GetSection("umbracoConfiguration/settings") as UmbracoSettingsSection; - } - return _umbracoSettingsSection; - } - } - } -} diff --git a/src/Umbraco.Configuration/Legacy/ContentSettings.cs b/src/Umbraco.Configuration/Legacy/ContentSettings.cs deleted file mode 100644 index 1c3f543bfe..0000000000 --- a/src/Umbraco.Configuration/Legacy/ContentSettings.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Macros; - -namespace Umbraco.Configuration.Implementations -{ - internal class ContentSettings : ConfigurationManagerConfigBase, IContentSettings - { - public string NotificationEmailAddress => UmbracoSettingsSection.Content.Notifications.NotificationEmailAddress; - public bool DisableHtmlEmail => UmbracoSettingsSection.Content.Notifications.DisableHtmlEmail; - public IEnumerable ImageFileTypes => UmbracoSettingsSection.Content.Imaging.ImageFileTypes; - public IEnumerable ImageAutoFillProperties => UmbracoSettingsSection.Content.Imaging.ImageAutoFillProperties; - public bool ResolveUrlsFromTextString => UmbracoSettingsSection.Content.ResolveUrlsFromTextString; - public IEnumerable Error404Collection => UmbracoSettingsSection.Content.Error404Collection; - public string PreviewBadge => UmbracoSettingsSection.Content.PreviewBadge; - public MacroErrorBehaviour MacroErrorBehaviour => UmbracoSettingsSection.Content.MacroErrors; - public IEnumerable DisallowedUploadFiles => UmbracoSettingsSection.Content.DisallowedUploadFiles; - public IEnumerable AllowedUploadFiles => UmbracoSettingsSection.Content.AllowedUploadFiles; - public bool ShowDeprecatedPropertyEditors => UmbracoSettingsSection.Content.ShowDeprecatedPropertyEditors; - public string LoginBackgroundImage => UmbracoSettingsSection.Content.LoginBackgroundImage; - } -} diff --git a/src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs b/src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs deleted file mode 100644 index 87b83416ac..0000000000 --- a/src/Umbraco.Configuration/Legacy/ContentSettingsExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Linq; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Core.Configuration -{ - public static class ContentSettingsExtensions - { - /// - /// Determines if file extension is allowed for upload based on (optional) white list and black list - /// held in settings. - /// Allow upload if extension is whitelisted OR if there is no whitelist and extension is NOT blacklisted. - /// - public static bool IsFileAllowedForUpload(this IContentSettings contentSettings, string extension) - { - return contentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)) || - (contentSettings.AllowedUploadFiles.Any() == false && - contentSettings.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false); - } - } -} diff --git a/src/Umbraco.Configuration/Models/ContentSettings.cs b/src/Umbraco.Configuration/Models/ContentSettings.cs deleted file mode 100644 index 6c9b986dd1..0000000000 --- a/src/Umbraco.Configuration/Models/ContentSettings.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Macros; - -namespace Umbraco.Configuration.Models -{ - internal class ContentSettings : IContentSettings - { - private const string Prefix = Constants.Configuration.ConfigPrefix + "Content:"; - private const string NotificationsPrefix = Prefix + "Notifications:"; - private const string ImagingPrefix = Prefix + "Imaging:"; - private const string DefaultPreviewBadge = - @"
Preview modeClick to end
"; - - private static readonly ImagingAutoFillUploadField[] DefaultImagingAutoFillUploadField = - { - new ImagingAutoFillUploadField - { - Alias = Constants.Conventions.Media.File, - WidthFieldAlias = Constants.Conventions.Media.Width, - HeightFieldAlias =Constants.Conventions.Media.Height, - ExtensionFieldAlias =Constants.Conventions.Media.Extension, - LengthFieldAlias =Constants.Conventions.Media.Bytes, - } - }; - - private readonly IConfiguration _configuration; - - public ContentSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string NotificationEmailAddress => - _configuration.GetValue(NotificationsPrefix+"Email"); - - public bool DisableHtmlEmail => - _configuration.GetValue(NotificationsPrefix+"DisableHtmlEmail", false); - - public IEnumerable ImageFileTypes => _configuration.GetValue( - ImagingPrefix+"ImageFileTypes", new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }); - - public IEnumerable ImageAutoFillProperties => - _configuration.GetValue(ImagingPrefix+"AutoFillImageProperties", - DefaultImagingAutoFillUploadField); - - - public bool ResolveUrlsFromTextString => - _configuration.GetValue(Prefix+"ResolveUrlsFromTextString", false); - - public IEnumerable Error404Collection => _configuration - .GetSection(Prefix+"Errors:Error404") - .GetChildren() - .Select(x => new ContentErrorPage(x)); - - public string PreviewBadge => _configuration.GetValue(Prefix+"PreviewBadge", DefaultPreviewBadge); - - public MacroErrorBehaviour MacroErrorBehaviour => - _configuration.GetValue(Prefix+"MacroErrors", MacroErrorBehaviour.Inline); - - public IEnumerable DisallowedUploadFiles => _configuration.GetValue( - Prefix+"DisallowedUploadFiles", - new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }); - - public IEnumerable AllowedUploadFiles => - _configuration.GetValue(Prefix+"AllowedUploadFiles", Array.Empty()); - - public bool ShowDeprecatedPropertyEditors => - _configuration.GetValue(Prefix+"ShowDeprecatedPropertyEditors", false); - - public string LoginBackgroundImage => - _configuration.GetValue(Prefix+"LoginBackgroundImage", "assets/img/login.jpg"); - - private class ContentErrorPage : IContentErrorPage - { - public ContentErrorPage(IConfigurationSection configurationSection) - { - Culture = configurationSection.Key; - - var value = configurationSection.Value; - - if (int.TryParse(value, out var contentId)) - { - HasContentId = true; - ContentId = contentId; - } - else if (Guid.TryParse(value, out var contentKey)) - { - HasContentKey = true; - ContentKey = contentKey; - } - else - { - ContentXPath = value; - } - } - - public int ContentId { get; } - public Guid ContentKey { get; } - public string ContentXPath { get; } - public bool HasContentId { get; } - public bool HasContentKey { get; } - public string Culture { get; set; } - } - - private class ImagingAutoFillUploadField : IImagingAutoFillUploadField - { - public string Alias { get; set; } - public string WidthFieldAlias { get; set; } - public string HeightFieldAlias { get; set; } - public string LengthFieldAlias { get; set; } - public string ExtensionFieldAlias { get; set; } - } - } -} diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index a4dac22386..21a6dd83af 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -26,9 +26,9 @@ - - - + + + diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs deleted file mode 100644 index 28b4314c9a..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; -using Umbraco.Core.Macros; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ContentElement : UmbracoConfigurationElement, IContentSettings - { - private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; - - [ConfigurationProperty("imaging")] - internal ContentImagingElement Imaging => (ContentImagingElement) this["imaging"]; - - [ConfigurationProperty("ResolveUrlsFromTextString")] - internal InnerTextConfigurationElement ResolveUrlsFromTextString => GetOptionalTextElement("ResolveUrlsFromTextString", false); - - public IEnumerable Error404Collection => Errors.Error404Collection; - - [ConfigurationProperty("errors", IsRequired = true)] - internal ContentErrorsElement Errors => (ContentErrorsElement) base["errors"]; - - [ConfigurationProperty("notifications", IsRequired = true)] - internal NotificationsElement Notifications => (NotificationsElement) base["notifications"]; - - [ConfigurationProperty("PreviewBadge")] - internal InnerTextConfigurationElement PreviewBadge => GetOptionalTextElement("PreviewBadge", DefaultPreviewBadge); - - [ConfigurationProperty("MacroErrors")] - internal InnerTextConfigurationElement MacroErrors => GetOptionalTextElement("MacroErrors", MacroErrorBehaviour.Inline); - - [ConfigurationProperty("disallowedUploadFiles")] - internal CommaDelimitedConfigurationElement DisallowedUploadFiles => GetOptionalDelimitedElement("disallowedUploadFiles", new[] {"ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd"}); - - [ConfigurationProperty("allowedUploadFiles")] - internal CommaDelimitedConfigurationElement AllowedUploadFiles => GetOptionalDelimitedElement("allowedUploadFiles", new string[0]); - - [ConfigurationProperty("showDeprecatedPropertyEditors")] - internal InnerTextConfigurationElement ShowDeprecatedPropertyEditors => GetOptionalTextElement("showDeprecatedPropertyEditors", false); - - [ConfigurationProperty("loginBackgroundImage")] - internal InnerTextConfigurationElement LoginBackgroundImage => GetOptionalTextElement("loginBackgroundImage", string.Empty); - - string IContentSettings.NotificationEmailAddress => Notifications.NotificationEmailAddress; - - bool IContentSettings.DisableHtmlEmail => Notifications.DisableHtmlEmail; - - IEnumerable IContentSettings.ImageFileTypes => Imaging.ImageFileTypes; - - IEnumerable IContentSettings.ImageAutoFillProperties => Imaging.ImageAutoFillProperties; - - bool IContentSettings.ResolveUrlsFromTextString => ResolveUrlsFromTextString; - - string IContentSettings.PreviewBadge => PreviewBadge; - - MacroErrorBehaviour IContentSettings.MacroErrorBehaviour => MacroErrors; - - IEnumerable IContentSettings.DisallowedUploadFiles => DisallowedUploadFiles; - - IEnumerable IContentSettings.AllowedUploadFiles => AllowedUploadFiles; - - bool IContentSettings.ShowDeprecatedPropertyEditors => ShowDeprecatedPropertyEditors; - - string IContentSettings.LoginBackgroundImage => LoginBackgroundImage; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs deleted file mode 100644 index e8ab155ef1..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class UmbracoSettingsSection : ConfigurationSection - { - - [ConfigurationProperty("content")] - public ContentElement Content => (ContentElement)this["content"]; - - - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSettings.cs deleted file mode 100644 index 08f6231309..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IContentSettings.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using Umbraco.Core.Macros; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IContentSettings : IUmbracoConfigurationSection - { - string NotificationEmailAddress { get; } - - bool DisableHtmlEmail { get; } - - IEnumerable ImageFileTypes { get; } - - IEnumerable ImageAutoFillProperties { get; } - - bool ResolveUrlsFromTextString { get; } - - IEnumerable Error404Collection { get; } - - string PreviewBadge { get; } - - MacroErrorBehaviour MacroErrorBehaviour { get; } - - IEnumerable DisallowedUploadFiles { get; } - - IEnumerable AllowedUploadFiles { get; } - - /// - /// Gets a value indicating whether to show deprecated property editors in - /// a datatype list of available editors. - /// - bool ShowDeprecatedPropertyEditors { get; } - - string LoginBackgroundImage { get; } - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index ca5569aa4d..9634baf960 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index d9cd6bf498..65f1babfc8 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -18,10 +18,10 @@ - - - - + + + + diff --git a/src/Umbraco.Tests.Common/SettingsForTests.cs b/src/Umbraco.Tests.Common/SettingsForTests.cs index ee46e5c82f..4d21b739e8 100644 --- a/src/Umbraco.Tests.Common/SettingsForTests.cs +++ b/src/Umbraco.Tests.Common/SettingsForTests.cs @@ -39,21 +39,6 @@ namespace Umbraco.Tests.Common return config; } - /// - /// Returns generated settings which can be stubbed to return whatever values necessary - /// - /// - public IContentSettings GenerateMockContentSettings() - { - - var content = new Mock(); - - //Now configure some defaults - the defaults in the config section classes do NOT pertain to the mocked data!! - content.Setup(x => x.ImageAutoFillProperties).Returns(ContentImagingElement.GetDefaultImageAutoFillProperties()); - content.Setup(x => x.ImageFileTypes).Returns(ContentImagingElement.GetDefaultImageFileTypes()); - return content.Object; - } - //// from appSettings //private readonly IDictionary SavedAppSettings = new Dictionary(); diff --git a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj index 072f15bcd1..dc10208d1e 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj +++ b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index b474da872f..9d2df22739 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -35,7 +35,6 @@ namespace Umbraco.Tests.IO composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); - composition.Register(_ => Mock.Of()); composition.Register(_ => TestHelper.ShortStringHelper); composition.Register(_ => TestHelper.IOHelper); composition.RegisterUnique(); diff --git a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs index bab3a540be..1b2f30db16 100644 --- a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs +++ b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs @@ -29,7 +29,6 @@ namespace Umbraco.Tests.Models Composition.ComposeFileSystems(); Composition.Register(_ => Mock.Of()); - Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), IOHelper, ShortStringHelper, LocalizedTextService) { Alias = "test" }; diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 31e928159b..ca56a25f68 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using System.Globalization; using System.Linq; using System.Threading; +using Microsoft.CodeAnalysis.Options; +using Microsoft.Extensions.Options; using Moq; using Newtonsoft.Json; using Umbraco.Core; @@ -39,7 +41,6 @@ namespace Umbraco.Tests.Models Composition.ComposeFileSystems(); Composition.Register(_ => Mock.Of()); - Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), IOHelper, ShortStringHelper, LocalizedTextService) { Alias = "test" }; diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 5f863c4538..7cb20cbbde 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -162,7 +162,6 @@ namespace Umbraco.Tests.Runtimes public void Compose(Composition composition) { - composition.Register(factory => SettingsForTests.GenerateMockContentSettings()); composition.RegisterUnique(); composition.Components().Append(); diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index 09118de5dd..af6b008a14 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -10,12 +10,6 @@ namespace Umbraco.Tests.TestHelpers public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateMockGlobalSettings(TestHelper.GetUmbracoVersion()); - /// - /// Returns generated settings which can be stubbed to return whatever values necessary - /// - /// - public static IContentSettings GenerateMockContentSettings() => _settingsForTests.GenerateMockContentSettings(); - //// from appSettings //private static readonly IDictionary SavedAppSettings = new Dictionary(); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 601956f217..95480f6632 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Editors private BackOfficeOwinUserManager _userManager; private BackOfficeSignInManager _signInManager; private readonly IUmbracoVersion _umbracoVersion; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly RuntimeSettings _runtimeSettings; private readonly SecuritySettings _securitySettings; @@ -48,7 +48,7 @@ namespace Umbraco.Web.Editors AppCaches appCaches, IProfilingLogger profilingLogger, IUmbracoVersion umbracoVersion, - IContentSettings contentSettings, + IOptions contentSettings, IHostingEnvironment hostingEnvironment, IOptions settings, IOptions securitySettings) @@ -57,7 +57,7 @@ namespace Umbraco.Web.Editors { _features = features; _umbracoVersion = umbracoVersion; - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value; _hostingEnvironment = hostingEnvironment; _runtimeSettings = settings.Value; _securitySettings = securitySettings.Value; diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 71c4bf1579..af67cd4288 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Editors private readonly UmbracoFeatures _features; private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; @@ -45,7 +45,7 @@ namespace Umbraco.Web.Editors UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, - IContentSettings contentSettings, + IOptions contentSettings, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, IOptions settings, @@ -57,7 +57,7 @@ namespace Umbraco.Web.Editors _features = features; _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; _settings = settings.Value; @@ -149,7 +149,7 @@ namespace Umbraco.Web.Editors {"appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd('/')}, { "imageFileTypes", - string.Join(",", _contentSettings.ImageFileTypes) + string.Join(",", _contentSettings.Imaging.ImageFileTypes) }, { "disallowedUploadFiles", diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 5ddd34fbed..b94cb655c8 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -10,6 +10,7 @@ using System.Web.Mvc.Html; using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Web.Mvc; @@ -60,7 +61,7 @@ namespace Umbraco.Web /// /// See: http://issues.umbraco.org/issue/U4-1614 /// - public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IIOHelper ioHelper, IContentSettings contentSettings) + public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IIOHelper ioHelper, ContentSettings contentSettings) { if (Current.UmbracoContext.InPreviewMode) { diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 7f6a1cdbf3..8d13c03e8b 100644 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.IO; @@ -20,7 +22,7 @@ namespace Umbraco.Web.Macros { private readonly IProfilingLogger _plogger; private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly IContentSettings _contentSettings; + private readonly ContentSettings _contentSettings; private readonly ILocalizedTextService _textService; private readonly AppCaches _appCaches; private readonly IMacroService _macroService; @@ -35,7 +37,7 @@ namespace Umbraco.Web.Macros public MacroRenderer( IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, - IContentSettings contentSettings, + IOptions contentSettings, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, @@ -48,7 +50,7 @@ namespace Umbraco.Web.Macros { _plogger = plogger ?? throw new ArgumentNullException(nameof(plogger)); _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); - _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _textService = textService; _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); @@ -288,7 +290,7 @@ namespace Umbraco.Web.Macros Alias = macro.Alias, MacroSource = macro.MacroSource, Exception = e, - Behaviour = _contentSettings.MacroErrorBehaviour + Behaviour = _contentSettings.MacroErrors }; switch (macroErrorEventArgs.Behaviour) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 45f9bd9df5..8484147878 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -86,8 +86,8 @@ - - + + diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index a9682c25b2..79ec56cfd3 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -31,7 +31,6 @@ namespace Umbraco.Web { protected IUmbracoContextAccessor UmbracoContextAccessor => Current.UmbracoContextAccessor; protected IGlobalSettings GlobalSettings => Current.Factory.GetInstance(); - protected IContentSettings ContentSettings => Current.Factory.GetInstance(); protected SecuritySettings SecuritySettings => Current.Factory.GetInstance>().Value; protected IUserPasswordConfiguration UserPasswordConfig => Current.Factory.GetInstance(); protected IRuntimeState RuntimeState => Current.RuntimeState; From 4173a2fb2027660cfede0a8b4cda356eeab4b3dc Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 12:58:41 +0200 Subject: [PATCH 44/58] More clean up of old configs --- .../CommaDelimitedConfigurationElement.cs | 70 ------------------- .../Legacy/InnerTextConfigurationElement.cs | 69 ------------------ ...ionalCommaDelimitedConfigurationElement.cs | 43 ------------ .../OptionalInnerTextConfigurationElement.cs | 23 ------ .../Legacy/RawXmlConfigurationElement.cs | 30 -------- .../Legacy/UmbracoConfigurationSection.cs | 24 ------- .../UmbracoSettings/CharCollection.cs | 36 ---------- .../UmbracoSettings/CharElement.cs | 24 ------- .../ContentError404Collection.cs | 37 ---------- .../ContentErrorPageElement.cs | 56 --------------- .../UmbracoSettings/ContentErrorsElement.cs | 44 ------------ .../UmbracoSettings/ContentImagingElement.cs | 64 ----------------- .../ImagingAutoFillPropertiesCollection.cs | 37 ---------- .../ImagingAutoFillUploadFieldElement.cs | 39 ----------- .../MemberPasswordConfigurationElement.cs | 6 -- .../UmbracoSettings/NotificationsElement.cs | 13 ---- .../PasswordConfigurationElement.cs | 31 -------- .../UmbracoConfigurationElement.cs | 36 ---------- .../UmbracoSettings/UrlReplacingElement.cs | 23 ------ .../UserPasswordConfigurationElement.cs | 6 -- 20 files changed, 711 deletions(-) delete mode 100644 src/Umbraco.Configuration/Legacy/CommaDelimitedConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/Legacy/InnerTextConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/Legacy/OptionalCommaDelimitedConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/Legacy/OptionalInnerTextConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/Legacy/RawXmlConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/Legacy/UmbracoConfigurationSection.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/CharElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/MemberPasswordConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/PasswordConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs delete mode 100644 src/Umbraco.Configuration/UmbracoSettings/UserPasswordConfigurationElement.cs diff --git a/src/Umbraco.Configuration/Legacy/CommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/Legacy/CommaDelimitedConfigurationElement.cs deleted file mode 100644 index 3ced2fab46..0000000000 --- a/src/Umbraco.Configuration/Legacy/CommaDelimitedConfigurationElement.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - /// - /// Defines a configuration section that contains inner text that is comma delimited - /// - internal class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable - { - public override CommaDelimitedStringCollection Value - { - get - { - var converter = new CommaDelimitedStringCollectionConverter(); - return (CommaDelimitedStringCollection) converter.ConvertFrom(RawValue); - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return new InnerEnumerator(Value.GetEnumerator()); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return new InnerEnumerator(Value.GetEnumerator()); - } - - /// - /// A wrapper for StringEnumerator since it doesn't explicitly implement IEnumerable - /// - private class InnerEnumerator : IEnumerator - { - private readonly StringEnumerator _stringEnumerator; - - public InnerEnumerator(StringEnumerator stringEnumerator) - { - _stringEnumerator = stringEnumerator; - } - - public bool MoveNext() - { - return _stringEnumerator.MoveNext(); - } - - public void Reset() - { - _stringEnumerator.Reset(); - } - - string IEnumerator.Current - { - get { return _stringEnumerator.Current; } - } - - public object Current - { - get { return _stringEnumerator.Current; } - } - - public void Dispose() - { - _stringEnumerator.DisposeIfDisposable(); - } - } - } -} diff --git a/src/Umbraco.Configuration/Legacy/InnerTextConfigurationElement.cs b/src/Umbraco.Configuration/Legacy/InnerTextConfigurationElement.cs deleted file mode 100644 index 6a125f2c1b..0000000000 --- a/src/Umbraco.Configuration/Legacy/InnerTextConfigurationElement.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Xml; -using System.Xml.Linq; - -namespace Umbraco.Core.Configuration -{ - /// - /// A full config section is required for any full element and we have some elements that are defined like this: - /// {element}MyValue{/element} instead of as attribute values. - /// - /// - internal class InnerTextConfigurationElement : RawXmlConfigurationElement - { - public InnerTextConfigurationElement() - { - } - - public InnerTextConfigurationElement(XElement rawXml) : base(rawXml) - { - } - - protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) - { - base.DeserializeElement(reader, serializeCollectionKey); - //now validate and set the raw value - if (RawXml.HasElements) - throw new InvalidOperationException("An InnerTextConfigurationElement cannot contain any child elements, only attributes and a value"); - RawValue = RawXml.Value.Trim(); - - //RawValue = reader.ReadElementContentAsString(); - } - - public virtual T Value - { - get - { - var converted = RawValue.TryConvertTo(); - if (converted.Success == false) - throw new InvalidCastException("Could not convert value " + RawValue + " to type " + typeof(T)); - return converted.Result; - } - } - - /// - /// Exposes the raw string value - /// - internal string RawValue { get; set; } - - /// - /// Implicit operator so we don't need to use the 'Value' property explicitly - /// - /// - /// - public static implicit operator T(InnerTextConfigurationElement m) - { - return m.Value; - } - - /// - /// Return the string value of Value - /// - /// - public override string ToString() - { - return string.Format("{0}", Value); - } - - } -} diff --git a/src/Umbraco.Configuration/Legacy/OptionalCommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/Legacy/OptionalCommaDelimitedConfigurationElement.cs deleted file mode 100644 index 610067d2db..0000000000 --- a/src/Umbraco.Configuration/Legacy/OptionalCommaDelimitedConfigurationElement.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Core.Configuration -{ - /// - /// Used for specifying default values for comma delimited config - /// - internal class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement - { - private readonly CommaDelimitedConfigurationElement _wrapped; - private readonly string[] _defaultValue; - - public OptionalCommaDelimitedConfigurationElement() - { - } - - public OptionalCommaDelimitedConfigurationElement(CommaDelimitedConfigurationElement wrapped, string[] defaultValue) - { - _wrapped = wrapped; - _defaultValue = defaultValue; - } - - public override CommaDelimitedStringCollection Value - { - get - { - if (_wrapped == null) - { - return base.Value; - } - - if (string.IsNullOrEmpty(_wrapped.RawValue)) - { - var val = new CommaDelimitedStringCollection(); - val.AddRange(_defaultValue); - return val; - } - return _wrapped.Value; - } - } - } -} diff --git a/src/Umbraco.Configuration/Legacy/OptionalInnerTextConfigurationElement.cs b/src/Umbraco.Configuration/Legacy/OptionalInnerTextConfigurationElement.cs deleted file mode 100644 index b15e33019d..0000000000 --- a/src/Umbraco.Configuration/Legacy/OptionalInnerTextConfigurationElement.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Umbraco.Core.Configuration -{ - /// - /// This is used to supply optional/default values when using InnerTextConfigurationElement - /// - /// - internal class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement - { - private readonly InnerTextConfigurationElement _wrapped; - private readonly T _defaultValue; - - public OptionalInnerTextConfigurationElement(InnerTextConfigurationElement wrapped, T defaultValue) - { - _wrapped = wrapped; - _defaultValue = defaultValue; - } - - public override T Value - { - get { return string.IsNullOrEmpty(_wrapped.RawValue) ? _defaultValue : _wrapped.Value; } - } - } -} diff --git a/src/Umbraco.Configuration/Legacy/RawXmlConfigurationElement.cs b/src/Umbraco.Configuration/Legacy/RawXmlConfigurationElement.cs deleted file mode 100644 index 5bc6ad3d32..0000000000 --- a/src/Umbraco.Configuration/Legacy/RawXmlConfigurationElement.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Configuration; -using System.Xml; -using System.Xml.Linq; - -namespace Umbraco.Core.Configuration -{ - /// - /// A configuration section that simply exposes the entire raw xml of the section itself which inheritors can use - /// to do with as they please. - /// - internal abstract class RawXmlConfigurationElement : ConfigurationElement - { - protected RawXmlConfigurationElement() - { - - } - - protected RawXmlConfigurationElement(XElement rawXml) - { - RawXml = rawXml; - } - - protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) - { - RawXml = (XElement)XNode.ReadFrom(reader); - } - - protected XElement RawXml { get; private set; } - } -} diff --git a/src/Umbraco.Configuration/Legacy/UmbracoConfigurationSection.cs b/src/Umbraco.Configuration/Legacy/UmbracoConfigurationSection.cs deleted file mode 100644 index 8c0754b91d..0000000000 --- a/src/Umbraco.Configuration/Legacy/UmbracoConfigurationSection.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - /// - /// Represents an Umbraco section within the configuration file. - /// - /// - /// The requirement for these sections is to be read-only. - /// However for unit tests purposes it is internally possible to override some values, and - /// then calling >ResetSection should cancel these changes and bring the section back to - /// what it was originally. - /// The UmbracoSettings.For{T} method will return a section, either one that - /// is in the configuration file, or a section that was created with default values. - /// - public abstract class UmbracoConfigurationSection : ConfigurationSection, IUmbracoConfigurationSection - { - /// - /// Gets a value indicating whether the section actually is in the configuration file. - /// - protected bool IsPresent { get { return ElementInformation.IsPresent; } } - - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs deleted file mode 100644 index 7b62fcc123..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class CharCollection : ConfigurationElementCollection, IEnumerable - { - internal void Add(CharElement c) - { - BaseAdd(c); - } - - protected override ConfigurationElement CreateNewElement() - { - return new CharElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((CharElement)element).Char; - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return BaseGet(i) as IChar; - } - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs deleted file mode 100644 index 1ff63ac017..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class CharElement : InnerTextConfigurationElement, IChar - { - private string _char; - private string _replacement; - - internal string Char - { - get => _char ?? (_char = (string)RawXml.Attribute("org")); - set => _char = value; - } - - internal string Replacement - { - get => _replacement ?? (_replacement = Value); - set => _replacement = value; - } - - string IChar.Char => Char; - - string IChar.Replacement => Replacement; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs deleted file mode 100644 index bdbcb27b4c..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ContentError404Collection : ConfigurationElementCollection, IEnumerable - { - internal void Add(ContentErrorPageElement element) - { - BaseAdd(element); - } - - protected override ConfigurationElement CreateNewElement() - { - return new ContentErrorPageElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((ContentErrorPageElement)element).Culture - + ((ContentErrorPageElement)element).Value; - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return BaseGet(i) as ContentErrorPageElement; - } - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs deleted file mode 100644 index 96cea71a8e..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Xml.Linq; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage - { - public ContentErrorPageElement(XElement rawXml) - : base(rawXml) - { - } - - public ContentErrorPageElement() - { - - } - - public bool HasContentId => ContentId != int.MinValue; - - public bool HasContentKey => ContentKey != Guid.Empty; - - public int ContentId - { - get - { - int parsed; - if (int.TryParse(Value, out parsed)) - { - return parsed; - } - return int.MinValue; - } - } - - public Guid ContentKey - { - get - { - Guid parsed; - if (Guid.TryParse(Value, out parsed)) - { - return parsed; - } - return Guid.Empty; - } - } - - public string ContentXPath => Value; - - public string Culture - { - get => (string) RawXml.Attribute("culture"); - set => RawXml.Attribute("culture").Value = value; - } - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs deleted file mode 100644 index 5b5b54380d..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ContentErrorsElement : RawXmlConfigurationElement - { - - public IEnumerable Error404Collection - { - get - { - var result = new ContentError404Collection(); - if (RawXml != null) - { - var e404 = RawXml.Elements("error404").First(); - var ePages = e404.Elements("errorPage").ToArray(); - if (ePages.Any()) - { - //there are multiple - foreach (var e in ePages) - { - result.Add(new ContentErrorPageElement(e) - { - Culture = (string)e.Attribute("culture"), - RawValue = e.Value - }); - } - } - else - { - //there's only one defined - result.Add(new ContentErrorPageElement(e404) - { - RawValue = e404.Value - }); - } - } - return result; - } - } - - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs deleted file mode 100644 index 9a5a9b2a59..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ContentImagingElement : ConfigurationElement - { - - [ConfigurationProperty("imageFileTypes")] - internal CommaDelimitedConfigurationElement ImageFileTypes => - new OptionalCommaDelimitedConfigurationElement( - (CommaDelimitedConfigurationElement)this["imageFileTypes"], - //set the default - GetDefaultImageFileTypes()); - - public static string[] GetDefaultImageFileTypes() - { - return new[] {"jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif"}; - } - - private ImagingAutoFillPropertiesCollection _defaultImageAutoFill; - - [ConfigurationCollection(typeof(ImagingAutoFillPropertiesCollection), AddItemName = "uploadField")] - [ConfigurationProperty("autoFillImageProperties", IsDefaultCollection = true)] - internal ImagingAutoFillPropertiesCollection ImageAutoFillProperties - { - get - { - if (_defaultImageAutoFill != null) - { - return _defaultImageAutoFill; - } - - //here we need to check if this element is defined, if it is not then we'll setup the defaults - var prop = Properties["autoFillImageProperties"]; - var autoFill = this[prop] as ConfigurationElement; - if (autoFill != null && autoFill.ElementInformation.IsPresent == false) - { - _defaultImageAutoFill = new ImagingAutoFillPropertiesCollection - { - new ImagingAutoFillUploadFieldElement - { - Alias = "umbracoFile" - } - }; - return _defaultImageAutoFill; - } - - return (ImagingAutoFillPropertiesCollection) base["autoFillImageProperties"]; - } - } - - public static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties() - { - return new ImagingAutoFillPropertiesCollection - { - new ImagingAutoFillUploadFieldElement - { - Alias = "umbracoFile" - } - }; - } - - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs deleted file mode 100644 index 0bac9721a3..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable - { - - protected override ConfigurationElement CreateNewElement() - { - return new ImagingAutoFillUploadFieldElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((ImagingAutoFillUploadFieldElement)element).Alias; - } - - internal void Add(ImagingAutoFillUploadFieldElement item) - { - BaseAdd(item); - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return BaseGet(i) as IImagingAutoFillUploadField; - } - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs deleted file mode 100644 index 9b4c45b5c6..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField - { - /// - /// Allow setting internally so we can create a default - /// - [ConfigurationProperty("alias", IsKey = true, IsRequired = true)] - public string Alias - { - get => (string)this["alias"]; - set => this["alias"] = value; - } - - [ConfigurationProperty("widthFieldAlias")] - internal InnerTextConfigurationElement WidthFieldAlias => GetOptionalTextElement("widthFieldAlias", "umbracoWidth"); - - [ConfigurationProperty("heightFieldAlias")] - internal InnerTextConfigurationElement HeightFieldAlias => GetOptionalTextElement("heightFieldAlias", "umbracoHeight"); - - [ConfigurationProperty("lengthFieldAlias")] - internal InnerTextConfigurationElement LengthFieldAlias => GetOptionalTextElement("lengthFieldAlias", "umbracoBytes"); - - [ConfigurationProperty("extensionFieldAlias")] - internal InnerTextConfigurationElement ExtensionFieldAlias => GetOptionalTextElement("extensionFieldAlias", "umbracoExtension"); - - string IImagingAutoFillUploadField.Alias => Alias; - - string IImagingAutoFillUploadField.WidthFieldAlias => WidthFieldAlias; - - string IImagingAutoFillUploadField.HeightFieldAlias => HeightFieldAlias; - - string IImagingAutoFillUploadField.LengthFieldAlias => LengthFieldAlias; - - string IImagingAutoFillUploadField.ExtensionFieldAlias => ExtensionFieldAlias; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/MemberPasswordConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/MemberPasswordConfigurationElement.cs deleted file mode 100644 index 92cd112630..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/MemberPasswordConfigurationElement.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class MemberPasswordConfigurationElement : PasswordConfigurationElement, IMemberPasswordConfiguration - { - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs deleted file mode 100644 index afadff5654..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class NotificationsElement : UmbracoConfigurationElement - { - [ConfigurationProperty("email")] - internal InnerTextConfigurationElement NotificationEmailAddress => (InnerTextConfigurationElement)this["email"]; - - [ConfigurationProperty("disableHtmlEmail")] - internal InnerTextConfigurationElement DisableHtmlEmail => GetOptionalTextElement("disableHtmlEmail", false); - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/PasswordConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/PasswordConfigurationElement.cs deleted file mode 100644 index 91b5cae7a4..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/PasswordConfigurationElement.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class PasswordConfigurationElement : UmbracoConfigurationElement - { - [ConfigurationProperty("requiredLength", DefaultValue = "12")] - public int RequiredLength => (int)base["requiredLength"]; - - [ConfigurationProperty("requireNonLetterOrDigit", DefaultValue = "false")] - public bool RequireNonLetterOrDigit => (bool)base["requireNonLetterOrDigit"]; - - [ConfigurationProperty("requireDigit", DefaultValue = "false")] - public bool RequireDigit => (bool)base["requireDigit"]; - - [ConfigurationProperty("requireLowercase", DefaultValue = "false")] - public bool RequireLowercase => (bool)base["requireLowercase"]; - - [ConfigurationProperty("requireUppercase", DefaultValue = "false")] - public bool RequireUppercase => (bool)base["requireUppercase"]; - - [ConfigurationProperty("useLegacyEncoding", DefaultValue = "false")] - public bool UseLegacyEncoding => (bool)base["useLegacyEncoding"]; - - [ConfigurationProperty("hashAlgorithmType", DefaultValue = Constants.Security.AspNetCoreV3PasswordHashAlgorithmName)] - public string HashAlgorithmType => (string)base["hashAlgorithmType"]; - - [ConfigurationProperty("maxFailedAccessAttemptsBeforeLockout", DefaultValue = "5")] - public int MaxFailedAccessAttemptsBeforeLockout => (int)base["maxFailedAccessAttemptsBeforeLockout"]; - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs deleted file mode 100644 index 670f620b15..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Concurrent; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - /// - /// Base class with shared helper methods - /// - internal class UmbracoConfigurationElement : ConfigurationElement - { - /// - /// Used so the RawElement types are not re-created every time they are accessed - /// - private readonly ConcurrentDictionary _rawElements = new ConcurrentDictionary(); - - protected OptionalInnerTextConfigurationElement GetOptionalTextElement(string name, T defaultVal) - { - return (OptionalInnerTextConfigurationElement) _rawElements.GetOrAdd( - name, - s => new OptionalInnerTextConfigurationElement( - (InnerTextConfigurationElement) this[s], - //set the default - defaultVal)); - } - - protected OptionalCommaDelimitedConfigurationElement GetOptionalDelimitedElement(string name, string[] defaultVal) - { - return (OptionalCommaDelimitedConfigurationElement) _rawElements.GetOrAdd( - name, - s => new OptionalCommaDelimitedConfigurationElement( - (CommaDelimitedConfigurationElement) this[name], - //set the default - defaultVal)); - } - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs deleted file mode 100644 index 3e12d106ff..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class UrlReplacingElement : ConfigurationElement - { - [ConfigurationProperty("removeDoubleDashes", DefaultValue = true)] - internal bool RemoveDoubleDashes => (bool) base["removeDoubleDashes"]; - - [ConfigurationProperty("toAscii", DefaultValue = "false")] - internal string ConvertUrlsToAscii => (string) base["toAscii"]; - - [ConfigurationCollection(typeof(CharCollection), AddItemName = "char")] - [ConfigurationProperty("", IsDefaultCollection = true)] - internal CharCollection CharCollection - { - get => (CharCollection)base[""]; - set => base[""] = value; - } - - } -} diff --git a/src/Umbraco.Configuration/UmbracoSettings/UserPasswordConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UserPasswordConfigurationElement.cs deleted file mode 100644 index a1d2aa8842..0000000000 --- a/src/Umbraco.Configuration/UmbracoSettings/UserPasswordConfigurationElement.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class UserPasswordConfigurationElement : PasswordConfigurationElement, IUserPasswordConfiguration - { - } -} From e74570c0ac5cda2527c884964d7a442da1ea21ae Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 14:12:38 +0200 Subject: [PATCH 45/58] More clean up of old configs --- .../Legacy/GlobalSettings.cs | 378 ------------------ .../Models/GlobalSettings.cs | 83 ---- .../Configuration/IGlobalSettings.cs | 110 ----- .../Configuration/Models/GlobalSettings.cs | 2 +- .../ConfigModelConversionsFromLegacy.cs | 66 --- .../ConfigModelConversionsToLegacy.cs | 130 ------ src/Umbraco.Tests.Common/SettingsForTests.cs | 117 ------ src/Umbraco.Tests.Common/TestHelperBase.cs | 3 - .../Models/ConnectionStringsTests.cs | 5 +- .../Extensions/UriExtensionsTests.cs | 2 - .../Umbraco.Web.Common/FileNameTests.cs | 4 +- src/Umbraco.Tests/Models/VariationTests.cs | 3 - .../Repositories/ScriptRepositoryTest.cs | 3 +- .../Repositories/StylesheetRepositoryTest.cs | 3 +- .../PublishedContent/NuCacheChildrenTests.cs | 4 - .../PublishedContent/NuCacheTests.cs | 3 - .../Routing/RoutableDocumentFilterTests.cs | 4 - .../Routing/UmbracoModuleTests.cs | 3 +- ...oviderWithHideTopLevelNodeFromPathTests.cs | 7 +- ...derWithoutHideTopLevelNodeFromPathTests.cs | 1 - .../Routing/UrlsProviderWithDomainsTests.cs | 1 - .../Routing/UrlsWithNestedDomains.cs | 3 - .../Runtimes/CoreRuntimeTests.cs | 6 +- .../Scoping/ScopeEventDispatcherTests.cs | 4 - .../BackOfficeOwinUserManagerTests.cs | 21 +- .../OwinDataProtectorTokenProviderTests.cs | 5 +- .../TestControllerActivatorBase.cs | 15 +- .../TestHelpers/SettingsForTests.cs | 49 --- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 6 +- .../TestHelpers/TestObjects-Mocks.cs | 5 +- .../TestHelpers/TestWithDatabaseBase.cs | 5 - .../Objects/TestUmbracoContextFactory.cs | 6 +- .../Testing/TestingTests/MockTests.cs | 5 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 4 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - .../Web/Mvc/RenderNoContentControllerTests.cs | 14 +- .../Controllers/IconController.cs | 10 +- src/Umbraco.Web/AppBuilderExtensions.cs | 6 +- .../AspNet/AspNetBackOfficeInfo.cs | 4 +- .../Compose/AuditEventsComponent.cs | 10 +- .../BackOfficeUserAuditEventsComponent.cs | 5 +- .../Editors/AuthenticationController.cs | 2 +- .../Editors/BackOfficeController.cs | 2 - .../Editors/BackOfficeServerVariables.cs | 12 +- .../UmbracoAuthorizedJsonController.cs | 4 +- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 2 +- .../Mvc/AreaRegistrationExtensions.cs | 1 - src/Umbraco.Web/Mvc/BackOfficeArea.cs | 1 - .../Mvc/RenderNoContentController.cs | 5 +- .../Mvc/UmbracoAuthorizeAttribute.cs | 4 +- .../Runtime/WebInitialComponent.cs | 1 - .../Security/AppBuilderExtensions.cs | 4 +- .../BackOfficeCookieAuthenticationProvider.cs | 4 +- .../Security/BackOfficeOwinUserManager.cs | 28 +- .../Security/BackOfficeSignInManager.cs | 13 +- .../Security/GetUserSecondsMiddleWare.cs | 8 +- src/Umbraco.Web/UmbracoApplicationBase.cs | 7 +- src/Umbraco.Web/UmbracoContext.cs | 2 - src/Umbraco.Web/UmbracoDefaultOwinStartup.cs | 2 +- src/Umbraco.Web/UmbracoInjectedModule.cs | 14 +- src/Umbraco.Web/UmbracoWebService.cs | 15 +- .../WebApi/UmbracoApiController.cs | 3 +- .../WebApi/UmbracoApiControllerBase.cs | 11 +- .../WebApi/UmbracoAuthorizedApiController.cs | 3 +- .../CDF/UmbracoClientDependencyLoader.cs | 5 +- 65 files changed, 131 insertions(+), 1138 deletions(-) delete mode 100644 src/Umbraco.Configuration/Legacy/GlobalSettings.cs delete mode 100644 src/Umbraco.Configuration/Models/GlobalSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/IGlobalSettings.cs delete mode 100644 src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs delete mode 100644 src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs delete mode 100644 src/Umbraco.Tests.Common/SettingsForTests.cs delete mode 100644 src/Umbraco.Tests/TestHelpers/SettingsForTests.cs diff --git a/src/Umbraco.Configuration/Legacy/GlobalSettings.cs b/src/Umbraco.Configuration/Legacy/GlobalSettings.cs deleted file mode 100644 index 8dee6e79dc..0000000000 --- a/src/Umbraco.Configuration/Legacy/GlobalSettings.cs +++ /dev/null @@ -1,378 +0,0 @@ -using System; -using System.Configuration; -using System.Linq; -using System.Net.Mail; -using System.Xml.Linq; -using Umbraco.Composing; -using Umbraco.Configuration; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.IO; - -namespace Umbraco.Core.Configuration.Legacy -{ - // TODO: Replace checking for if the app settings exist and returning an empty string, instead return the defaults! - // TODO: need to massively cleanup these configuration classes - - /// - /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information from web.config appsettings - /// - public class GlobalSettings : IGlobalSettings - { - - // TODO these should not be static - private static string _reservedPaths; - private static string _reservedUrls; - - //ensure the built on (non-changeable) reserved paths are there at all times - 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! - - /// - /// Used in unit testing to reset all config items that were set with property setters (i.e. did not come from config) - /// - private static void ResetInternal() - { - _reservedPaths = null; - _reservedUrls = null; - } - - /// - /// Resets settings that were set programmatically, to their initial values. - /// - /// To be used in unit tests. - internal static void Reset() - { - ResetInternal(); - } - - - public bool IsSmtpServerConfigured - { - get - { - var smtpSettings = SmtpSettings; - - if (smtpSettings is null) return false; - - if (!(smtpSettings.From is null)) return true; - if (!(smtpSettings.Host is null)) return true; - if (!(smtpSettings.PickupDirectoryLocation is null)) return true; - - return false; - } - } - - public SmtpSettings SmtpSettings - { - get - { - var smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as ConfigurationSection; - if (smtpSection is null) return null; - - var result = new SmtpSettings(); - var from = smtpSection.ElementInformation.Properties["from"]; - if (@from != null - && @from.Value is string fromPropValue - && string.IsNullOrEmpty(fromPropValue) == false - && !string.Equals("noreply@example.com", fromPropValue, StringComparison.OrdinalIgnoreCase)) - { - result.From = fromPropValue; - } - - var specifiedPickupDirectorySection = ConfigurationManager.GetSection("system.net/mailSettings/smtp/specifiedPickupDirectory") as ConfigurationSection; - var pickupDirectoryLocation = specifiedPickupDirectorySection?.ElementInformation.Properties["pickupDirectoryLocation"]; - if (pickupDirectoryLocation != null - && pickupDirectoryLocation.Value is string pickupDirectoryLocationPropValue - && string.IsNullOrEmpty(pickupDirectoryLocationPropValue) == false) - { - result.PickupDirectoryLocation = pickupDirectoryLocationPropValue; - } - - // SmtpClient can magically read the section system.net/mailSettings/smtp/network, witch is always - // null if we use ConfigurationManager.GetSection. SmtpSection does not exist in .Net Standard - var smtpClient = new SmtpClient(); - - result.Host = smtpClient.Host; - result.Port = smtpClient.Port; - - return result; - - } - } - - /// - /// Gets the reserved urls from web.config. - /// - /// The reserved urls. - public string ReservedUrls - { - get - { - if (_reservedUrls != null) return _reservedUrls; - - var urls = ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.ReservedUrls) - ? ConfigurationManager.AppSettings[Constants.AppSettings.ReservedUrls] - : string.Empty; - - //ensure the built on (non-changeable) reserved paths are there at all times - _reservedUrls = StaticReservedUrls + urls; - return _reservedUrls; - } - internal set => _reservedUrls = value; - } - - /// - /// Gets the reserved paths from web.config - /// - /// The reserved paths. - public string ReservedPaths - { - get - { - if (_reservedPaths != null) return _reservedPaths; - - var reservedPaths = StaticReservedPaths; - var umbPath = ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.UmbracoPath) && !ConfigurationManager.AppSettings[Constants.AppSettings.UmbracoPath].IsNullOrWhiteSpace() - ? ConfigurationManager.AppSettings[Constants.AppSettings.UmbracoPath] - : "~/umbraco"; - //always add the umbraco path to the list - reservedPaths += umbPath.EnsureEndsWith(','); - - var allPaths = ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.ReservedPaths) - ? ConfigurationManager.AppSettings[Constants.AppSettings.ReservedPaths] - : string.Empty; - - _reservedPaths = reservedPaths + allPaths; - return _reservedPaths; - } - } - - - - - /// - /// Gets or sets the configuration status. This will return the version number of the currently installed umbraco instance. - /// - /// The configuration status. - public string ConfigurationStatus - { - get - { - return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.ConfigurationStatus) - ? ConfigurationManager.AppSettings[Constants.AppSettings.ConfigurationStatus] - : string.Empty; - } - set - { - SaveSetting(Constants.AppSettings.ConfigurationStatus, value, Current.IOHelper); //TODO remove - } - } - - /// - /// Saves a setting into the configuration file. - /// - /// Key of the setting to be saved. - /// Value of the setting to be saved. - internal static void SaveSetting(string key, string value, IIOHelper ioHelper) - { - var fileName = ioHelper.MapPath("~/web.config"); - var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); - - var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); - - // Update appSetting if it exists, or else create a new appSetting for the given key and value - var setting = appSettings.Descendants("add").FirstOrDefault(s => s.Attribute("key").Value == key); - if (setting == null) - appSettings.Add(new XElement("add", new XAttribute("key", key), new XAttribute("value", value))); - else - setting.Attribute("value").Value = value; - - xml.Save(fileName, SaveOptions.DisableFormatting); - ConfigurationManager.RefreshSection("appSettings"); - } - - - /// - /// Gets the time out in minutes. - /// - /// The time out in minutes. - public int TimeOutInMinutes - { - get - { - try - { - return int.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.TimeOutInMinutes]); - } - catch - { - return 20; - } - } - } - - /// - /// Returns the number of days that should take place between version checks. - /// - /// The version check period in days (0 = never). - public int VersionCheckPeriod - { - get - { - try - { - var val = ConfigurationManager.AppSettings[Constants.AppSettings.VersionCheckPeriod]; - if (!(val is null)) - { - return int.Parse(val); - } - } - catch - { - // Ignore - } - return 7; - } - } - - - - - /// - /// Gets the default UI language. - /// - /// The default UI language. - // ReSharper disable once InconsistentNaming - public string DefaultUILanguage - { - get - { - return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.DefaultUILanguage) - ? ConfigurationManager.AppSettings[Constants.AppSettings.DefaultUILanguage] - : string.Empty; - } - } - - /// - /// Gets a value indicating whether umbraco should hide top level nodes from generated urls. - /// - /// - /// true if umbraco hides top level nodes from urls; otherwise, false. - /// - public bool HideTopLevelNodeFromPath - { - get - { - try - { - return bool.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.HideTopLevelNodeFromPath]); - } - catch - { - return false; - } - } - } - - /// - /// Gets a value indicating whether umbraco should force a secure (https) connection to the backoffice. - /// - public bool UseHttps - { - get - { - try - { - return bool.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.UseHttps]); - } - catch - { - return false; - } - } - } - - private string _umbracoMediaPath = null; - public string UmbracoMediaPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoMediaPath, "~/media", ref _umbracoMediaPath); - - private string _umbracoScriptsPath = null; - public string UmbracoScriptsPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoScriptsPath, "~/scripts", ref _umbracoScriptsPath); - - private string _umbracoCssPath = null; - public string UmbracoCssPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoCssPath, "~/css", ref _umbracoCssPath); - - private string _umbracoPath = null; - public string UmbracoPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoPath, "~/umbraco", ref _umbracoPath); - - private bool _installMissingDatabase; - public bool InstallMissingDatabase => GetterWithDefaultValue("Umbraco.Core.RuntimeState.InstallMissingDatabase", false, ref _installMissingDatabase); - - private bool _installEmptyDatabase; - public bool InstallEmptyDatabase => GetterWithDefaultValue("Umbraco.Core.RuntimeState.InstallEmptyDatabase", false, ref _installEmptyDatabase); - - private bool _disableElectionForSingleServer; - public bool DisableElectionForSingleServer => GetterWithDefaultValue(Constants.AppSettings.DisableElectionForSingleServer, false, ref _disableElectionForSingleServer); - - private string _registerType; - public string RegisterType => GetterWithDefaultValue(Constants.AppSettings.RegisterType, string.Empty, ref _registerType); - - private string _databaseFactoryServerVersion; - public string DatabaseFactoryServerVersion => GetterWithDefaultValue(Constants.AppSettings.Debug.DatabaseFactoryServerVersion, string.Empty, ref _databaseFactoryServerVersion); - - - - private string _iconsPath; - /// - /// Gets the path to folder containing the icons used in the umbraco backoffice (/umbraco/assets/icons by default). - /// - /// The icons path. - public string IconsPath => GetterWithDefaultValue(Constants.AppSettings.IconsPath, $"{UmbracoPath}/assets/icons", ref _iconsPath); - - private string _mainDomLock; - - public string MainDomLock => GetterWithDefaultValue(Constants.AppSettings.MainDomLock, string.Empty, ref _mainDomLock); - - private T GetterWithDefaultValue(string appSettingKey, T defaultValue, ref T backingField) - { - if (backingField != null) return backingField; - - if (ConfigurationManager.AppSettings.ContainsKey(appSettingKey)) - { - try - { - var value = ConfigurationManager.AppSettings[appSettingKey]; - - backingField = (T)Convert.ChangeType(value, typeof(T)); - } - catch - { - /* ignore and use default value */ - backingField = defaultValue; - } - } - else - { - backingField = defaultValue; - } - - return backingField; - } - - /// - /// Gets the path to the razor file used when no published content is available. - /// - public string NoNodesViewPath - { - get - { - var configuredValue = ConfigurationManager.AppSettings[Constants.AppSettings.NoNodesViewPath]; - if (!string.IsNullOrWhiteSpace(configuredValue)) - { - return configuredValue; - } - - return "~/config/splashes/NoNodes.cshtml"; - } - } - } -} diff --git a/src/Umbraco.Configuration/Models/GlobalSettings.cs b/src/Umbraco.Configuration/Models/GlobalSettings.cs deleted file mode 100644 index 5dfac1f8a3..0000000000 --- a/src/Umbraco.Configuration/Models/GlobalSettings.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Linq; -using System.Net.Mail; -using Microsoft.Extensions.Configuration; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; - -namespace Umbraco.Configuration.Models -{ - /// - /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information - /// from web.config appsettings - /// - internal class GlobalSettings : IGlobalSettings - { - private const string Prefix = Constants.Configuration.ConfigGlobalPrefix; - - 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! - - private readonly IConfiguration _configuration; - - public GlobalSettings(IConfiguration configuration) - { - _configuration = configuration; - } - - public string ReservedUrls => _configuration.GetValue(Prefix + "ReservedUrls", StaticReservedUrls); - public string ReservedPaths => _configuration.GetValue(Prefix + "ReservedPaths", StaticReservedPaths); - - // TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings - public string ConfigurationStatus - { - get => _configuration.GetValue(Prefix + "ConfigurationStatus"); - set => throw new NotImplementedException("We should remove this and only use the value from database"); - } - - public int TimeOutInMinutes => _configuration.GetValue(Prefix + "TimeOutInMinutes", 20); - public string DefaultUILanguage => _configuration.GetValue(Prefix + "DefaultUILanguage", "en-US"); - - public bool HideTopLevelNodeFromPath => - _configuration.GetValue(Prefix + "HideTopLevelNodeFromPath", true); - - public bool UseHttps => _configuration.GetValue(Prefix + "UseHttps", false); - public int VersionCheckPeriod => _configuration.GetValue(Prefix + "VersionCheckPeriod", 7); - public string UmbracoPath => _configuration.GetValue(Prefix + "UmbracoPath", "~/umbraco"); - public string IconsPath => _configuration.GetValue(Prefix + "IconsPath", $"{UmbracoPath}/assets/icons"); - - public string UmbracoCssPath => _configuration.GetValue(Prefix + "UmbracoCssPath", "~/css"); - - public string UmbracoScriptsPath => - _configuration.GetValue(Prefix + "UmbracoScriptsPath", "~/scripts"); - - public string UmbracoMediaPath => _configuration.GetValue(Prefix + "UmbracoMediaPath", "~/media"); - - public bool InstallMissingDatabase => - _configuration.GetValue(Prefix + "InstallMissingDatabase", false); - - public bool InstallEmptyDatabase => _configuration.GetValue(Prefix + "InstallEmptyDatabase", false); - - public bool DisableElectionForSingleServer => - _configuration.GetValue(Prefix + "DisableElectionForSingleServer", false); - - public string RegisterType => _configuration.GetValue(Prefix + "RegisterType", string.Empty); - - public string DatabaseFactoryServerVersion => - _configuration.GetValue(Prefix + "DatabaseFactoryServerVersion", string.Empty); - - public string MainDomLock => _configuration.GetValue(Prefix + "MainDomLock", string.Empty); - - public string NoNodesViewPath => - _configuration.GetValue(Prefix + "NoNodesViewPath", "~/config/splashes/NoNodes.cshtml"); - - public bool IsSmtpServerConfigured => - _configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "Smtp")?.GetChildren().Any() ?? false; - - public SmtpSettings SmtpSettings => new SmtpSettings(); - } -} diff --git a/src/Umbraco.Core/Configuration/IGlobalSettings.cs b/src/Umbraco.Core/Configuration/IGlobalSettings.cs deleted file mode 100644 index ac32ea41c6..0000000000 --- a/src/Umbraco.Core/Configuration/IGlobalSettings.cs +++ /dev/null @@ -1,110 +0,0 @@ -using Umbraco.Core.Configuration.Models; - -namespace Umbraco.Core.Configuration -{ - /// - /// Contains general settings information for the entire Umbraco instance based on information from web.config appsettings - /// - public interface IGlobalSettings - { - // fixme: Review this class, it is now just a dumping ground for config options (based basically on whatever might be in appSettings), - // our config classes should be named according to what they are configuring. - - /// - /// Gets the reserved urls from web.config. - /// - /// The reserved urls. - string ReservedUrls { get; } - - /// - /// Gets the reserved paths from web.config - /// - /// The reserved paths. - string ReservedPaths { get; } - - /// - /// Gets the path to umbraco's icons directory (/umbraco/assets/icons by default). - /// - string IconsPath { get; } - - /// - /// Gets or sets the configuration status. This will return the version number of the currently installed umbraco instance. - /// - string ConfigurationStatus { get; set; } - - /// - /// Gets the time out in minutes. - /// - int TimeOutInMinutes { get; } - - /// - /// Gets the default UI language. - /// - /// The default UI language. - // ReSharper disable once InconsistentNaming - string DefaultUILanguage { get; } - - /// - /// Gets a value indicating whether umbraco should hide top level nodes from generated urls. - /// - /// - /// true if umbraco hides top level nodes from urls; otherwise, false. - /// - bool HideTopLevelNodeFromPath { get; } - - /// - /// Gets a value indicating whether umbraco should force a secure (https) connection to the backoffice. - /// - bool UseHttps { get; } - - /// - /// Returns a string value to determine if umbraco should skip version-checking. - /// - /// The version check period in days (0 = never). - int VersionCheckPeriod { get; } - - /// - /// Gets the path to umbraco's root directory. - /// - string UmbracoPath { get; } - string UmbracoCssPath { get; } - string UmbracoScriptsPath { get; } - string UmbracoMediaPath { get; } - - bool IsSmtpServerConfigured { get; } - SmtpSettings SmtpSettings { get; } - - /// - /// Gets a value indicating whether the runtime should enter Install level when the database is missing. - /// - /// - /// By default, when a database connection string is configured but it is not possible to - /// connect to the database, the runtime enters the BootFailed level. If this options is set to true, - /// it enters the Install level instead. - /// It is then up to the implementor, that is setting this value, to take over the installation - /// sequence. - /// - bool InstallMissingDatabase { get; } - - /// - /// Gets a value indicating whether the runtime should enter Install level when the database is empty. - /// - /// - /// By default, when a database connection string is configured and it is possible to connect to - /// the database, but the database is empty, the runtime enters the BootFailed level. If this options - /// is set to true, it enters the Install level instead. - /// It is then up to the implementor, that is setting this value, to take over the installation - /// sequence. - /// - bool InstallEmptyDatabase { get; } - bool DisableElectionForSingleServer { get; } - string RegisterType { get; } - string DatabaseFactoryServerVersion { get; } - string MainDomLock { get; } - - /// - /// Gets the path to the razor file used when no published content is available. - /// - string NoNodesViewPath { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index c28e05b32e..84956c7636 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -7,7 +7,7 @@ public class GlobalSettings { internal const string - StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma! + StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,~/umbraco/,"; //must end with a comma! internal const string StaticReservedUrls = "~/config/splashes/noNodes.aspx,~/.well-known,"; //must end with a comma! diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs deleted file mode 100644 index 278bbcfca2..0000000000 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsFromLegacy.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Infrastructure.Configuration -{ - /// - /// TEMPORARY: this class has been added just to ensure Umbraco.Web functionality continues to compile, by - /// converting between e.g. (used by - /// legacy configuration and (used by Netcore/IOptions configuration). - /// - public static class ConfigModelConversionsFromLegacy - { - public static GlobalSettings ConvertGlobalSettings(IGlobalSettings globalSettings) - { - return new GlobalSettings - { - DatabaseFactoryServerVersion = globalSettings.DatabaseFactoryServerVersion, - DefaultUILanguage = globalSettings.DefaultUILanguage, - DisableElectionForSingleServer = globalSettings.DisableElectionForSingleServer, - HideTopLevelNodeFromPath = globalSettings.HideTopLevelNodeFromPath, - InstallEmptyDatabase = globalSettings.InstallEmptyDatabase, - InstallMissingDatabase = globalSettings.InstallMissingDatabase, - MainDomLock = globalSettings.MainDomLock, - NoNodesViewPath = globalSettings.NoNodesViewPath, - RegisterType = globalSettings.RegisterType, - ReservedPaths = globalSettings.ReservedPaths, - ReservedUrls = globalSettings.ReservedUrls, - Smtp = globalSettings.SmtpSettings != null - ? new SmtpSettings - { - DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, - From = globalSettings.SmtpSettings.From, - Host = globalSettings.SmtpSettings.Host, - Password = globalSettings.SmtpSettings.Password, - PickupDirectoryLocation = globalSettings.SmtpSettings.PickupDirectoryLocation, - Port = globalSettings.SmtpSettings.Port, - Username = globalSettings.SmtpSettings.Username, - } - : new SmtpSettings(), - TimeOutInMinutes = globalSettings.TimeOutInMinutes, - UmbracoCssPath = globalSettings.UmbracoCssPath, - UmbracoMediaPath = globalSettings.UmbracoMediaPath, - UmbracoPath = globalSettings.UmbracoPath, - UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, - IconsPath = globalSettings.IconsPath, - UseHttps = globalSettings.UseHttps, - VersionCheckPeriod = globalSettings.VersionCheckPeriod, - }; - } - - public static UserPasswordConfigurationSettings ConvertUserPasswordConfiguration(IUserPasswordConfiguration passwordConfiguration) - { - return new UserPasswordConfigurationSettings - { - HashAlgorithmType = passwordConfiguration.HashAlgorithmType, - RequireDigit = passwordConfiguration.RequireDigit, - RequiredLength = passwordConfiguration.RequiredLength, - RequireLowercase = passwordConfiguration.RequireLowercase, - RequireNonLetterOrDigit = passwordConfiguration.RequireNonLetterOrDigit, - RequireUppercase = passwordConfiguration.RequireUppercase, - }; - } - } -} diff --git a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs b/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs deleted file mode 100644 index ca4c1cd29e..0000000000 --- a/src/Umbraco.Infrastructure/Configuration/ConfigModelConversionsToLegacy.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System.Collections.Generic; -using System.Net.Mail; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; - -namespace Umbraco.Infrastructure.Configuration -{ - /// - /// TEMPORARY: this class has been added just to ensure tests on Umbraco.Web functionality, that still use the interface - /// based configuration, by converting between e.g (used by - /// legacy configuration and (used by Netcore/IOptions configuration). - /// - public static class ConfigModelConversionsToLegacy - { - public static IGlobalSettings ConvertGlobalSettings(GlobalSettings globalSettings) - { - return new TestGlobalSettings - { - DatabaseFactoryServerVersion = globalSettings.DatabaseFactoryServerVersion, - DefaultUILanguage = globalSettings.DefaultUILanguage, - DisableElectionForSingleServer = globalSettings.DisableElectionForSingleServer, - HideTopLevelNodeFromPath = globalSettings.HideTopLevelNodeFromPath, - InstallEmptyDatabase = globalSettings.InstallEmptyDatabase, - InstallMissingDatabase = globalSettings.InstallMissingDatabase, - MainDomLock = globalSettings.MainDomLock, - NoNodesViewPath = globalSettings.NoNodesViewPath, - RegisterType = globalSettings.RegisterType, - ReservedPaths = globalSettings.ReservedPaths, - ReservedUrls = globalSettings.ReservedUrls, - SmtpSettings = new SmtpSettings - { - DeliveryMethod = globalSettings.Smtp.DeliveryMethod, - From = globalSettings.Smtp.From, - Host = globalSettings.Smtp.Host, - Password = globalSettings.Smtp.Password, - PickupDirectoryLocation = globalSettings.Smtp.PickupDirectoryLocation, - Port = globalSettings.Smtp.Port, - Username = globalSettings.Smtp.Username, - }, - TimeOutInMinutes = globalSettings.TimeOutInMinutes, - UmbracoCssPath = globalSettings.UmbracoCssPath, - UmbracoMediaPath = globalSettings.UmbracoMediaPath, - UmbracoPath = globalSettings.UmbracoPath, - UmbracoScriptsPath = globalSettings.UmbracoScriptsPath, - IconsPath = globalSettings.IconsPath, - UseHttps = globalSettings.UseHttps, - VersionCheckPeriod = globalSettings.VersionCheckPeriod, - }; - } - - public static IUserPasswordConfiguration ConvertUserPasswordConfiguration(UserPasswordConfigurationSettings passwordConfiguration) - { - return new TestUserPasswordConfiguration - { - HashAlgorithmType = passwordConfiguration.HashAlgorithmType, - RequireDigit = passwordConfiguration.RequireDigit, - RequiredLength = passwordConfiguration.RequiredLength, - RequireLowercase = passwordConfiguration.RequireLowercase, - RequireNonLetterOrDigit = passwordConfiguration.RequireNonLetterOrDigit, - RequireUppercase = passwordConfiguration.RequireUppercase, - }; - } - - private class TestGlobalSettings : IGlobalSettings - { - public string ReservedUrls { get; set; } - - public string ReservedPaths { get; set; } - - public int TimeOutInMinutes { get; set; } - - public string DefaultUILanguage { get; set; } - - public bool HideTopLevelNodeFromPath { get; set; } - - public bool UseHttps { get; set; } - - public int VersionCheckPeriod { get; set; } - - public string UmbracoPath { get; set; } - - public string UmbracoCssPath { get; set; } - - public string UmbracoScriptsPath { get; set; } - - public string UmbracoMediaPath { get; set; } - - public bool IsSmtpServerConfigured { get; set; } - - public SmtpSettings SmtpSettings { get; set; } - - public bool InstallMissingDatabase { get; set; } - - public bool InstallEmptyDatabase { get; set; } - - public bool DisableElectionForSingleServer { get; set; } - - public string RegisterType { get; set; } - - public string DatabaseFactoryServerVersion { get; set; } - - public string MainDomLock { get; set; } - - public string NoNodesViewPath { get; set; } - - public string IconsPath { get; set; } - - public string ConfigurationStatus { get; set; } - } - - - private class TestUserPasswordConfiguration : IUserPasswordConfiguration - { - public int RequiredLength { get; set; } - - public bool RequireNonLetterOrDigit { get; set; } - - public bool RequireDigit { get; set; } - - public bool RequireLowercase { get; set; } - - public bool RequireUppercase { get; set; } - - public string HashAlgorithmType { get; set; } - - public int MaxFailedAccessAttemptsBeforeLockout { get; set; } - } - } -} diff --git a/src/Umbraco.Tests.Common/SettingsForTests.cs b/src/Umbraco.Tests.Common/SettingsForTests.cs deleted file mode 100644 index 4d21b739e8..0000000000 --- a/src/Umbraco.Tests.Common/SettingsForTests.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System.Collections.Generic; -using Moq; -using Semver; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.IO; -using Umbraco.Core.Models.PublishedContent; - -namespace Umbraco.Tests.Common -{ - public class SettingsForTests - { - public SettingsForTests() - { - } - - public IGlobalSettings GenerateMockGlobalSettings(IUmbracoVersion umbVersion = null) - { - var semanticVersion = umbVersion?.SemanticVersion ?? new SemVersion(9); - - var config = Mock.Of( - settings => - settings.UseHttps == false && - settings.HideTopLevelNodeFromPath == false && - settings.TimeOutInMinutes == 20 && - settings.DefaultUILanguage == "en" && - settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") && - settings.ReservedUrls == GlobalSettings.StaticReservedUrls && - settings.UmbracoPath == "~/umbraco" && - settings.UmbracoMediaPath == "~/media" && - settings.UmbracoCssPath == "~/css" && - settings.UmbracoScriptsPath == "~/scripts" - ); - - - - return config; - } - - //// from appSettings - - //private readonly IDictionary SavedAppSettings = new Dictionary(); - - //static void SaveSetting(string key) - //{ - // SavedAppSettings[key] = ConfigurationManager.AppSettings[key]; - //} - - //static void SaveSettings() - //{ - // SaveSetting("umbracoHideTopLevelNodeFromPath"); - // SaveSetting("umbracoUseDirectoryUrls"); - // SaveSetting("umbracoPath"); - // SaveSetting("umbracoReservedPaths"); - // SaveSetting("umbracoReservedUrls"); - // SaveSetting("umbracoConfigurationStatus"); - //} - - - - // reset & defaults - - //static SettingsForTests() - //{ - // //SaveSettings(); - //} - - public void Reset() - { - ResetSettings(); - GlobalSettings.Reset(); - - //foreach (var kvp in SavedAppSettings) - // ConfigurationManager.AppSettings.Set(kvp.Key, kvp.Value); - - //// set some defaults that are wrong in the config file?! - //// this is annoying, really - //HideTopLevelNodeFromPath = false; - } - - /// - /// This sets all settings back to default settings - /// - private void ResetSettings() - { - _defaultGlobalSettings.Clear(); - } - - private readonly Dictionary _defaultGlobalSettings = new Dictionary(); - - public IGlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion) - { - if (_defaultGlobalSettings.TryGetValue(umbVersion.SemanticVersion, out var settings)) - return settings; - - settings = GenerateMockGlobalSettings(umbVersion); - _defaultGlobalSettings[umbVersion.SemanticVersion] = settings; - return settings; - } - - public IUserPasswordConfiguration GenerateMockUserPasswordConfiguration() - { - var mock = new Mock(); - - return mock.Object; - } - - public IMemberPasswordConfiguration GenerateMockMemberPasswordConfiguration() - { - var mock = new Mock(); - - return mock.Object; - } - } -} diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 65b4002b0d..7b5fed3000 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -35,7 +35,6 @@ namespace Umbraco.Tests.Common protected TestHelperBase(Assembly entryAssembly) { - SettingsForTests = new SettingsForTests(); MainDom = new SimpleMainDom(); _typeFinder = new TypeFinder(Mock.Of(), new DefaultUmbracoAssemblyProvider(entryAssembly), new VaryingRuntimeHash()); } @@ -99,8 +98,6 @@ namespace Umbraco.Tests.Common return _uriUtility; } } - - public SettingsForTests SettingsForTests { get; } /// /// Some test files are copied to the /bin (/bin/debug) on build, this is a utility to return their physical path based on a virtual path name /// diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs index 24917aba15..8c5f096208 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs @@ -1,7 +1,4 @@ -using Microsoft.Extensions.Configuration; -using Moq; -using NUnit.Framework; -using Umbraco.Configuration.Models; +using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration.Models; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs index f098af7de6..77a7ba1732 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UriExtensionsTests.cs @@ -17,12 +17,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions [OneTimeSetUp] public void Setup() { - _settingsForTests = new SettingsForTests(); _hostEnvironment = Mock.Of(); _globalSettings = new GlobalSettingsBuilder().Build(); } - private SettingsForTests _settingsForTests; private IWebHostEnvironment _hostEnvironment; private GlobalSettings _globalSettings; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs index 2669d74b11..e7cf097dd5 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs @@ -55,10 +55,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common [Test] [AutoMoqData] public void PreviewViewExists( - [Frozen] IGlobalSettings globalSettings, + [Frozen] IOptions globalSettings, PreviewController sut) { - Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); + globalSettings.Value.UmbracoPath = "/"; var viewResult = sut.Index() as ViewResult; var fileName = GetViewName(viewResult); diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index 1c7445a901..17042d5c96 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -23,9 +23,6 @@ namespace Umbraco.Tests.Models [SetUp] public void SetUp() { - // annoying, but content type wants short string helper ;( - SettingsForTests.Reset(); - // well, this is also annoying, but... // validating a value is performed by its data editor, // based upon the configuration in the data type, so we diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 2ef8d2d30f..6a45dafa54 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -31,7 +32,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, SettingsForTests.GenerateMockGlobalSettings().UmbracoScriptsPath); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, new GlobalSettings().UmbracoScriptsPath); Mock.Get(_fileSystems).Setup(x => x.ScriptsFileSystem).Returns(_fileSystem); using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index 5b6f77ac7e..028f99f89e 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; @@ -30,7 +31,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, SettingsForTests.GenerateMockGlobalSettings().UmbracoCssPath); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, new GlobalSettings().UmbracoCssPath); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index d224d97467..e50d6fe8ab 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -7,12 +7,8 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; using Umbraco.Core.Events; using Umbraco.Core.Hosting; -using Umbraco.Core.Install; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index d65d89a363..010569fe42 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -6,10 +6,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; using Umbraco.Core.Events; -using Umbraco.Core.Install; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; diff --git a/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs b/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs index 9bf85d61be..c0b83b08cb 100644 --- a/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs +++ b/src/Umbraco.Tests/Routing/RoutableDocumentFilterTests.cs @@ -1,11 +1,7 @@ using System; using System.Web.Mvc; using System.Web.Routing; -using Moq; using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web; diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index a2b3ce62e4..ceea358a42 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -5,7 +5,6 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; -using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -39,7 +38,7 @@ namespace Umbraco.Tests.Routing new RoutableDocumentFilter(globalSettings, IOHelper), UriUtility, AppCaches.RequestCache, - ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), + globalSettings, HostingEnvironment ); diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs index e6774076bf..2c5bfc52e9 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs @@ -1,13 +1,8 @@ -using Moq; -using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Core.Configuration; +using NUnit.Framework; using Umbraco.Core.Configuration.Models; -using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Testing; -using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; namespace Umbraco.Tests.Routing diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs index bb25635d6f..e8f3bf97fd 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs @@ -7,7 +7,6 @@ using NUnit.Framework; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; diff --git a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs index c566e742cb..a960cdba53 100644 --- a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs @@ -7,7 +7,6 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; -using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.LegacyXmlPublishedCache; diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index d5b98c402f..03faa70d8c 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -3,17 +3,14 @@ using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Tests.TestHelpers; using Umbraco.Web.Routing; using Umbraco.Core.Services; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Web; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; -using Umbraco.Infrastructure.Configuration; namespace Umbraco.Tests.Routing { diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 7cb20cbbde..045ed2e3e8 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -9,14 +9,12 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; -using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Stubs; @@ -87,7 +85,7 @@ namespace Umbraco.Tests.Runtimes { public TestUmbracoApplication() : base(_logger, new SecuritySettings(), - ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.DefaultGlobalSettings), + new GlobalSettings(), new ConnectionStrings(), _ioHelper, _profiler, new AspNetHostingEnvironment(Options.Create(new HostingSettings())), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _logger, Options.Create(new WebRoutingSettings()))) { @@ -96,7 +94,7 @@ namespace Umbraco.Tests.Runtimes private static readonly DebugDiagnosticsLogger _logger = new DebugDiagnosticsLogger(new MessageTemplates()); private static readonly IIOHelper _ioHelper = TestHelper.IOHelper; private static readonly IProfiler _profiler = new TestProfiler(); - private static readonly IGlobalSettings _globalSettings = SettingsForTests.DefaultGlobalSettings; + private static readonly GlobalSettings _globalSettings = new GlobalSettings(); public IRuntime Runtime { get; private set; } diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index d775b0d8d3..5ca6308bcd 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -45,16 +45,12 @@ namespace Umbraco.Tests.Scoping Current.Reset(); Current.Factory = composition.CreateFactory(); - - SettingsForTests.Reset(); // ensure we have configuration } [TearDown] public void TearDown() { Current.Reset(); - - SettingsForTests.Reset(); } [TestCase(false, true, true)] diff --git a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs index ca38f0ce70..32c85121d2 100644 --- a/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeOwinUserManagerTests.cs @@ -3,14 +3,15 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Microsoft.Owin.Security.DataProtection; using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; -using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Web.Security; @@ -24,28 +25,32 @@ namespace Umbraco.Tests.Security const string v7Hash = "7Uob6fMTTxDIhWGebYiSxg==P+hgvWlXLbDd4cFLADn811KOaVI/9pg1PNvTuG5NklY="; const string plaintext = "4XxzH3s3&J"; - var mockPasswordConfiguration = new Mock(); + var userPasswordConfiguration = new UserPasswordConfigurationSettings() + { + HashAlgorithmType = Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName + }; var mockIpResolver = new Mock(); var mockUserStore = new Mock>(); var mockDataProtectionProvider = new Mock(); mockDataProtectionProvider.Setup(x => x.Create(It.IsAny())) .Returns(new Mock().Object); - mockPasswordConfiguration.Setup(x => x.HashAlgorithmType) - .Returns(Constants.Security.AspNetUmbraco8PasswordHashAlgorithmName); + var userManager = BackOfficeOwinUserManager.Create( - mockPasswordConfiguration.Object, + Options.Create(userPasswordConfiguration), mockIpResolver.Object, mockUserStore.Object, null, mockDataProtectionProvider.Object, new NullLogger>()); - var mockGlobalSettings = new Mock(); - mockGlobalSettings.Setup(x => x.DefaultUILanguage).Returns("test"); + var globalSettings = new GlobalSettings() + { + DefaultUILanguage = "test" + }; - var user = new BackOfficeIdentityUser(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(mockGlobalSettings.Object), 2, new List()) + var user = new BackOfficeIdentityUser(globalSettings, 2, new List()) { UserName = "alice", Name = "Alice", diff --git a/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs b/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs index 65efdfeb0d..4874545571 100644 --- a/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs +++ b/src/Umbraco.Tests/Security/OwinDataProtectorTokenProviderTests.cs @@ -8,6 +8,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Tests.Common.Builders; using Umbraco.Web.Security; @@ -82,7 +83,7 @@ namespace Umbraco.Tests.Security reader.ReadInt64(); // creation time reader.ReadString(); // user ID var purpose = reader.ReadString(); - + Assert.AreEqual(expectedPurpose, purpose); } } @@ -229,8 +230,6 @@ namespace Umbraco.Tests.Security _mockDataProtector.Setup(x => x.Unprotect(It.IsAny())).Returns((byte[] originalBytes) => originalBytes); var globalSettings = new GlobalSettingsBuilder().Build(); - var mockGlobalSettings = new Mock(); - mockGlobalSettings.Setup(x => x.DefaultUILanguage).Returns("test"); _mockUserManager = new Mock>(new Mock>().Object, null, null, null, null, null, null, null, null); diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index 27aa9a832c..87d470f31e 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -1,32 +1,21 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Web; using System.Web.Http; using System.Web.Http.Controllers; using System.Web.Http.Dispatcher; -using System.Web.Security; using Moq; using Umbraco.Core.BackOffice; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Dictionary; -using Umbraco.Core.IO; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi; -using Umbraco.Core.Logging; -using Umbraco.Infrastructure.Configuration; -using Umbraco.Tests.Testing.Objects.Accessors; -using Umbraco.Web.Security.Providers; -using Umbraco.Tests.Strings; using Umbraco.Tests.Common; using Umbraco.Tests.TestHelpers.Entities; @@ -68,7 +57,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting contentTypeService: mockedContentTypeService, localizedTextService:Mock.Of()); - var globalSettings = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.GenerateMockGlobalSettings()); + var globalSettings = new GlobalSettings(); // FIXME: v8? ////new app context diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs deleted file mode 100644 index af6b008a14..0000000000 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Tests.TestHelpers -{ - public class SettingsForTests - { - private static Common.SettingsForTests _settingsForTests = new Common.SettingsForTests(); - - public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateMockGlobalSettings(TestHelper.GetUmbracoVersion()); - - //// from appSettings - - //private static readonly IDictionary SavedAppSettings = new Dictionary(); - - //static void SaveSetting(string key) - //{ - // SavedAppSettings[key] = ConfigurationManager.AppSettings[key]; - //} - - //static void SaveSettings() - //{ - // SaveSetting("umbracoHideTopLevelNodeFromPath"); - // SaveSetting("umbracoUseDirectoryUrls"); - // SaveSetting("umbracoPath"); - // SaveSetting("umbracoReservedPaths"); - // SaveSetting("umbracoReservedUrls"); - // SaveSetting("umbracoConfigurationStatus"); - //} - - - - // reset & defaults - - //static SettingsForTests() - //{ - // //SaveSettings(); - //} - - public static void Reset() => _settingsForTests.Reset(); - - internal static IGlobalSettings DefaultGlobalSettings => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion()); - - public static IUserPasswordConfiguration GenerateMockUserPasswordConfiguration() => _settingsForTests.GenerateMockUserPasswordConfiguration(); - - public static IMemberPasswordConfiguration GenerateMockMemberPasswordConfiguration() => _settingsForTests.GenerateMockMemberPasswordConfiguration(); - } -} diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 7161e82323..760fb7dbaa 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -62,7 +62,7 @@ namespace Umbraco.Tests.TestHelpers public override IBackOfficeInfo GetBackOfficeInfo() => new AspNetBackOfficeInfo( - SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion()), + new GlobalSettings(), TestHelper.IOHelper, Mock.Of(), Options.Create(new WebRoutingSettings())); public override IHostingEnvironment GetHostingEnvironment() @@ -116,12 +116,12 @@ namespace Umbraco.Tests.TestHelpers public static void InitializeContentDirectories() { - CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, SettingsForTests.GenerateMockGlobalSettings().UmbracoMediaPath, Constants.SystemDirectories.AppPlugins }); + CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath, Constants.SystemDirectories.AppPlugins }); } public static void CleanContentDirectories() { - CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, SettingsForTests.GenerateMockGlobalSettings().UmbracoMediaPath }); + CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath }); } public static void CreateDirectories(string[] directories) diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 1ed2bce83e..7037961e7d 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -7,15 +7,12 @@ using System.Linq.Expressions; using Moq; using Umbraco.Core; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence; -using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Services; -using Umbraco.Infrastructure.Configuration; using Umbraco.Persistance.SqlCe; using Umbraco.Tests.Common; using Umbraco.Web; @@ -140,7 +137,7 @@ namespace Umbraco.Tests.TestHelpers public GlobalSettings GetGlobalSettings() { - return ConfigModelConversionsFromLegacy.ConvertGlobalSettings(SettingsForTests.DefaultGlobalSettings); + return new GlobalSettings(); } public IFileSystems GetFileSystemsMock() { diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 54123ad78b..f1a834021f 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Configuration; using System.Data.SqlServerCe; -using System.Linq; using System.Threading; using System.Web.Routing; using System.Xml; @@ -10,9 +8,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.SqlSyntax; @@ -30,7 +26,6 @@ using Umbraco.Tests.Testing; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence.Repositories; -using Umbraco.Infrastructure.Configuration; using Umbraco.Persistance.SqlCe; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Web.WebApi; diff --git a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs index 595185c271..544e60d721 100644 --- a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs +++ b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs @@ -1,10 +1,6 @@ using Moq; -using NUnit.Framework.Internal; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Services; -using Umbraco.Infrastructure.Configuration; using Umbraco.Tests.Common; using Umbraco.Tests.TestHelpers; using Umbraco.Web; @@ -23,7 +19,7 @@ namespace Umbraco.Tests.Testing.Objects IHttpContextAccessor httpContextAccessor = null, IPublishedUrlProvider publishedUrlProvider = null) { - if (globalSettings == null) globalSettings = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(TestHelpers.SettingsForTests.GenerateMockGlobalSettings()); + if (globalSettings == null) globalSettings = new GlobalSettings(); if (umbracoContextAccessor == null) umbracoContextAccessor = new TestUmbracoContextAccessor(); if (httpContextAccessor == null) httpContextAccessor = TestHelper.GetHttpContextAccessor(); if (publishedUrlProvider == null) publishedUrlProvider = TestHelper.GetPublishedUrlProvider(); diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index 0232cafb1c..8a08e2be07 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Dictionary; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; @@ -110,7 +111,7 @@ namespace Umbraco.Tests.Testing.TestingTests var membershipHelper = new MembershipHelper(Mock.Of(), Mock.Of(), membershipProvider, Mock.Of(), memberService, memberTypeService, Mock.Of(), AppCaches.Disabled, logger, ShortStringHelper, Mock.Of()); var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of() })); - var umbracoApiController = new FakeUmbracoApiController(Mock.Of(), Mock.Of(), Mock.Of(), ServiceContext.CreatePartial(), AppCaches.NoCache, logger, Mock.Of(), umbracoMapper, Mock.Of()); + var umbracoApiController = new FakeUmbracoApiController(new GlobalSettings(), Mock.Of(), Mock.Of(), ServiceContext.CreatePartial(), AppCaches.NoCache, logger, Mock.Of(), umbracoMapper, Mock.Of()); Assert.Pass(); } @@ -118,7 +119,7 @@ namespace Umbraco.Tests.Testing.TestingTests internal class FakeUmbracoApiController : UmbracoApiController { - public FakeUmbracoApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + public FakeUmbracoApiController(GlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 541021613e..0ebe1ab2fb 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -38,7 +38,6 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; -using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Tests.Common; using Umbraco.Tests.Common.Builders; @@ -177,7 +176,7 @@ namespace Umbraco.Tests.Testing var globalSettings = new GlobalSettingsBuilder().Build(); var settings = new WebRoutingSettings(); - IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, Microsoft.Extensions.Options.Options.Create(settings)); + IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, logger, Microsoft.Extensions.Options.Options.Create(settings)); IIpResolver ipResolver = new AspNetIpResolver(); UmbracoVersion = new UmbracoVersion(); @@ -562,7 +561,6 @@ namespace Umbraco.Tests.Testing // reset all other static things that should not be static ;( UriUtility.ResetAppDomainAppVirtualPath(HostingEnvironment); - TestHelpers.SettingsForTests.Reset(); // FIXME: should it be optional? // clear static events DocumentRepository.ClearScopeEvents(); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index c210cb2ffa..bad75ba05c 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -391,7 +391,6 @@ - diff --git a/src/Umbraco.Tests/Web/Mvc/RenderNoContentControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderNoContentControllerTests.cs index d33ce3bfcc..3f66dcb86c 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderNoContentControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderNoContentControllerTests.cs @@ -2,6 +2,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Tests.Common; using Umbraco.Web; @@ -20,8 +21,7 @@ namespace Umbraco.Tests.Web.Mvc var mockUmbracoContext = new Mock(); mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true); var mockIOHelper = new Mock(); - var mockGlobalSettings = new Mock(); - var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, mockGlobalSettings.Object); + var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, new GlobalSettings()); var result = controller.Index() as RedirectResult; @@ -39,10 +39,12 @@ namespace Umbraco.Tests.Web.Mvc mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(false); var mockIOHelper = new Mock(); mockIOHelper.Setup(x => x.ResolveUrl(It.Is(y => y == UmbracoPathSetting))).Returns(UmbracoPath); - var mockGlobalSettings = new Mock(); - mockGlobalSettings.SetupGet(x => x.UmbracoPath).Returns(UmbracoPathSetting); - mockGlobalSettings.SetupGet(x => x.NoNodesViewPath).Returns(ViewPath); - var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, mockGlobalSettings.Object); + var globalSettings = new GlobalSettings() + { + UmbracoPath = UmbracoPathSetting, + NoNodesViewPath = ViewPath, + }; + var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, globalSettings); var result = controller.Index() as ViewResult; Assert.IsNotNull(result); diff --git a/src/Umbraco.Web.BackOffice/Controllers/IconController.cs b/src/Umbraco.Web.BackOffice/Controllers/IconController.cs index bbefa82bd9..83d6ba299d 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/IconController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/IconController.cs @@ -4,7 +4,9 @@ using Umbraco.Web.Models; using System.IO; using Umbraco.Core; using Ganss.XSS; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Common.Attributes; @@ -16,11 +18,11 @@ namespace Umbraco.Web.Editors public class IconController : UmbracoAuthorizedApiController { private readonly IHostingEnvironment _hostingEnvironment; - private readonly IGlobalSettings _globalSettings; + private readonly IOptions _globalSettings; public IconController( IHostingEnvironment hostingEnvironment, - IGlobalSettings globalSettings) + IOptions globalSettings) { _hostingEnvironment = hostingEnvironment; _globalSettings = globalSettings; @@ -37,7 +39,7 @@ namespace Umbraco.Web.Editors return string.IsNullOrWhiteSpace(iconName) ? null : CreateIconModel(iconName.StripFileExtension(), - _hostingEnvironment.MapPathWebRoot($"{_globalSettings.IconsPath}/{iconName}.svg")); + _hostingEnvironment.MapPathWebRoot($"{_globalSettings.Value.IconsPath}/{iconName}.svg")); } /// @@ -60,7 +62,7 @@ namespace Umbraco.Web.Editors public List GetAllIcons() { var icons = new List(); - var directory = new DirectoryInfo(_hostingEnvironment.MapPathWebRoot($"{_globalSettings.IconsPath}/")); + var directory = new DirectoryInfo(_hostingEnvironment.MapPathWebRoot($"{_globalSettings.Value.IconsPath}/")); var iconNames = directory.GetFiles("*.svg"); iconNames.OrderBy(f => f.Name).ToList().ForEach(iconInfo => diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index 499ebbd929..f4766bc414 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -3,8 +3,8 @@ using Microsoft.AspNet.SignalR; using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Logging; namespace Umbraco.Web @@ -45,9 +45,9 @@ namespace Umbraco.Web /// The app builder. /// /// - public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public static IAppBuilder UseSignalR(this IAppBuilder app, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - var umbracoPath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings).GetUmbracoMvcArea(hostingEnvironment); + var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true }); } diff --git a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs index 8992813b73..515824dc77 100644 --- a/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs +++ b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs @@ -11,12 +11,12 @@ namespace Umbraco.Web { public class AspNetBackOfficeInfo : IBackOfficeInfo { - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; private readonly WebRoutingSettings _webRoutingSettings; - public AspNetBackOfficeInfo(IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IOptions webRoutingSettings) + public AspNetBackOfficeInfo(GlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IOptions webRoutingSettings) { _globalSettings = globalSettings; _ioHelper = ioHelper; diff --git a/src/Umbraco.Web/Compose/AuditEventsComponent.cs b/src/Umbraco.Web/Compose/AuditEventsComponent.cs index d3667ef93c..4b5669a33f 100644 --- a/src/Umbraco.Web/Compose/AuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/AuditEventsComponent.cs @@ -3,14 +3,14 @@ using System.Linq; using System.Text; using System.Threading; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Extensions; -using Umbraco.Infrastructure.Configuration; + using Umbraco.Net; namespace Umbraco.Core.Compose @@ -21,9 +21,9 @@ namespace Umbraco.Core.Compose private readonly IUserService _userService; private readonly IEntityService _entityService; private readonly IIpResolver _ipResolver; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public AuditEventsComponent(IAuditService auditService, IUserService userService, IEntityService entityService, IIpResolver ipResolver, IGlobalSettings globalSettings) + public AuditEventsComponent(IAuditService auditService, IUserService userService, IEntityService entityService, IIpResolver ipResolver, GlobalSettings globalSettings) { _auditService = auditService; _userService = userService; @@ -62,7 +62,7 @@ namespace Umbraco.Core.Compose MemberService.Exported -= OnMemberExported; } - public static IUser UnknownUser(IGlobalSettings globalSettings) => new User(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; + public static IUser UnknownUser(GlobalSettings globalSettings) => new User(globalSettings) { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; private IUser CurrentPerformingUser { diff --git a/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs b/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs index e4f9679f4c..bfb80924d1 100644 --- a/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs +++ b/src/Umbraco.Web/Compose/BackOfficeUserAuditEventsComponent.cs @@ -3,6 +3,7 @@ using Umbraco.Core; using Umbraco.Core.Compose; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Web.Security; @@ -13,9 +14,9 @@ namespace Umbraco.Web.Compose { private readonly IAuditService _auditService; private readonly IUserService _userService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public BackOfficeUserAuditEventsComponent(IAuditService auditService, IUserService userService, IGlobalSettings globalSettings) + public BackOfficeUserAuditEventsComponent(IAuditService auditService, IUserService userService, GlobalSettings globalSettings) { _auditService = auditService; _userService = userService; diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index f325ae82da..1cf5efb69e 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -55,7 +55,7 @@ namespace Umbraco.Web.Editors public AuthenticationController( IUserPasswordConfiguration passwordConfiguration, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 95480f6632..26ca83413f 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -16,10 +16,8 @@ using Umbraco.Core.Services; using Umbraco.Web.Features; using Umbraco.Web.Security; using Constants = Umbraco.Core.Constants; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using BackOfficeIdentityUser = Umbraco.Core.BackOffice.BackOfficeIdentityUser; -using Umbraco.Infrastructure.Configuration; namespace Umbraco.Web.Editors { diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index af67cd4288..7b2cc04652 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -9,10 +9,8 @@ using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.WebAssets; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Features; using Umbraco.Web.Mvc; using Umbraco.Web.Security; @@ -29,7 +27,7 @@ namespace Umbraco.Web.Editors private readonly UrlHelper _urlHelper; private readonly IRuntimeState _runtimeState; private readonly UmbracoFeatures _features; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; private readonly ContentSettings _contentSettings; private readonly TreeCollection _treeCollection; @@ -43,7 +41,7 @@ namespace Umbraco.Web.Editors UrlHelper urlHelper, IRuntimeState runtimeState, UmbracoFeatures features, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IOptions contentSettings, TreeCollection treeCollection, @@ -144,7 +142,7 @@ namespace Umbraco.Web.Editors { "umbracoSettings", new Dictionary { - {"umbracoPath", ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}, + {"umbracoPath", _globalSettings.GetBackOfficePath(_hostingEnvironment)}, {"mediaPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath).TrimEnd('/')}, {"appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd('/')}, { @@ -168,8 +166,8 @@ namespace Umbraco.Web.Editors {"cssPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoCssPath).TrimEnd('/')}, {"allowPasswordReset", _securitySettings.AllowPasswordReset}, {"loginBackgroundImage", _contentSettings.LoginBackgroundImage}, - {"showUserInvite", EmailSender.CanSendRequiredEmail(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings))}, - {"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings))}, + {"showUserInvite", EmailSender.CanSendRequiredEmail(globalSettings)}, + {"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(globalSettings)}, {"showAllowSegmentationForDocumentTypes", false}, } }, diff --git a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs index 64aba378f4..4cd5a76fa4 100644 --- a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs +++ b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs @@ -1,7 +1,9 @@ using System; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -31,7 +33,7 @@ namespace Umbraco.Web.Editors } protected UmbracoAuthorizedJsonController( - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index b94cb655c8..eccbe073cb 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -61,7 +61,7 @@ namespace Umbraco.Web /// /// See: http://issues.umbraco.org/issue/U4-1614 /// - public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IIOHelper ioHelper, ContentSettings contentSettings) + public static MvcHtmlString PreviewBadge(this HtmlHelper helper, IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings, IIOHelper ioHelper, ContentSettings contentSettings) { if (Current.UmbracoContext.InPreviewMode) { diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 6d177651dc..e25ab4a69e 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -8,7 +8,6 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index bbb2078b10..eeb48c3b38 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -2,7 +2,6 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Editors; namespace Umbraco.Web.Mvc diff --git a/src/Umbraco.Web/Mvc/RenderNoContentController.cs b/src/Umbraco.Web/Mvc/RenderNoContentController.cs index 9334591fbb..52ee7cf44d 100644 --- a/src/Umbraco.Web/Mvc/RenderNoContentController.cs +++ b/src/Umbraco.Web/Mvc/RenderNoContentController.cs @@ -1,6 +1,7 @@ using System; using System.Web.Mvc; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Web.Models; @@ -10,9 +11,9 @@ namespace Umbraco.Web.Mvc { private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IIOHelper _ioHelper; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IGlobalSettings globalSettings) + public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, GlobalSettings globalSettings) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index ee3596b7a5..64a9e56014 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -3,7 +3,7 @@ using System.Web; using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Infrastructure.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Composing; using Umbraco.Web.Security; @@ -56,7 +56,7 @@ namespace Umbraco.Web.Mvc { if (redirectToUmbracoLogin) { - _redirectUrl = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(/*Current.Configs.Global()*/ null).GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); + _redirectUrl = new GlobalSettings().GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~"); } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index 15261a2d6f..9108dd820e 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -11,7 +11,6 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Strings; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; using Constants = Umbraco.Core.Constants; diff --git a/src/Umbraco.Web/Security/AppBuilderExtensions.cs b/src/Umbraco.Web/Security/AppBuilderExtensions.cs index 562c46d5e1..e51b68ef54 100644 --- a/src/Umbraco.Web/Security/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/Security/AppBuilderExtensions.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Security /// /// By default this will be configured to execute on PipelineStage.Authenticate /// - public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache) + public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache) { return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, hostingEnvironment, requestCache, PipelineStage.Authenticate); } @@ -54,7 +54,7 @@ namespace Umbraco.Web.Security /// public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, - IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage) + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage) { if (app == null) throw new ArgumentNullException(nameof(app)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState)); diff --git a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs index 4daf695912..6ce61c90d6 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs @@ -21,11 +21,11 @@ namespace Umbraco.Web.Security { private readonly IUserService _userService; private readonly IRuntimeState _runtimeState; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly SecuritySettings _securitySettings; - public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IOptions securitySettings) + public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IOptions securitySettings) { _userService = userService; _runtimeState = runtimeState; diff --git a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs index 51b5947a99..65d7836d42 100644 --- a/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeOwinUserManager.cs @@ -8,10 +8,10 @@ using Microsoft.Owin.Security.DataProtection; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Security; using Umbraco.Core.Services; -using Umbraco.Infrastructure.Configuration; using Umbraco.Net; namespace Umbraco.Web.Security @@ -21,7 +21,7 @@ namespace Umbraco.Web.Security public const string OwinMarkerKey = "Umbraco.Web.Security.Identity.BackOfficeUserManagerMarker"; public BackOfficeOwinUserManager( - IUserPasswordConfiguration passwordConfiguration, + IOptions passwordConfiguration, IIpResolver ipResolver, IUserStore store, IOptions optionsAccessor, @@ -31,9 +31,9 @@ namespace Umbraco.Web.Security BackOfficeIdentityErrorDescriber errors, IDataProtectionProvider dataProtectionProvider, ILogger> logger) - : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, Microsoft.Extensions.Options.Options.Create(ConfigModelConversionsFromLegacy.ConvertUserPasswordConfiguration(passwordConfiguration))) + : base(ipResolver, store, optionsAccessor, null, userValidators, passwordValidators, keyNormalizer, errors, null, logger, passwordConfiguration) { - PasswordConfiguration = passwordConfiguration; + PasswordConfiguration = passwordConfiguration.Value; InitUserManager(this, dataProtectionProvider); } @@ -46,15 +46,15 @@ namespace Umbraco.Web.Security IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, - IGlobalSettings globalSettings, + IOptions globalSettings, UmbracoMapper mapper, - IUserPasswordConfiguration passwordConfiguration, + IOptions passwordConfiguration, IIpResolver ipResolver, BackOfficeIdentityErrorDescriber errors, IDataProtectionProvider dataProtectionProvider, ILogger> logger) { - var store = new BackOfficeUserStore(userService, entityService, externalLoginService, Microsoft.Extensions.Options.Options.Create(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)), mapper); + var store = new BackOfficeUserStore(userService, entityService, externalLoginService, globalSettings, mapper); return Create( passwordConfiguration, @@ -69,7 +69,7 @@ namespace Umbraco.Web.Security /// Creates a BackOfficeUserManager instance with all default options and a custom BackOfficeUserManager instance /// public static BackOfficeOwinUserManager Create( - IUserPasswordConfiguration passwordConfiguration, + IOptions passwordConfiguration, IIpResolver ipResolver, IUserStore customUserStore, BackOfficeIdentityErrorDescriber errors, @@ -84,11 +84,11 @@ namespace Umbraco.Web.Security // Configure validation logic for passwords var passwordValidators = new List> { new PasswordValidator() }; - options.Password.RequiredLength = passwordConfiguration.RequiredLength; - options.Password.RequireNonAlphanumeric = passwordConfiguration.RequireNonLetterOrDigit; - options.Password.RequireDigit = passwordConfiguration.RequireDigit; - options.Password.RequireLowercase = passwordConfiguration.RequireLowercase; - options.Password.RequireUppercase = passwordConfiguration.RequireUppercase; + options.Password.RequiredLength = passwordConfiguration.Value.RequiredLength; + options.Password.RequireNonAlphanumeric = passwordConfiguration.Value.RequireNonLetterOrDigit; + options.Password.RequireDigit = passwordConfiguration.Value.RequireDigit; + options.Password.RequireLowercase = passwordConfiguration.Value.RequireLowercase; + options.Password.RequireUppercase = passwordConfiguration.Value.RequireUppercase; // Ensure Umbraco security stamp claim type is used options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier; @@ -97,7 +97,7 @@ namespace Umbraco.Web.Security options.ClaimsIdentity.SecurityStampClaimType = Constants.Security.SecurityStampClaimType; options.Lockout.AllowedForNewUsers = true; - options.Lockout.MaxFailedAccessAttempts = passwordConfiguration.MaxFailedAccessAttemptsBeforeLockout; + options.Lockout.MaxFailedAccessAttempts = passwordConfiguration.Value.MaxFailedAccessAttemptsBeforeLockout; //NOTE: This just needs to be in the future, we currently don't support a lockout timespan, it's either they are locked // or they are not locked, but this determines what is set on the account lockout date which corresponds to whether they are // locked out or not. diff --git a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs index fe90db9ec7..0dc86f7b1b 100644 --- a/src/Umbraco.Web/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeSignInManager.cs @@ -9,8 +9,7 @@ using Microsoft.Owin.Logging; using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.BackOffice; -using Umbraco.Core.Configuration; -using Umbraco.Infrastructure.Configuration; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.Security { @@ -25,7 +24,7 @@ namespace Umbraco.Web.Security private readonly IUserClaimsPrincipalFactory _claimsPrincipalFactory; private readonly IAuthenticationManager _authenticationManager; private readonly ILogger _logger; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IOwinRequest _request; public BackOfficeSignInManager( @@ -33,7 +32,7 @@ namespace Umbraco.Web.Security IUserClaimsPrincipalFactory claimsPrincipalFactory, IAuthenticationManager authenticationManager, ILogger logger, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IOwinRequest request) { _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); @@ -52,7 +51,7 @@ namespace Umbraco.Web.Security return claimsPrincipal.Identity as ClaimsIdentity; } - public static BackOfficeSignInManager Create(IOwinContext context, IGlobalSettings globalSettings, ILogger logger) + public static BackOfficeSignInManager Create(IOwinContext context, GlobalSettings globalSettings, ILogger logger) { var userManager = context.GetBackOfficeUserManager(); @@ -78,7 +77,7 @@ namespace Umbraco.Web.Security var user = await _userManager.FindByNameAsync(userName); //if the user is null, create an empty one which can be used for auto-linking - if (user == null) user = BackOfficeIdentityUser.CreateNew(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings), userName, null, _globalSettings.DefaultUILanguage); + if (user == null) user = BackOfficeIdentityUser.CreateNew(_globalSettings, userName, null, _globalSettings.DefaultUILanguage); //check the password for the user, this will allow a developer to auto-link //an account if they have specified an IBackOfficeUserPasswordChecker @@ -248,7 +247,7 @@ namespace Umbraco.Web.Security } return null; } - + /// /// Two factor verification step /// diff --git a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs index 83b6843a39..62724a4846 100644 --- a/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs +++ b/src/Umbraco.Web/Security/GetUserSecondsMiddleWare.cs @@ -9,9 +9,7 @@ using Microsoft.Owin.Logging; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; -using Umbraco.Infrastructure.Configuration; namespace Umbraco.Web.Security { @@ -26,7 +24,7 @@ namespace Umbraco.Web.Security internal class GetUserSecondsMiddleWare : OwinMiddleware { private readonly UmbracoBackOfficeCookieAuthOptions _authOptions; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly SecuritySettings _security; private readonly ILogger _logger; private readonly IHostingEnvironment _hostingEnvironment; @@ -34,7 +32,7 @@ namespace Umbraco.Web.Security public GetUserSecondsMiddleWare( OwinMiddleware next, UmbracoBackOfficeCookieAuthOptions authOptions, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IOptions security, ILogger logger, IHostingEnvironment hostingEnvironment) @@ -54,7 +52,7 @@ namespace Umbraco.Web.Security if (request.Uri.Scheme.InvariantStartsWith("http") && request.Uri.AbsolutePath.InvariantEquals( - $"{ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) + $"{_globalSettings.GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds")) { var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName); if (cookie.IsNullOrWhiteSpace() == false) diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 93167b76e0..3bf1b6be12 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -10,15 +10,12 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Logging.Serilog.Enrichers; -using Umbraco.Infrastructure.Configuration; using Umbraco.Net; using Umbraco.Web.Hosting; using Umbraco.Web.Logging; @@ -46,7 +43,7 @@ namespace Umbraco.Web //var configFactory = new ConfigsFactory(); HostingSettings hostingSettings = null; - IGlobalSettings globalSettings = null; + GlobalSettings globalSettings = null; SecuritySettings securitySettings = null; WebRoutingSettings webRoutingSettings = null; @@ -62,7 +59,7 @@ namespace Umbraco.Web var profiler = GetWebProfiler(hostingEnvironment); Umbraco.Composing.Current.Initialize(logger, securitySettings, - ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings), + globalSettings, ioHelper, hostingEnvironment, backOfficeInfo, profiler); Logger = logger; } diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 563435e9f9..bda836c847 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -1,11 +1,9 @@ using System; using System.Web; using Umbraco.Core; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index 79ec56cfd3..edd429946f 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web public class UmbracoDefaultOwinStartup { protected IUmbracoContextAccessor UmbracoContextAccessor => Current.UmbracoContextAccessor; - protected IGlobalSettings GlobalSettings => Current.Factory.GetInstance(); + protected GlobalSettings GlobalSettings => Current.Factory.GetInstance(); protected SecuritySettings SecuritySettings => Current.Factory.GetInstance>().Value; protected IUserPasswordConfiguration UserPasswordConfig => Current.Factory.GetInstance(); protected IRuntimeState RuntimeState => Current.RuntimeState; diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index 3bd627be71..06b8953338 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -4,11 +4,11 @@ using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Exceptions; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Security; -using Umbraco.Infrastructure.Configuration; using Umbraco.Web.Composing; using Umbraco.Web.Routing; @@ -37,7 +37,7 @@ namespace Umbraco.Web private readonly IUmbracoContextFactory _umbracoContextFactory; private readonly RoutableDocumentFilter _routableDocumentLookup; private readonly IRequestCache _requestCache; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; private readonly UriUtility _uriUtility; @@ -49,7 +49,7 @@ namespace Umbraco.Web RoutableDocumentFilter routableDocumentLookup, UriUtility uriUtility, IRequestCache requestCache, - IGlobalSettings globalSettings, + GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { _runtime = runtime; @@ -111,7 +111,7 @@ namespace Umbraco.Web var umbracoContext = Current.UmbracoContext; // re-write for the default back office path - if (httpContext.Request.Url.IsDefaultBackOfficeRequest(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings), _hostingEnvironment)) + if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_globalSettings, _hostingEnvironment)) { if (EnsureRuntime(httpContext, umbracoContext.OriginalRequestUrl)) RewriteToBackOfficeHandler(httpContext); @@ -244,7 +244,7 @@ namespace Umbraco.Web private void RewriteToBackOfficeHandler(HttpContextBase context) { // GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any) - var rewritePath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default"; + var rewritePath = _globalSettings.GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default"; // rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc) context.RewritePath(rewritePath, "", "", false); @@ -277,7 +277,7 @@ namespace Umbraco.Web var query = pcr.Uri.Query.TrimStart('?'); // GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any) - var rewritePath = ConfigModelConversionsFromLegacy.ConvertGlobalSettings(_globalSettings).GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc"; + var rewritePath = _globalSettings.GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc"; // rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc) context.RewritePath(rewritePath, "", query, false); @@ -295,7 +295,7 @@ namespace Umbraco.Web } - + #endregion #region IHttpModule diff --git a/src/Umbraco.Web/UmbracoWebService.cs b/src/Umbraco.Web/UmbracoWebService.cs index b8d69f5b62..a0d12cba93 100644 --- a/src/Umbraco.Web/UmbracoWebService.cs +++ b/src/Umbraco.Web/UmbracoWebService.cs @@ -1,14 +1,7 @@ -using System; -using System.Web; -using System.Web.Mvc; -using System.Web.Routing; +using System.Web.Mvc; using System.Web.Services; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Legacy; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; -using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.Security; @@ -22,7 +15,7 @@ namespace Umbraco.Web { private UrlHelper _url; - protected UmbracoWebService(IProfilingLogger profilingLogger, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, IGlobalSettings globalSettings) + protected UmbracoWebService(IProfilingLogger profilingLogger, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, GlobalSettings globalSettings) { Logger = profilingLogger; ProfilingLogger = profilingLogger; @@ -64,7 +57,7 @@ namespace Umbraco.Web /// /// Gets the global settings. /// - public IGlobalSettings GlobalSettings { get; } + public GlobalSettings GlobalSettings { get; } /// /// Gets the web security helper. diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index a832b4e823..724ea810c9 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -3,6 +3,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -20,7 +21,7 @@ namespace Umbraco.Web.WebApi { } - protected UmbracoApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoApiController(GlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs index d009528bc7..7c15775f7b 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Web.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; @@ -38,7 +39,7 @@ namespace Umbraco.Web.WebApi /// Dependencies are obtained from the service locator. protected UmbracoApiControllerBase() : this( - Current.Factory.GetInstance(), + Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), Current.Factory.GetInstance(), @@ -53,10 +54,9 @@ namespace Umbraco.Web.WebApi /// /// Initializes a new instance of the class with all its dependencies. /// - protected UmbracoApiControllerBase(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoApiControllerBase(GlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) { UmbracoContextAccessor = umbracoContextAccessor; - GlobalSettings = globalSettings; SqlContext = sqlContext; Services = services; AppCaches = appCaches; @@ -72,11 +72,6 @@ namespace Umbraco.Web.WebApi /// For debugging purposes. internal Guid InstanceId { get; } = Guid.NewGuid(); - /// - /// Gets the Umbraco context. - /// - public virtual IGlobalSettings GlobalSettings { get; } - /// /// Gets the Umbraco context. /// diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 015cb3c6bc..7858d6955a 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -1,6 +1,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Web.WebApi.Filters; using Umbraco.Core.Persistence; @@ -35,7 +36,7 @@ namespace Umbraco.Web.WebApi { } - protected UmbracoAuthorizedApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) + protected UmbracoAuthorizedApiController(GlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { } diff --git a/src/Umbraco.Web/WebAssets/CDF/UmbracoClientDependencyLoader.cs b/src/Umbraco.Web/WebAssets/CDF/UmbracoClientDependencyLoader.cs index a89cf8f908..a0704140f1 100644 --- a/src/Umbraco.Web/WebAssets/CDF/UmbracoClientDependencyLoader.cs +++ b/src/Umbraco.Web/WebAssets/CDF/UmbracoClientDependencyLoader.cs @@ -2,6 +2,7 @@ using ClientDependency.Core.Controls; using ClientDependency.Core.FileRegistration.Providers; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; namespace Umbraco.Web.WebAssets.CDF @@ -15,7 +16,7 @@ namespace Umbraco.Web.WebAssets.CDF /// /// Set the defaults /// - public UmbracoClientDependencyLoader(IGlobalSettings globalSettings, IIOHelper ioHelper) + public UmbracoClientDependencyLoader(GlobalSettings globalSettings, IIOHelper ioHelper) : base() { this.AddPath("UmbracoRoot", ioHelper.ResolveUrl(globalSettings.UmbracoPath)); @@ -23,7 +24,7 @@ namespace Umbraco.Web.WebAssets.CDF } - public static ClientDependencyLoader TryCreate(Control parent, out bool isNew, IGlobalSettings globalSettings, IIOHelper ioHelper) + public static ClientDependencyLoader TryCreate(Control parent, out bool isNew, GlobalSettings globalSettings, IIOHelper ioHelper) { if (ClientDependencyLoader.Instance == null) { From 1599e741938dffa47987aa77b8f4aaac4d75adbe Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 14:15:09 +0200 Subject: [PATCH 46/58] Removed Umbraco.Configuration project --- build/NuSpecs/UmbracoCms.Core.nuspec | 3 --- src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj | 1 - src/Umbraco.Tests/Umbraco.Tests.csproj | 4 ---- src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj | 1 - src/Umbraco.Web.Common/Umbraco.Web.Common.csproj | 3 +-- src/Umbraco.Web/Umbraco.Web.csproj | 4 ---- src/umbraco.sln | 6 ------ 7 files changed, 1 insertion(+), 21 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Core.nuspec b/build/NuSpecs/UmbracoCms.Core.nuspec index 477bb143f9..ce8f3aae44 100644 --- a/build/NuSpecs/UmbracoCms.Core.nuspec +++ b/build/NuSpecs/UmbracoCms.Core.nuspec @@ -71,7 +71,6 @@ - @@ -79,7 +78,6 @@ - @@ -87,7 +85,6 @@ - diff --git a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj index 68d3f23ac4..0f5ed6b28f 100644 --- a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj +++ b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index bad75ba05c..8c0c26d477 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -456,10 +456,6 @@ - - {fbe7c065-dac0-4025-a78b-63b24d3ab00b} - Umbraco.Configuration - {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Core diff --git a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj index 1c66edc2ce..cd7824cd52 100644 --- a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj +++ b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj @@ -31,7 +31,6 @@ - diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj index ee657e82bb..3865a7fdad 100644 --- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj +++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj @@ -15,7 +15,6 @@ - @@ -36,5 +35,5 @@ <_Parameter1>Umbraco.Tests.UnitTests - + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 8484147878..c2d36285e6 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -110,10 +110,6 @@ - - {fbe7c065-dac0-4025-a78b-63b24d3ab00b} - Umbraco.Configuration - {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Core diff --git a/src/umbraco.sln b/src/umbraco.sln index b2922abf3e..6216b3128b 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -137,8 +137,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.ModelsBuilder.Embed EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Infrastructure", "Umbraco.Infrastructure\Umbraco.Infrastructure.csproj", "{3AE7BF57-966B-45A5-910A-954D7C554441}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Configuration", "Umbraco.Configuration\Umbraco.Configuration.csproj", "{FBE7C065-DAC0-4025-A78B-63B24D3AB00B}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Persistance.SqlCe", "Umbraco.Persistance.SqlCe\Umbraco.Persistance.SqlCe.csproj", "{33085570-9BF2-4065-A9B0-A29D920D13BA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.TestData", "Umbraco.TestData\Umbraco.TestData.csproj", "{FB5676ED-7A69-492C-B802-E7B24144C0FC}" @@ -199,10 +197,6 @@ Global {3AE7BF57-966B-45A5-910A-954D7C554441}.Debug|Any CPU.Build.0 = Debug|Any CPU {3AE7BF57-966B-45A5-910A-954D7C554441}.Release|Any CPU.ActiveCfg = Release|Any CPU {3AE7BF57-966B-45A5-910A-954D7C554441}.Release|Any CPU.Build.0 = Release|Any CPU - {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Release|Any CPU.Build.0 = Release|Any CPU {33085570-9BF2-4065-A9B0-A29D920D13BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {33085570-9BF2-4065-A9B0-A29D920D13BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {33085570-9BF2-4065-A9B0-A29D920D13BA}.Release|Any CPU.ActiveCfg = Release|Any CPU From 8141e7c6c8c4775c7b6afb05c73dcf4ea378a7c4 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 14:35:57 +0200 Subject: [PATCH 47/58] Bugfix --- .../BackOffice/ContentTypeModelValidator.cs | 4 ++-- .../BackOffice/ContentTypeModelValidatorBase.cs | 7 ++++--- .../BackOffice/MediaTypeModelValidator.cs | 5 +++-- .../BackOffice/MemberTypeModelValidator.cs | 5 +++-- .../Controllers/ContentTypeController.cs | 4 ++-- src/Umbraco.Web.UI.NetCore/appsettings.json | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs index af2a2a04cd..5f806883f0 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidator.cs @@ -1,4 +1,4 @@ -using Umbraco.Core.Configuration; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; @@ -11,7 +11,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class ContentTypeModelValidator : ContentTypeModelValidatorBase { - public ContentTypeModelValidator(ModelsBuilderConfig config) : base(config) + public ContentTypeModelValidator(IOptions config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs index 02ac9e42eb..c1684dde7a 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.PublishedContent; @@ -13,9 +14,9 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice where TModel : ContentTypeSave where TProperty : PropertyTypeBasic { - private readonly ModelsBuilderConfig _config; + private readonly IOptions _config; - public ContentTypeModelValidatorBase(ModelsBuilderConfig config) + public ContentTypeModelValidatorBase(IOptions config) { _config = config; } @@ -23,7 +24,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice protected override IEnumerable Validate(TModel model) { //don't do anything if we're not enabled - if (!_config.Enable) yield break; + if (!_config.Value.Enable) yield break; var properties = model.Groups.SelectMany(x => x.Properties) .Where(x => x.Inherited == false) diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs index 5e29a888a0..b6cc135e7c 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MediaTypeModelValidator.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +11,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class MediaTypeModelValidator : ContentTypeModelValidatorBase { - public MediaTypeModelValidator(ModelsBuilderConfig config) : base(config) + public MediaTypeModelValidator(IOptions config) : base(config) { } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs index 970259d06b..c930642155 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/BackOffice/MemberTypeModelValidator.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.ModelsBuilder.Embedded.BackOffice @@ -10,7 +11,7 @@ namespace Umbraco.ModelsBuilder.Embedded.BackOffice // ReSharper disable once UnusedMember.Global - This is typed scanned public class MemberTypeModelValidator : ContentTypeModelValidatorBase { - public MemberTypeModelValidator(ModelsBuilderConfig config) : base(config) + public MemberTypeModelValidator(IOptions config) : base(config) { } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index d62b6ecd73..4f7260a35c 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -71,7 +71,6 @@ namespace Umbraco.Web.BackOffice.Controllers public ContentTypeController( ICultureDictionary cultureDictionary, - EditorValidatorCollection editorValidatorCollection, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, @@ -92,7 +91,8 @@ namespace Umbraco.Web.BackOffice.Controllers ILocalizationService localizationService, IMacroService macroService, IEntityService entityService, - IHostingEnvironment hostingEnvironment) + IHostingEnvironment hostingEnvironment, + EditorValidatorCollection editorValidatorCollection) : base(cultureDictionary, editorValidatorCollection, contentTypeService, diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 3bbb4e7da4..f28d3bca6c 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "umbracoDbDSN": "" + "umbracoDbDSN": "Server=(LocalDB)\\Umbraco;Database=NetCore;Integrated Security=true" }, "Umbraco": { "CMS": { @@ -61,4 +61,4 @@ } } } -} +} \ No newline at end of file From dc8933b6b975ecff18ff1a6718b627e2f53ae1fc Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 15:05:32 +0200 Subject: [PATCH 48/58] Removed test code --- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index e1a969e668..ae930613dd 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -149,11 +149,6 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); - //services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); - services.Configure(settings => - { - settings.EnableTours = false; - }); return services; } From ce2da183041412e0802c6576f6b1def332b16973 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 21:27:31 +0200 Subject: [PATCH 49/58] Fixed based on review comments Signed-off-by: Bjarke Berg --- .../HealthChecks/DisabledHealthCheck.cs | 11 +++ .../HealthChecks/IDisabledHealthCheck.cs | 11 --- .../Configuration/Models/ConnectionStrings.cs | 22 +++-- .../Configuration/Models/ContentErrorPage.cs | 15 ++++ .../Configuration/Models/ContentSettings.cs | 42 +-------- .../Models/HealthChecksSettings.cs | 86 +------------------ .../Models/ImagingCacheSettings.cs | 6 +- .../UmbracoSettings/IContentErrorPage.cs | 14 --- .../HealthCheck/HealthCheckResults.cs | 2 +- .../Routing/NotFoundHandlerHelper.cs | 7 +- .../UmbracoAuthorizedApiController.cs | 2 +- src/Umbraco.Web.UI.NetCore/appsettings.json | 4 +- .../Mvc/UmbracoViewPageOfTModel.cs | 2 + src/Umbraco.Web/PublishedContentExtensions.cs | 4 +- 14 files changed, 60 insertions(+), 168 deletions(-) create mode 100644 src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheck.cs delete mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs create mode 100644 src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs delete mode 100644 src/Umbraco.Core/Configuration/UmbracoSettings/IContentErrorPage.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheck.cs b/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheck.cs new file mode 100644 index 0000000000..c962014bd5 --- /dev/null +++ b/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheck.cs @@ -0,0 +1,11 @@ +using System; + +namespace Umbraco.Core.Configuration.HealthChecks +{ + public class DisabledHealthCheck + { + public Guid Id { get; set; } + public DateTime DisabledOn { get; set; } + public int DisabledBy { get; set; } + } +} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs b/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs deleted file mode 100644 index 4ea63048f8..0000000000 --- a/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Umbraco.Core.Configuration.HealthChecks -{ - public interface IDisabledHealthCheck - { - Guid Id { get; } - DateTime DisabledOn { get; } - int DisabledBy { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index 056611a0ed..db7be894db 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -6,6 +6,8 @@ namespace Umbraco.Core.Configuration.Models { public class ConnectionStrings { + + // Backing field for UmbracoConnectionString to load from configuration value with key umbracoDbDSN. // Attributes cannot be applied to map from keys that don't match, and have chosen to retain the key name // used in configuration for older Umbraco versions. @@ -13,21 +15,27 @@ namespace Umbraco.Core.Configuration.Models private string umbracoDbDSN { get => string.Empty; - set => UmbracoConnectionString = value; + set + { + UmbracoConnectionString = value; + + ConnectionStringDictionary[Constants.System.UmbracoConnectionName] = value; + } } - public string UmbracoConnectionString { get; set; } + public string UmbracoConnectionString + { + get => ConnectionStringDictionary[Constants.System.UmbracoConnectionName]; + set => ConnectionStringDictionary[Constants.System.UmbracoConnectionName] = value; + } - private Dictionary AsDictionary() => new Dictionary - { - { Constants.System.UmbracoConnectionName, UmbracoConnectionString } - }; + private Dictionary ConnectionStringDictionary { get; } = new Dictionary(); public ConfigConnectionString this[string key] { get { - var connectionString = this.AsDictionary()[key]; + var connectionString = ConnectionStringDictionary[key]; var provider = ParseProvider(connectionString); return new ConfigConnectionString(connectionString, provider, key); } diff --git a/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs b/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs new file mode 100644 index 0000000000..e04362eafd --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs @@ -0,0 +1,15 @@ +using System; + +namespace Umbraco.Core.Configuration.Models +{ + public class ContentErrorPage + { + //TODO introduce valiation, to check only one of key/id/xPath is used. + public int ContentId { get; } + public Guid ContentKey { get; } + public string ContentXPath { get; } + public bool HasContentId { get; } + public bool HasContentKey { get; } + public string Culture { get; set; } + } +} diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index 31a97e6615..5158a5c746 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -16,15 +16,7 @@ namespace Umbraco.Core.Configuration.Models public bool ResolveUrlsFromTextString { get; set; } = false; - // TODO: to retain previous configuration structure, this should come from a nested collection, - // "Errors:Error404". Although we can use JsonPropertyName to map when the JSON field name differs - // from the one in this class, not sure how we'd "flatten" a collection like this. - public IEnumerable Error404Collection { get; set; } - - // public IEnumerable Error404Collection => _configuration - // .GetSection(Prefix + "Errors:Error404") - // .GetChildren() - // .Select(x => new ContentErrorPage(x)); + public IEnumerable Error404Collection { get; set; } = Array.Empty(); public string PreviewBadge { get; set; } = DefaultPreviewBadge; @@ -38,38 +30,6 @@ namespace Umbraco.Core.Configuration.Models public string LoginBackgroundImage { get; set; } = "assets/img/login.jpg"; - /* - private class ContentErrorPage : IContentErrorPage - { - public ContentErrorPage(IConfigurationSection configurationSection) - { - Culture = configurationSection.Key; - var value = configurationSection.Value; - - if (int.TryParse(value, out var contentId)) - { - HasContentId = true; - ContentId = contentId; - } - else if (Guid.TryParse(value, out var contentKey)) - { - HasContentKey = true; - ContentKey = contentKey; - } - else - { - ContentXPath = value; - } - } - - public int ContentId { get; } - public Guid ContentKey { get; } - public string ContentXPath { get; } - public bool HasContentId { get; } - public bool HasContentKey { get; } - public string Culture { get; set; } - } - */ } } diff --git a/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs b/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs index 37580195d6..0903a8f242 100644 --- a/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs @@ -6,37 +6,10 @@ namespace Umbraco.Core.Configuration.Models { public class HealthChecksSettings { - // TODO: implement - public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); + public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); public HealthCheckNotificationSettings NotificationSettings { get; set; } = new HealthCheckNotificationSettings(); - /* - public IEnumerable DisabledChecks => _configuration - .GetSection(Prefix+"DisabledChecks") - .GetChildren() - .Select( - x => new DisabledHealthCheck - { - Id = x.GetValue("Id"), - DisabledOn = x.GetValue("DisabledOn"), - DisabledBy = x.GetValue("DisabledBy") - }); - - public IHealthCheckNotificationSettings NotificationSettings => - new HealthCheckNotificationSettings( - _configuration.GetSection(Prefix+"NotificationSettings")); - - - private class DisabledHealthCheck : IDisabledHealthCheck - { - public Guid Id { get; set; } - public DateTime DisabledOn { get; set; } - public int DisabledBy { get; set; } - } - */ - - // TODO: move to new file public class HealthCheckNotificationSettings { public bool Enabled { get; set; } = false; @@ -45,64 +18,9 @@ namespace Umbraco.Core.Configuration.Models public int PeriodInHours { get; set; } = 24; - // TODO: implement - public IReadOnlyDictionary NotificationMethods { get; set; } = new Dictionary(); - public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); - - /* - public IReadOnlyDictionary NotificationMethods => _configurationSection - .GetSection("NotificationMethods") - .GetChildren() - .ToDictionary(x => x.Key, x => (INotificationMethod) new NotificationMethod(x.Key, x), StringComparer.InvariantCultureIgnoreCase); - - public IEnumerable DisabledChecks => _configurationSection - .GetSection("DisabledChecks").GetChildren().Select( - x => new DisabledHealthCheck - { - Id = x.GetValue("Id"), - DisabledOn = x.GetValue("DisabledOn"), - DisabledBy = x.GetValue("DisabledBy") - }); - */ + public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); } - - /* - private class NotificationMethod : INotificationMethod - { - private readonly IConfigurationSection _configurationSection; - - public NotificationMethod(string alias, IConfigurationSection configurationSection) - { - Alias = alias; - _configurationSection = configurationSection; - } - - public string Alias { get; } - public bool Enabled => _configurationSection.GetValue("Enabled", false); - - public HealthCheckNotificationVerbosity Verbosity => - _configurationSection.GetValue("Verbosity", HealthCheckNotificationVerbosity.Summary); - - public bool FailureOnly => _configurationSection.GetValue("FailureOnly", true); - - public IReadOnlyDictionary Settings => _configurationSection - .GetSection("Settings").GetChildren().ToDictionary(x => x.Key, - x => (INotificationMethodSettings) new NotificationMethodSettings(x.Key, x.Value), StringComparer.InvariantCultureIgnoreCase); - } - - private class NotificationMethodSettings : INotificationMethodSettings - { - public NotificationMethodSettings(string key, string value) - { - Key = key; - Value = value; - } - - public string Key { get; } - public string Value { get; } - } - */ } } diff --git a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs index 9ab3386129..d2395b6da9 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs @@ -1,4 +1,6 @@ -namespace Umbraco.Core.Configuration.Models +using System.IO; + +namespace Umbraco.Core.Configuration.Models { public class ImagingCacheSettings { @@ -8,6 +10,6 @@ public uint CachedNameLength { get; set; } = 8; - public string CacheFolder { get; set; } = "../App_Data/Cache"; + public string CacheFolder { get; set; } = Path.Combine("~", "Umbraco", "Cache"); } } diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IContentErrorPage.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IContentErrorPage.cs deleted file mode 100644 index 3ea00d7c74..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IContentErrorPage.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IContentErrorPage - { - int ContentId { get; } - Guid ContentKey { get; } - string ContentXPath { get; } - bool HasContentId { get; } - bool HasContentKey { get; } - string Culture { get; set; } - } -} diff --git a/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs b/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs index 0b27b34875..8f3c05f5bd 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/HealthCheckResults.cs @@ -71,7 +71,7 @@ namespace Umbraco.Web.HealthCheck foreach (var checkResult in checkResults) { - Logger.Info("'Result for {HealthCheckName}: {HealthCheckResult}, Message: '{HealthCheckMessage}'", checkName, checkResult.ResultType, checkResult.Message); + Logger.Info("Result for {HealthCheckName}: {HealthCheckResult}, Message: '{HealthCheckMessage}'", checkName, checkResult.ResultType, checkResult.Message); } } } diff --git a/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs index 335e1f868a..20fbe9a1ef 100644 --- a/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs +++ b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using Umbraco.Composing; using Umbraco.Core; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -28,7 +29,7 @@ namespace Umbraco.Web.Routing /// /// internal static int? GetCurrentNotFoundPageId( - IContentErrorPage[] error404Collection, + ContentErrorPage[] error404Collection, string requestServerName, IEntityService entityService, IPublishedContentQuery publishedContentQuery, @@ -38,7 +39,7 @@ namespace Umbraco.Web.Routing } internal static int? GetCurrentNotFoundPageId( - IContentErrorPage[] error404Collection, + ContentErrorPage[] error404Collection, IEntityService entityService, IPublishedContentQuery publishedContentQuery, CultureInfo errorCulture) @@ -67,7 +68,7 @@ namespace Umbraco.Web.Routing /// /// /// - internal static int? GetContentIdFromErrorPageConfig(IContentErrorPage errorPage, IEntityService entityService, IPublishedContentQuery publishedContentQuery) + internal static int? GetContentIdFromErrorPageConfig(ContentErrorPage errorPage, IEntityService entityService, IPublishedContentQuery publishedContentQuery) { if (errorPage.HasContentId) return errorPage.ContentId; diff --git a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs index 85c92d1139..c3e1a71b86 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.BackOffice.Controllers [UmbracoAuthorize] [DisableBrowserCache] [UmbracoWebApiRequireHttps] - [CheckIfUserTicketDataIsStale] + //[CheckIfUserTicketDataIsStale] //TODO reintroduce //[UnhandedExceptionLoggerConfiguration] //TODO reintroduce //[EnableDetailedErrors] //TODO reintroduce public abstract class UmbracoAuthorizedApiController : UmbracoApiController diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index f28d3bca6c..3bbb4e7da4 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "umbracoDbDSN": "Server=(LocalDB)\\Umbraco;Database=NetCore;Integrated Security=true" + "umbracoDbDSN": "" }, "Umbraco": { "CMS": { @@ -61,4 +61,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index 4a651fd04a..f461fb9a22 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -115,6 +115,8 @@ namespace Umbraco.Web.Mvc protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IOptions globalSettings, IOptions contentSettings) { + if (globalSettings == null) throw new ArgumentNullException(nameof(globalSettings)); + if (contentSettings == null) throw new ArgumentNullException(nameof(contentSettings)); Services = services; AppCaches = appCaches; _globalSettings = globalSettings.Value; diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index e132b8fcdd..487212840b 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web Current.Services.ContentTypeService, /*Current.Configs.WebRouting().DisableAlternativeTemplates, Current.Configs.WebRouting().ValidateAlternativeTemplates, - TODO*/ + TODO get values from config*/ false, false, templateId); } @@ -87,7 +87,7 @@ namespace Umbraco.Web Current.Services.ContentTypeService, /*Current.Configs.WebRouting().DisableAlternativeTemplates, Current.Configs.WebRouting().ValidateAlternativeTemplates, - TODO*/ + TODO get values from config*/ false, false, templateAlias); } From 4a4b57ef87b4cbcc20f44d099b709be75eb9e267 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 14 Sep 2020 21:53:56 +0200 Subject: [PATCH 50/58] bugfixes related to no umbraco connection string Signed-off-by: Bjarke Berg --- .../Configuration/Models/ConnectionStrings.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index db7be894db..eee8faa492 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -25,7 +25,11 @@ namespace Umbraco.Core.Configuration.Models public string UmbracoConnectionString { - get => ConnectionStringDictionary[Constants.System.UmbracoConnectionName]; + get + { + ConnectionStringDictionary.TryGetValue(Constants.System.UmbracoConnectionName, out var value); + return value; + } set => ConnectionStringDictionary[Constants.System.UmbracoConnectionName] = value; } @@ -35,7 +39,11 @@ namespace Umbraco.Core.Configuration.Models { get { - var connectionString = ConnectionStringDictionary[key]; + if (!ConnectionStringDictionary.TryGetValue(key, out var connectionString)) + { + return null; + } + var provider = ParseProvider(connectionString); return new ConfigConnectionString(connectionString, provider, key); } From b4353585c363b2944b8cce63626ff93273bac098 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 15 Sep 2020 09:11:36 +0200 Subject: [PATCH 51/58] Simplifyed the ConnectionStrings config --- .../Configuration/ConfigConnectionString.cs | 51 +++++++++++- .../Configuration/Models/ConnectionStrings.cs | 82 +------------------ .../Install/InstallHelper.cs | 2 +- .../InstallSteps/DatabaseConfigureStep.cs | 2 +- .../InstallSteps/DatabaseUpgradeStep.cs | 2 +- .../Install/InstallSteps/NewInstallStep.cs | 2 +- .../Persistence/UmbracoDatabaseFactory.cs | 8 +- .../Runtime/SqlMainDomLock.cs | 1 - .../Builders/ConnectionStringsBuilder.cs | 4 +- .../Umbraco.Tests.Integration.csproj | 3 + .../Models/ConnectionStringsTests.cs | 11 ++- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 1 - src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 1 - 13 files changed, 70 insertions(+), 100 deletions(-) diff --git a/src/Umbraco.Core/Configuration/ConfigConnectionString.cs b/src/Umbraco.Core/Configuration/ConfigConnectionString.cs index e9ac944b85..3a540aa3e2 100644 --- a/src/Umbraco.Core/Configuration/ConfigConnectionString.cs +++ b/src/Umbraco.Core/Configuration/ConfigConnectionString.cs @@ -1,16 +1,61 @@ +using System; +using System.Data.Common; + namespace Umbraco.Core.Configuration { public class ConfigConnectionString { - public ConfigConnectionString(string connectionString, string providerName, string name) + public ConfigConnectionString(string name, string connectionString, string providerName = null) { + Name = name ?? throw new ArgumentNullException(nameof(name)); ConnectionString = connectionString; - ProviderName = providerName; - Name = name; + + ProviderName = string.IsNullOrEmpty(providerName) ? ParseProvider(connectionString) : providerName; } public string ConnectionString { get; } public string ProviderName { get; } public string Name { get; } + + private string ParseProvider(string connectionString) + { + if (string.IsNullOrEmpty(connectionString)) + { + return null; + } + + var builder = new DbConnectionStringBuilder + { + ConnectionString = connectionString + }; + + if (builder.TryGetValue("Data Source", out var ds) && ds is string dataSource) + { + if (dataSource.EndsWith(".sdf")) + { + return Constants.DbProviderNames.SqlCe; + } + } + + if (builder.TryGetValue("Server", out var s) && s is string server && !string.IsNullOrEmpty(server)) + { + if (builder.TryGetValue("Database", out var db) && db is string database && !string.IsNullOrEmpty(database)) + { + return Constants.DbProviderNames.SqlServer; + } + + if (builder.TryGetValue("AttachDbFileName", out var a) && a is string attachDbFileName && !string.IsNullOrEmpty(attachDbFileName)) + { + return Constants.DbProviderNames.SqlServer; + } + + if (builder.TryGetValue("Initial Catalog", out var i) && i is string initialCatalog && !string.IsNullOrEmpty(initialCatalog)) + { + return Constants.DbProviderNames.SqlServer; + } + } + + throw new ArgumentException("Cannot determine provider name from connection string", nameof(connectionString)); + } } } diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index eee8faa492..d21cba4486 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -1,93 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Data.Common; +using System.Collections.Generic; namespace Umbraco.Core.Configuration.Models { public class ConnectionStrings { - - // Backing field for UmbracoConnectionString to load from configuration value with key umbracoDbDSN. // Attributes cannot be applied to map from keys that don't match, and have chosen to retain the key name // used in configuration for older Umbraco versions. // See: https://stackoverflow.com/a/54607296/489433 private string umbracoDbDSN { - get => string.Empty; - set - { - UmbracoConnectionString = value; - - ConnectionStringDictionary[Constants.System.UmbracoConnectionName] = value; - } + get => UmbracoConnectionString?.ConnectionString; + set => UmbracoConnectionString = new ConfigConnectionString(Constants.System.UmbracoConnectionName, value); } - public string UmbracoConnectionString - { - get - { - ConnectionStringDictionary.TryGetValue(Constants.System.UmbracoConnectionName, out var value); - return value; - } - set => ConnectionStringDictionary[Constants.System.UmbracoConnectionName] = value; - } - - private Dictionary ConnectionStringDictionary { get; } = new Dictionary(); - - public ConfigConnectionString this[string key] - { - get - { - if (!ConnectionStringDictionary.TryGetValue(key, out var connectionString)) - { - return null; - } - - var provider = ParseProvider(connectionString); - return new ConfigConnectionString(connectionString, provider, key); - } - set => throw new NotImplementedException(); - } - - private string ParseProvider(string connectionString) - { - if (string.IsNullOrEmpty(connectionString)) - { - return null; - } - - var builder = new DbConnectionStringBuilder(); - - builder.ConnectionString = connectionString; - - if (builder.TryGetValue("Data Source", out var ds) && ds is string dataSource) - { - if (dataSource.EndsWith(".sdf")) - { - return Constants.DbProviderNames.SqlCe; - } - } - - if (builder.TryGetValue("Server", out var s) && s is string server && !string.IsNullOrEmpty(server)) - { - if (builder.TryGetValue("Database", out var db) && db is string database && !string.IsNullOrEmpty(database)) - { - return Constants.DbProviderNames.SqlServer; - } - - if (builder.TryGetValue("AttachDbFileName", out var a) && a is string attachDbFileName && !string.IsNullOrEmpty(attachDbFileName)) - { - return Constants.DbProviderNames.SqlServer; - } - - if (builder.TryGetValue("Initial Catalog", out var i) && i is string initialCatalog && !string.IsNullOrEmpty(initialCatalog)) - { - return Constants.DbProviderNames.SqlServer; - } - } - - throw new ArgumentException("Cannot determine provider name from connection string", nameof(connectionString)); - } + public ConfigConnectionString UmbracoConnectionString { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Install/InstallHelper.cs b/src/Umbraco.Infrastructure/Install/InstallHelper.cs index af00034983..967e8cc087 100644 --- a/src/Umbraco.Infrastructure/Install/InstallHelper.cs +++ b/src/Umbraco.Infrastructure/Install/InstallHelper.cs @@ -116,7 +116,7 @@ namespace Umbraco.Web.Install { get { - var databaseSettings = _connectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = _connectionStrings.UmbracoConnectionString; if (databaseSettings.IsConnectionStringConfigured() == false) { //no version or conn string configured, must be a brand new install diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs index d995002daa..74b5b68bfd 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs @@ -108,7 +108,7 @@ namespace Umbraco.Web.Install.InstallSteps private bool ShouldDisplayView() { //If the connection string is already present in web.config we don't need to show the settings page and we jump to installing/upgrading. - var databaseSettings = _connectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = _connectionStrings.UmbracoConnectionString; if (databaseSettings.IsConnectionStringConfigured()) { diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs index 22ad84df74..476feba119 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web.Install.InstallSteps return false; } - var databaseSettings = _connectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = _connectionStrings.UmbracoConnectionString; if (databaseSettings.IsConnectionStringConfigured()) { diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index 11f8f916ed..f2e9556a48 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -132,7 +132,7 @@ namespace Umbraco.Web.Install.InstallSteps public override bool RequiresExecution(UserModel model) { //now we have to check if this is really a new install, the db might be configured and might contain data - var databaseSettings = _connectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = _connectionStrings.UmbracoConnectionString; if (databaseSettings.IsConnectionStringConfigured() && _databaseBuilder.IsDatabaseConfigured) return _databaseBuilder.HasSomeNonDefaultUser() == false; diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index eea82026ab..c092cc8b0e 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -70,7 +70,7 @@ namespace Umbraco.Core.Persistence /// /// Used by core runtime. public UmbracoDatabaseFactory(ILogger logger, IOptions globalSettings, IOptions connectionStrings, Lazy mappers,IDbProviderFactoryCreator dbProviderFactoryCreator) - : this(logger, globalSettings.Value, connectionStrings.Value, Constants.System.UmbracoConnectionName, mappers, dbProviderFactoryCreator) + : this(logger, globalSettings.Value, connectionStrings.Value, mappers, dbProviderFactoryCreator) { } @@ -79,17 +79,15 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . ///
/// Used by the other ctor and in tests. - public UmbracoDatabaseFactory(ILogger logger, GlobalSettings globalSettings, ConnectionStrings connectionStrings, string connectionStringName, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) + public UmbracoDatabaseFactory(ILogger logger, GlobalSettings globalSettings, ConnectionStrings connectionStrings, Lazy mappers, IDbProviderFactoryCreator dbProviderFactoryCreator) { - if (connectionStringName == null) throw new ArgumentNullException(nameof(connectionStringName)); - if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(connectionStringName)); _globalSettings = globalSettings; _mappers = mappers ?? throw new ArgumentNullException(nameof(mappers)); _dbProviderFactoryCreator = dbProviderFactoryCreator ?? throw new ArgumentNullException(nameof(dbProviderFactoryCreator)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - var settings = connectionStrings[connectionStringName]; + var settings = connectionStrings.UmbracoConnectionString; if (settings == null) { diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index 723be61283..4cbe8f088a 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -41,7 +41,6 @@ namespace Umbraco.Core.Runtime _dbFactory = new UmbracoDatabaseFactory(_logger, globalSettings, connectionStrings, - Constants.System.UmbracoConnectionName, new Lazy(() => new MapperCollection(Enumerable.Empty())), dbProviderFactoryCreator); diff --git a/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs b/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs index a252a7996c..4aba98fccd 100644 --- a/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs @@ -1,3 +1,5 @@ +using Umbraco.Core; +using Umbraco.Core.Configuration; using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; namespace Umbraco.Tests.Common.Builders @@ -18,7 +20,7 @@ namespace Umbraco.Tests.Common.Builders return new ConnectionStrings { - UmbracoConnectionString = umbracoConnectionString, + UmbracoConnectionString = new ConfigConnectionString(Constants.System.UmbracoConnectionName, umbracoConnectionString), }; } } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj index dc10208d1e..b5d2da1bba 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj +++ b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj @@ -11,6 +11,9 @@ + + + diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs index 8c5f096208..544765ee9c 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Configuration/Models/ConnectionStringsTests.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.UnitTests.Umbraco.Configuration.Models @@ -13,19 +14,17 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Configuration.Models [TestCase(@"Server=(LocalDb)\Umbraco;Database=NetCore;Integrated Security=true", ExpectedResult = Constants.DbProviderNames.SqlServer)] public string ParseProviderName(string connectionString) { - var key = Constants.System.UmbracoConnectionName; - var connectionStrings = new ConnectionStrings { - UmbracoConnectionString = connectionString + UmbracoConnectionString = new ConfigConnectionString(Constants.System.UmbracoConnectionName, connectionString) }; - var actual = connectionStrings[key]; + var actual = connectionStrings.UmbracoConnectionString; Assert.AreEqual(connectionString, actual.ConnectionString); - Assert.AreEqual(key, actual.Name); + Assert.AreEqual(Constants.System.UmbracoConnectionName, actual.Name); - return connectionStrings[key].ProviderName; + return connectionStrings.UmbracoConnectionString.ProviderName; } } } diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index b3f576b06d..e101bb33a3 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -96,7 +96,6 @@ namespace Umbraco.Tests.TestHelpers databaseFactory = new UmbracoDatabaseFactory(logger, globalSettings, connectionStrings, - Constants.System.UmbracoConnectionName, new Lazy(() => mappers), TestHelper.DbProviderFactoryCreator); } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 0ebe1ab2fb..0c39ee47f0 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -471,7 +471,6 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(f => new UmbracoDatabaseFactory(Logger, globalSettings, connectionStrings, - Constants.System.UmbracoConnectionName, new Lazy(f.GetInstance), TestHelper.DbProviderFactoryCreator)); From 9d91e629c6cfb069e8f74be22a5d34101bf76b19 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 15 Sep 2020 10:13:05 +0200 Subject: [PATCH 52/58] Bugfix in CheckIfUserTicketDataIsStaleAttribute --- .../Controllers/UmbracoAuthorizedApiController.cs | 2 +- .../Filters/CheckIfUserTicketDataIsStaleAttribute.cs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs index c3e1a71b86..85c92d1139 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.BackOffice.Controllers [UmbracoAuthorize] [DisableBrowserCache] [UmbracoWebApiRequireHttps] - //[CheckIfUserTicketDataIsStale] //TODO reintroduce + [CheckIfUserTicketDataIsStale] //[UnhandedExceptionLoggerConfiguration] //TODO reintroduce //[EnableDetailedErrors] //TODO reintroduce public abstract class UmbracoAuthorizedApiController : UmbracoApiController diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index c3bc1a56db..fd82b498bb 100644 --- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -67,7 +67,7 @@ namespace Umbraco.Web.BackOffice.Filters await CheckStaleData(actionContext); //we need new tokens and append the custom header if changes have been made - if (!(_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null)) + if (_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null) return; var tokenFilter = @@ -83,10 +83,7 @@ namespace Umbraco.Web.BackOffice.Filters private async Task CheckStaleData(ActionExecutingContext actionContext) { - if (actionContext == null - || actionContext.HttpContext.Request == null - || actionContext.HttpContext.User == null - || actionContext.HttpContext.User.Identity == null) + if (actionContext?.HttpContext.Request == null || actionContext.HttpContext.User?.Identity == null) { return; } From 5836ca3da44861b80df24c792f4ffcfd1e947732 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 15 Sep 2020 10:27:23 +0200 Subject: [PATCH 53/58] Bugfix - Imagesharp cache folder is not relative to root but to the wwwroot. "~" is not replaced with root --- src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs index d2395b6da9..25467b5a46 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs @@ -10,6 +10,6 @@ namespace Umbraco.Core.Configuration.Models public uint CachedNameLength { get; set; } = 8; - public string CacheFolder { get; set; } = Path.Combine("~", "Umbraco", "Cache"); + public string CacheFolder { get; set; } = Path.Combine("..", "Umbraco", "MediaCache"); } } From 9c91dd5994610ee2fe7f2e7b039e646bc2e1fbdb Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 15 Sep 2020 12:23:41 +0200 Subject: [PATCH 54/58] Fixed test --- .../Builders/ConnectionStringsBuilderTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs index c8ba34be60..7a95df708e 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs @@ -10,7 +10,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders public void Is_Built_Correctly() { // Arrange - const string umbracoConnectionString = "connection string"; + const string umbracoConnectionString = "Server=(LocalDB)\\Umbraco;Database=FakeName;Integrated Security=true"; var builder = new ConnectionStringsBuilder(); @@ -20,7 +20,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders .Build(); // Assert - Assert.AreEqual(umbracoConnectionString, connectionStrings.UmbracoConnectionString); + Assert.AreEqual(umbracoConnectionString, connectionStrings.UmbracoConnectionString.ConnectionString); } } } From b7a48686f0a3b2b2a2ddc2c09f7f6b9110fa9af6 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 15 Sep 2020 13:18:01 +0200 Subject: [PATCH 55/58] Updates based on review feedback --- .../Configuration/Models/ContentErrorPage.cs | 2 +- .../TestServerTest/UmbracoBuilderExtensions.cs | 1 - src/Umbraco.Tests/Models/VariationTests.cs | 4 ---- .../Filters/CheckIfUserTicketDataIsStaleAttribute.cs | 11 ++++++++--- .../UmbracoCoreServiceCollectionExtensions.cs | 4 ++-- src/Umbraco.Web/Security/AuthenticationExtensions.cs | 2 +- .../Security/ExternalSignInAutoLinkOptions.cs | 2 +- src/Umbraco.Web/UmbracoApplicationBase.cs | 2 -- src/Umbraco.Web/UmbracoModule.cs | 2 +- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs b/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs index e04362eafd..8971dda5cc 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs @@ -4,7 +4,7 @@ namespace Umbraco.Core.Configuration.Models { public class ContentErrorPage { - //TODO introduce valiation, to check only one of key/id/xPath is used. + //TODO introduce validation, to check only one of key/id/xPath is used. public int ContentId { get; } public Guid ContentKey { get; } public string ContentXPath { get; } diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs index 0fa81d7de5..953be73c27 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs @@ -30,7 +30,6 @@ namespace Umbraco.Tests.Integration.TestServerTest typeof(UmbracoBuilderExtensions).Assembly, AppCaches.NoCache, // Disable caches in integration tests testHelper.GetLoggingConfiguration(), - // TODO: Yep that's extremely ugly (globalSettings, connectionStrings, umbVersion, ioHelper, logger, profiler, hostingEnv, backOfficeInfo, typeFinder, appCaches, dbProviderFactoryCreator) => { diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index 17042d5c96..e811d06db1 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -30,10 +30,6 @@ namespace Umbraco.Tests.Models Current.Reset(); - // var configs = TestHelper.GetConfigs(); - // configs.Add(() => SettingsForTests.DefaultGlobalSettings); - // configs.Add(SettingsForTests.GenerateMockContentSettings); - _factory = Mock.Of(); var dataTypeService = Mock.Of(); diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index fd82b498bb..fdeb86feaf 100644 --- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -66,21 +66,26 @@ namespace Umbraco.Web.BackOffice.Filters await CheckStaleData(actionContext); - //we need new tokens and append the custom header if changes have been made + //return if nothing is updated if (_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null) return; + await UpdateTokesAndAppendCustomHeaders(actionContext); + } + + private async Task UpdateTokesAndAppendCustomHeaders(ActionExecutingContext actionContext) + { var tokenFilter = new SetAngularAntiForgeryTokensAttribute.SetAngularAntiForgeryTokensFilter(_backOfficeAntiforgery, _globalSettings); - await tokenFilter.OnActionExecutionAsync(actionContext, () => Task.FromResult(new ActionExecutedContext(actionContext, new List(), null))); + await tokenFilter.OnActionExecutionAsync(actionContext, + () => Task.FromResult(new ActionExecutedContext(actionContext, new List(), null))); //add the header AppendUserModifiedHeaderAttribute.AppendHeader(actionContext); } - private async Task CheckStaleData(ActionExecutingContext actionContext) { if (actionContext?.HttpContext.Request == null || actionContext.HttpContext.User?.Identity == null) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index ae930613dd..8d75159ce9 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -143,7 +143,7 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Security")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); @@ -213,7 +213,7 @@ namespace Umbraco.Extensions /// /// /// - /// Delegate to create ana + /// Delegate to create an /// /// public static IServiceCollection AddUmbracoCore( diff --git a/src/Umbraco.Web/Security/AuthenticationExtensions.cs b/src/Umbraco.Web/Security/AuthenticationExtensions.cs index 343579fb11..de5abf8a6b 100644 --- a/src/Umbraco.Web/Security/AuthenticationExtensions.cs +++ b/src/Umbraco.Web/Security/AuthenticationExtensions.cs @@ -164,7 +164,7 @@ namespace Umbraco.Web.Security public static AuthenticationTicket GetUmbracoAuthTicket(this IOwinContext ctx) { if (ctx == null) throw new ArgumentNullException(nameof(ctx)); - return GetAuthTicket(ctx, /*Current.Configs.Security() TODO*/new SecuritySettings().AuthCookieName); + return GetAuthTicket(ctx, /*Current.Configs.Security() TODO introduce injection instead of default value*/new SecuritySettings().AuthCookieName); } private static AuthenticationTicket GetAuthTicket(this IOwinContext owinCtx, string cookieName) diff --git a/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs b/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs index 72b3f0abe0..52239f0fda 100644 --- a/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs +++ b/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Security { _defaultUserGroups = defaultUserGroups ?? new[] { Constants.Security.EditorGroupAlias }; _autoLinkExternalAccount = autoLinkExternalAccount; - _defaultCulture = defaultCulture ?? /*Current.Configs.Global().DefaultUILanguage TODO */ "en-US"; + _defaultCulture = defaultCulture ?? /*Current.Configs.Global().DefaultUILanguage TODO reintroduce config value*/ "en-US"; } private readonly string[] _defaultUserGroups; diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 3bf1b6be12..f144a52761 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -40,8 +40,6 @@ namespace Umbraco.Web { if (!Umbraco.Composing.Current.IsInitialized) { - //var configFactory = new ConfigsFactory(); - HostingSettings hostingSettings = null; GlobalSettings globalSettings = null; SecuritySettings securitySettings = null; diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 98b6feb9b1..358d213bb8 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web else if (pcr.Is404) { response.StatusCode = 404; - response.TrySkipIisCustomErrors = /*Current.Configs.WebRouting().TrySkipIisCustomErrors; TODO */ false; + response.TrySkipIisCustomErrors = /*Current.Configs.WebRouting().TrySkipIisCustomErrors; TODO introduce from config*/ false; if (response.TrySkipIisCustomErrors == false) logger.Warn("Status code is 404 yet TrySkipIisCustomErrors is false - IIS will take over."); From 1334fd0c5e56c957dd90730243cc687b911e5ee3 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 16 Sep 2020 11:47:37 +0200 Subject: [PATCH 56/58] Typo --- .../Filters/CheckIfUserTicketDataIsStaleAttribute.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index fdeb86feaf..cde2f77bf7 100644 --- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -70,10 +70,10 @@ namespace Umbraco.Web.BackOffice.Filters if (_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null) return; - await UpdateTokesAndAppendCustomHeaders(actionContext); + await UpdateTokensAndAppendCustomHeaders(actionContext); } - private async Task UpdateTokesAndAppendCustomHeaders(ActionExecutingContext actionContext) + private async Task UpdateTokensAndAppendCustomHeaders(ActionExecutingContext actionContext) { var tokenFilter = new SetAngularAntiForgeryTokensAttribute.SetAngularAntiForgeryTokensFilter(_backOfficeAntiforgery, From 380bec0e2f4f3afc6643b5a3b3dc6ff982b72745 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 18 Sep 2020 07:05:40 +0200 Subject: [PATCH 57/58] Fixed wrong config file path Signed-off-by: Bjarke Berg --- src/Umbraco.Web.UI.NetCore/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 3bbb4e7da4..1eb761e1ad 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -13,7 +13,7 @@ "Global": { "DefaultUILanguage": "en-us", "HideTopLevelNodeFromPath": true, - "Path": "~/umbraco", + "UmbracoPath": "~/umbraco", "TimeOutInMinutes": 20, "UseHttps": false }, From d7ab7d3d2eb3e70faff8462201cfa175cd528db0 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 18 Sep 2020 08:30:48 +0200 Subject: [PATCH 58/58] Removed test code Signed-off-by: Bjarke Berg --- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 8d75159ce9..44fb18a159 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -284,13 +284,6 @@ namespace Umbraco.Extensions factory = coreRuntime.Configure(container); - - services.Configure(hostingSettings => - { - hostingSettings.Debug = false; - }); - - return services; }