diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs index 0e4f252431..268ce92aa6 100644 --- a/src/Umbraco.Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Configuration/ConfigsFactory.cs @@ -31,7 +31,7 @@ namespace Umbraco.Core.Configuration public IContentSettings ContentSettings { get; } = new ContentSettings(); public IGlobalSettings GlobalSettings { get; } = new GlobalSettings(); - public Configs Create(IIOHelper ioHelper, ILogger logger) + public Configs Create() { var configs = new Configs(section => ConfigurationManager.GetSection(section)); configs.Add(() => GlobalSettings); @@ -41,7 +41,7 @@ namespace Umbraco.Core.Configuration configs.Add(() => CoreDebug); configs.Add(() => MachineKeyConfig); - configs.Add(() => new ConnectionStrings(ioHelper, logger)); + configs.Add(() => new ConnectionStrings()); configs.Add(() => new ModelsBuilderConfig()); diff --git a/src/Umbraco.Configuration/ConnectionStrings.cs b/src/Umbraco.Configuration/ConnectionStrings.cs index 23436d6caf..66fdb33d5b 100644 --- a/src/Umbraco.Configuration/ConnectionStrings.cs +++ b/src/Umbraco.Configuration/ConnectionStrings.cs @@ -3,6 +3,7 @@ using System.Configuration; using System.IO; using System.Linq; using System.Xml.Linq; +using Umbraco.Composing; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -10,14 +11,6 @@ namespace Umbraco.Core.Configuration { public class ConnectionStrings : IConnectionStrings { - private readonly IIOHelper _ioHelper; - private readonly ILogger _logger; - - public ConnectionStrings(IIOHelper ioHelper, ILogger logger) - { - _ioHelper = ioHelper; - _logger = logger; - } public ConfigConnectionString this[string key] { @@ -29,9 +22,9 @@ namespace Umbraco.Core.Configuration } } - public void RemoveConnectionString(string key) + public void RemoveConnectionString(string key, IIOHelper ioHelper) { - var fileName = _ioHelper.MapPath(string.Format("{0}/web.config", _ioHelper.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", ioHelper.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -52,7 +45,7 @@ namespace Umbraco.Core.Configuration /// Saves the ConnectionString in the very nasty 'medium trust'-supportive way. /// The connection string. /// The provider name. - public void SaveConnectionString(string connectionString, string providerName) + public void SaveConnectionString(string connectionString, string providerName, IIOHelper ioHelper) { if (connectionString == null) throw new ArgumentNullException(nameof(connectionString)); @@ -62,7 +55,7 @@ namespace Umbraco.Core.Configuration var fileSource = "web.config"; - var fileName = _ioHelper.MapPath(_ioHelper.Root +"/" + fileSource); + var fileName = ioHelper.MapPath(ioHelper.Root +"/" + fileSource); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); if (xml.Root == null) throw new Exception($"Invalid {fileSource} file (no root)."); @@ -75,7 +68,7 @@ namespace Umbraco.Core.Configuration if (configSourceAttribute != null) { fileSource = configSourceAttribute.Value; - fileName = _ioHelper.MapPath(_ioHelper.Root + "/" + fileSource); + fileName = ioHelper.MapPath(ioHelper.Root + "/" + fileSource); if (!File.Exists(fileName)) throw new Exception($"Invalid configSource \"{fileSource}\" (no such file)."); @@ -103,9 +96,9 @@ namespace Umbraco.Core.Configuration } // save - _logger.Info("Saving connection string to {ConfigFile}.", fileSource); + Current.Logger.Info("Saving connection string to {ConfigFile}.", fileSource); xml.Save(fileName, SaveOptions.DisableFormatting); - _logger.Info("Saved connection string to {ConfigFile}.", fileSource); + Current.Logger.Info("Saved connection string to {ConfigFile}.", fileSource); } private static void AddOrUpdateAttribute(XElement element, string name, string value) diff --git a/src/Umbraco.Core/Configuration/IConfigsFactory.cs b/src/Umbraco.Core/Configuration/IConfigsFactory.cs index b2ad6295a1..dd2459b88c 100644 --- a/src/Umbraco.Core/Configuration/IConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/IConfigsFactory.cs @@ -5,6 +5,6 @@ namespace Umbraco.Core.Configuration { public interface IConfigsFactory { - Configs Create(IIOHelper ioHelper, ILogger logger); + Configs Create(); } } diff --git a/src/Umbraco.Core/Configuration/IConnectionStrings.cs b/src/Umbraco.Core/Configuration/IConnectionStrings.cs index 2a14c0e614..f8d17d6794 100644 --- a/src/Umbraco.Core/Configuration/IConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/IConnectionStrings.cs @@ -1,3 +1,5 @@ +using Umbraco.Core.IO; + namespace Umbraco.Core.Configuration { public interface IConnectionStrings @@ -7,7 +9,7 @@ namespace Umbraco.Core.Configuration get; } - void RemoveConnectionString(string umbracoConnectionName); - void SaveConnectionString(string connectionString, string providerName); + void RemoveConnectionString(string umbracoConnectionName, IIOHelper ioHelper); + void SaveConnectionString(string connectionString, string providerName, IIOHelper ioHelper); } } diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs index a7b3dcc218..8c73e63b78 100644 --- a/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs @@ -65,7 +65,7 @@ namespace Umbraco.Web.Install.InstallSteps // Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists if (databaseSettings != null) { - connectionStrings.RemoveConnectionString(Constants.System.UmbracoConnectionName); + connectionStrings.RemoveConnectionString(Constants.System.UmbracoConnectionName, ioHelper); } else { diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index a5a58dc9f1..b92a8499fa 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -146,7 +146,7 @@ namespace Umbraco.Core.Migrations.Install private void ConfigureEmbeddedDatabaseConnection(IUmbracoDatabaseFactory factory, IIOHelper ioHelper) { - _connectionStrings.SaveConnectionString(EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe); + _connectionStrings.SaveConnectionString(EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe, ioHelper); var path = Path.Combine(ioHelper.GetRootDirectorySafe(), "App_Data", "Umbraco.sdf"); if (File.Exists(path) == false) @@ -169,7 +169,7 @@ namespace Umbraco.Core.Migrations.Install { const string providerName = Constants.DbProviderNames.SqlServer; - _connectionStrings.SaveConnectionString(connectionString, providerName); + _connectionStrings.SaveConnectionString(connectionString, providerName, _ioHelper); _databaseFactory.Configure(connectionString, providerName); } @@ -185,7 +185,7 @@ namespace Umbraco.Core.Migrations.Install { var connectionString = GetDatabaseConnectionString(server, databaseName, user, password, databaseProvider, out var providerName); - _connectionStrings.SaveConnectionString(connectionString, providerName); + _connectionStrings.SaveConnectionString(connectionString, providerName, _ioHelper); _databaseFactory.Configure(connectionString, providerName); } @@ -216,7 +216,7 @@ namespace Umbraco.Core.Migrations.Install public void ConfigureIntegratedSecurityDatabaseConnection(string server, string databaseName) { var connectionString = GetIntegratedSecurityDatabaseConnectionString(server, databaseName); - _connectionStrings.SaveConnectionString(connectionString, Constants.DbProviderNames.SqlServer); + _connectionStrings.SaveConnectionString(connectionString, Constants.DbProviderNames.SqlServer, _ioHelper); _databaseFactory.Configure(connectionString, Constants.DbProviderNames.SqlServer); } diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 288442a5a5..a5810715fb 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -50,7 +50,7 @@ namespace Umbraco.Tests.Common public Configs GetConfigs() { - return GetConfigsFactory().Create(IOHelper, Mock.Of()); + return GetConfigsFactory().Create(); } public IRuntimeState GetRuntimeState() { diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 9fb77ef59d..3f1ce81d84 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -96,7 +96,7 @@ namespace Umbraco.Tests.Runtimes private static Configs GetConfigs() { - var configs = new ConfigsFactory().Create(_ioHelper, _logger); + var configs = new ConfigsFactory().Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GenerateMockContentSettings); configs.Add(SettingsForTests.GetDefaultHostingSettings); diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs index 4d34a0511c..c05f4af4f8 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -45,7 +45,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment, httpContextAccessor, hostApplicationLifetime); var ioHelper = new IOHelper(hostingEnvironment, globalSettings); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, new AspNetCoreSessionIdResolver(httpContextAccessor), () => services.BuildServiceProvider().GetService(), coreDebug, ioHelper, new AspNetCoreMarchal()); - var configs = configFactory.Create(ioHelper, logger); + var configs = configFactory.Create(); var backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); var profiler = new LogProfiler(logger); diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 1b5b7cc145..889cae5002 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -40,7 +40,7 @@ namespace Umbraco.Web var hostingEnvironment = new AspNetHostingEnvironment(hostingSettings); var ioHelper = new IOHelper(hostingEnvironment, globalSettings); var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, new AspNetSessionManager(), () => _factory?.GetInstance(), coreDebug, ioHelper, new FrameworkMarchal()); - var configs = configFactory.Create(ioHelper, logger); + var configs = configFactory.Create(); var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, configFactory.WebRoutingSettings); var profiler = new LogProfiler(logger);