diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index 299aff2caab3..fd8bdc026932 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.Cms.Core; +using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Infrastructure.Migrations.Install; using Umbraco.Cms.Infrastructure.Persistence.FaultHandling; @@ -72,21 +73,21 @@ private DbProviderFactory DbProviderFactory #region Constructors - /// + + /// /// Initializes a new instance of the . /// /// Used by the other ctor and in tests. - public UmbracoDatabaseFactory( + internal UmbracoDatabaseFactory( ILogger logger, ILoggerFactory loggerFactory, IOptions globalSettings, - IOptionsMonitor connectionStrings, IMapperCollection mappers, IDbProviderFactoryCreator dbProviderFactoryCreator, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, - NPocoMapperCollection npocoMappers) + NPocoMapperCollection npocoMappers, + string connectionString) { - _globalSettings = globalSettings; _mappers = mappers ?? throw new ArgumentNullException(nameof(mappers)); _dbProviderFactoryCreator = dbProviderFactoryCreator ?? throw new ArgumentNullException(nameof(dbProviderFactoryCreator)); @@ -95,22 +96,40 @@ public UmbracoDatabaseFactory( _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _loggerFactory = loggerFactory; - var settings = connectionStrings.CurrentValue.UmbracoConnectionString; - if (settings == null) + if (connectionString is null) { logger.LogDebug("Missing connection string, defer configuration."); return; // not configured } + var configConnectionString = new ConfigConnectionString("Custom", connectionString); // could as well be // so need to test the values too - if (settings.IsConnectionStringConfigured() == false) + if (configConnectionString.IsConnectionStringConfigured() == false) { logger.LogDebug("Empty connection string or provider name, defer configuration."); return; // not configured } - Configure(settings.ConnectionString, settings.ProviderName); + Configure(configConnectionString.ConnectionString, configConnectionString.ProviderName); + } + + /// + /// Initializes a new instance of the . + /// + /// Used by the other ctor and in tests. + public UmbracoDatabaseFactory( + ILogger logger, + ILoggerFactory loggerFactory, + IOptions globalSettings, + IOptionsMonitor connectionStrings, + IMapperCollection mappers, + IDbProviderFactoryCreator dbProviderFactoryCreator, + DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, + NPocoMapperCollection npocoMappers): + this(logger, loggerFactory, globalSettings, mappers, dbProviderFactoryCreator, databaseSchemaCreatorFactory, npocoMappers, connectionStrings?.CurrentValue?.UmbracoConnectionString?.ConnectionString) + { + } #endregion diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index 8dee49a07c78..8d1c74b619ad 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -62,11 +62,11 @@ public SqlMainDomLock( loggerFactory.CreateLogger(), loggerFactory, _globalSettings, - connectionStrings, new MapperCollection(() => Enumerable.Empty()), dbProviderFactoryCreator, databaseSchemaCreatorFactory, - npocoMappers); + npocoMappers, + connectionStringName); MainDomKey = MainDomKeyPrefix + "-" + (Environment.MachineName + MainDom.GetMainDomId(_hostingEnvironment)).GenerateHash(); } @@ -88,18 +88,10 @@ public SqlMainDomLock( hostingEnvironment, databaseSchemaCreatorFactory, npocoMappers, - Constants.System.UmbracoConnectionName + connectionStrings.CurrentValue.UmbracoConnectionString.ConnectionString ) { - loggerFactory.CreateLogger(), - loggerFactory, - _globalSettings, - connectionStrings, - new MapperCollection(() => Enumerable.Empty()), - dbProviderFactoryCreator, - databaseSchemaCreatorFactory, - npocoMappers); } public async Task AcquireLockAsync(int millisecondsTimeout)