From 5c0e42e1cbf60b06214a29afb27eb35baf873b7f Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 10 Sep 2021 10:31:38 -0600 Subject: [PATCH] Allows replacing MainDom with alternate DB There are some cases where there is a complex hosting strategy and folks want a readonly database and are hosting on Azure. In that case, it is not entirely possible to have a readonly Umbraco database because SqlMainDom is required and part of that requirement is to have read/write access to the umbraco key value table. This PR allows for the default MainDom to be replaced and to allow for an SqlMainDomLock to use an alternate connection string so that a separate read/write database can be used. (cherry picked from commit 9f48a9f940b9fee7a09fe4a2f2062c33f455eeb4) --- src/Umbraco.Core/Runtime/MainDom.cs | 2 +- src/Umbraco.Core/Runtime/SqlMainDomLock.cs | 6 +++--- src/Umbraco.Web/UmbracoApplication.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Runtime/MainDom.cs b/src/Umbraco.Core/Runtime/MainDom.cs index d784560f2c..b5404c62b2 100644 --- a/src/Umbraco.Core/Runtime/MainDom.cs +++ b/src/Umbraco.Core/Runtime/MainDom.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Runtime /// When an AppDomain starts, it tries to acquire the main domain status. /// When an AppDomain stops (eg the application is restarting) it should release the main domain status. /// - internal class MainDom : IMainDom, IRegisteredObject, IDisposable + public class MainDom : IMainDom, IRegisteredObject, IDisposable { #region Vars diff --git a/src/Umbraco.Core/Runtime/SqlMainDomLock.cs b/src/Umbraco.Core/Runtime/SqlMainDomLock.cs index 12359c96d1..8e38fa74c4 100644 --- a/src/Umbraco.Core/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Core/Runtime/SqlMainDomLock.cs @@ -18,7 +18,7 @@ using MapperCollection = Umbraco.Core.Persistence.Mappers.MapperCollection; namespace Umbraco.Core.Runtime { - internal class SqlMainDomLock : IMainDomLock + public class SqlMainDomLock : IMainDomLock { private readonly TimeSpan _lockTimeout; private string _lockId; @@ -33,14 +33,14 @@ namespace Umbraco.Core.Runtime private object _locker = new object(); private bool _hasTable = false; - public SqlMainDomLock(ILogger logger) + public SqlMainDomLock(ILogger logger, string connectionStringName = Constants.System.UmbracoConnectionName) { // 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(); _logger = logger; _dbFactory = new UmbracoDatabaseFactory( - Constants.System.UmbracoConnectionName, + connectionStringName, _logger, new Lazy(() => new MapperCollection(Enumerable.Empty()))); diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index c96e21e348..563d553ac2 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -76,7 +76,7 @@ namespace Umbraco.Web /// /// Returns a new MainDom /// - protected IMainDom GetMainDom(ILogger logger) + protected virtual IMainDom GetMainDom(ILogger logger) { // Determine if we should use the sql main dom or the default var appSettingMainDomLock = ConfigurationManager.AppSettings[Constants.AppSettings.MainDomLock];