Skip to content

Commit

Permalink
Allows replacing MainDom with alternate DB
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Shazwazza authored and nul800sebastiaan committed Sep 30, 2021
1 parent ef7fe70 commit 9f48a9f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Runtime/MainDom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/Umbraco.Core/Runtime/SqlMainDomLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Umbraco.Core.Runtime
{
internal class SqlMainDomLock : IMainDomLock
public class SqlMainDomLock : IMainDomLock
{
private readonly TimeSpan _lockTimeout;
private string _lockId;
Expand All @@ -33,14 +33,14 @@ internal class SqlMainDomLock : IMainDomLock
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>())));

Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Web/UmbracoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected virtual string GetBootErrorFileName()
/// <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];
Expand Down

0 comments on commit 9f48a9f

Please sign in to comment.