Skip to content

Commit 9f48a9f

Browse files
Shazwazzanul800sebastiaan
authored andcommitted
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.
1 parent ef7fe70 commit 9f48a9f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Umbraco.Core/Runtime/MainDom.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Umbraco.Core.Runtime
1919
/// <para>When an AppDomain starts, it tries to acquire the main domain status.</para>
2020
/// <para>When an AppDomain stops (eg the application is restarting) it should release the main domain status.</para>
2121
/// </remarks>
22-
internal class MainDom : IMainDom, IRegisteredObject, IDisposable
22+
public class MainDom : IMainDom, IRegisteredObject, IDisposable
2323
{
2424
#region Vars
2525

src/Umbraco.Core/Runtime/SqlMainDomLock.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace Umbraco.Core.Runtime
2020
{
21-
internal class SqlMainDomLock : IMainDomLock
21+
public class SqlMainDomLock : IMainDomLock
2222
{
2323
private readonly TimeSpan _lockTimeout;
2424
private string _lockId;
@@ -33,14 +33,14 @@ internal class SqlMainDomLock : IMainDomLock
3333
private object _locker = new object();
3434
private bool _hasTable = false;
3535

36-
public SqlMainDomLock(ILogger logger)
36+
public SqlMainDomLock(ILogger logger, string connectionStringName = Constants.System.UmbracoConnectionName)
3737
{
3838
// unique id for our appdomain, this is more unique than the appdomain id which is just an INT counter to its safer
3939
_lockId = Guid.NewGuid().ToString();
4040
_logger = logger;
4141

4242
_dbFactory = new UmbracoDatabaseFactory(
43-
Constants.System.UmbracoConnectionName,
43+
connectionStringName,
4444
_logger,
4545
new Lazy<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())));
4646

src/Umbraco.Web/UmbracoApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected virtual string GetBootErrorFileName()
7676
/// <summary>
7777
/// Returns a new MainDom
7878
/// </summary>
79-
protected IMainDom GetMainDom(ILogger logger)
79+
protected virtual IMainDom GetMainDom(ILogger logger)
8080
{
8181
// Determine if we should use the sql main dom or the default
8282
var appSettingMainDomLock = ConfigurationManager.AppSettings[Constants.AppSettings.MainDomLock];

0 commit comments

Comments
 (0)