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 9f48a9f940)
This commit is contained in:
committed by
Sebastiaan Janssen
parent
b6268e3650
commit
5c0e42e1cb
@@ -19,7 +19,7 @@ namespace Umbraco.Core.Runtime
|
||||
/// <para>When an AppDomain starts, it tries to acquire the main domain status.</para>
|
||||
/// <para>When an AppDomain stops (eg the application is restarting) it should release the main domain status.</para>
|
||||
/// </remarks>
|
||||
internal class MainDom : IMainDom, IRegisteredObject, IDisposable
|
||||
public class MainDom : IMainDom, IRegisteredObject, IDisposable
|
||||
{
|
||||
#region Vars
|
||||
|
||||
|
||||
@@ -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<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())));
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Returns a new MainDom
|
||||
/// </summary>
|
||||
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];
|
||||
|
||||
Reference in New Issue
Block a user