diff --git a/src/Umbraco.Core/CompositionExtensions.cs b/src/Umbraco.Core/CompositionExtensions.cs
index e1c7ad4467..828a577c34 100644
--- a/src/Umbraco.Core/CompositionExtensions.cs
+++ b/src/Umbraco.Core/CompositionExtensions.cs
@@ -203,6 +203,28 @@ namespace Umbraco.Core
composition.RegisterUnique(_ => registrar);
}
+ ///
+ /// Sets the database server messenger options.
+ ///
+ /// The composition.
+ /// A function creating the options.
+ /// Use DatabaseServerRegistrarAndMessengerComposer.GetDefaultOptions to get the options that Umbraco would use by default.
+ public static void SetDatabaseServerMessengerOptions(this Composition composition, Func factory)
+ {
+ composition.RegisterUnique(factory);
+ }
+
+ ///
+ /// Sets the database server messenger options.
+ ///
+ /// The composition.
+ /// Options.
+ /// Use DatabaseServerRegistrarAndMessengerComposer.GetDefaultOptions to get the options that Umbraco would use by default.
+ public static void SetDatabaseServerMessengerOptions(this Composition composition, DatabaseServerMessengerOptions options)
+ {
+ composition.RegisterUnique(_ => options);
+ }
+
///
/// Sets the short string helper.
///
diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs
index 76d7565862..818e8ecf77 100644
--- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs
+++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs
@@ -27,9 +27,8 @@ namespace Umbraco.Web
private readonly IUmbracoDatabaseFactory _databaseFactory;
public BatchedDatabaseServerMessenger(
- IRuntimeState runtime, IUmbracoDatabaseFactory databaseFactory, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, IGlobalSettings globalSettings,
- bool enableDistCalls, DatabaseServerMessengerOptions options)
- : base(runtime, scopeProvider, sqlContext, proflog, globalSettings, enableDistCalls, options)
+ IRuntimeState runtime, IUmbracoDatabaseFactory databaseFactory, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, IGlobalSettings globalSettings, DatabaseServerMessengerOptions options)
+ : base(runtime, scopeProvider, sqlContext, proflog, globalSettings, true, options)
{
_databaseFactory = databaseFactory;
}
diff --git a/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs
index 086aa9b197..a68e137665 100644
--- a/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs
+++ b/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs
@@ -38,54 +38,44 @@ namespace Umbraco.Web.Compose
public sealed class DatabaseServerRegistrarAndMessengerComposer : ComponentComposer, ICoreComposer
{
+ public static DatabaseServerMessengerOptions GetDefaultOptions(IFactory factory)
+ {
+ var logger = factory.GetInstance();
+ var indexRebuilder = factory.GetInstance();
+
+ return new DatabaseServerMessengerOptions
+ {
+ //These callbacks will be executed if the server has not been synced
+ // (i.e. it is a new server or the lastsynced.txt file has been removed)
+ InitializingCallbacks = new Action[]
+ {
+ //rebuild the xml cache file if the server is not synced
+ () =>
+ {
+ // rebuild the published snapshot caches entirely, if the server is not synced
+ // this is equivalent to DistributedCache RefreshAll... but local only
+ // (we really should have a way to reuse RefreshAll... locally)
+ // note: refresh all content & media caches does refresh content types too
+ var svc = Current.PublishedSnapshotService;
+ svc.Notify(new[] { new DomainCacheRefresher.JsonPayload(0, DomainChangeTypes.RefreshAll) });
+ svc.Notify(new[] { new ContentCacheRefresher.JsonPayload(0, TreeChangeTypes.RefreshAll) }, out _, out _);
+ svc.Notify(new[] { new MediaCacheRefresher.JsonPayload(0, TreeChangeTypes.RefreshAll) }, out _);
+ },
+
+ //rebuild indexes if the server is not synced
+ // NOTE: This will rebuild ALL indexes including the members, if developers want to target specific
+ // indexes then they can adjust this logic themselves.
+ () => { ExamineComponent.RebuildIndexes(indexRebuilder, logger, false, 5000); }
+ }
+ };
+ }
+
public override void Compose(Composition composition)
{
base.Compose(composition);
- composition.SetServerMessenger(factory =>
- {
- var runtime = factory.GetInstance();
- var databaseFactory = factory.GetInstance();
- var globalSettings = factory.GetInstance();
- var proflog = factory.GetInstance();
- var scopeProvider = factory.GetInstance();
- var sqlContext = factory.GetInstance();
- var logger = factory.GetInstance();
- var indexRebuilder = factory.GetInstance();
-
- return new BatchedDatabaseServerMessenger(
- runtime, databaseFactory, scopeProvider, sqlContext, proflog, globalSettings,
- true,
- //Default options for web including the required callbacks to build caches
- new DatabaseServerMessengerOptions
- {
- //These callbacks will be executed if the server has not been synced
- // (i.e. it is a new server or the lastsynced.txt file has been removed)
- InitializingCallbacks = new Action[]
- {
- //rebuild the xml cache file if the server is not synced
- () =>
- {
- // rebuild the published snapshot caches entirely, if the server is not synced
- // this is equivalent to DistributedCache RefreshAll... but local only
- // (we really should have a way to reuse RefreshAll... locally)
- // note: refresh all content & media caches does refresh content types too
- var svc = Current.PublishedSnapshotService;
- svc.Notify(new[] { new DomainCacheRefresher.JsonPayload(0, DomainChangeTypes.RefreshAll) });
- svc.Notify(new[] { new ContentCacheRefresher.JsonPayload(0, TreeChangeTypes.RefreshAll) }, out _, out _);
- svc.Notify(new[] { new MediaCacheRefresher.JsonPayload(0, TreeChangeTypes.RefreshAll) }, out _);
- },
-
- //rebuild indexes if the server is not synced
- // NOTE: This will rebuild ALL indexes including the members, if developers want to target specific
- // indexes then they can adjust this logic themselves.
- () =>
- {
- ExamineComponent.RebuildIndexes(indexRebuilder, logger, false, 5000);
- }
- }
- });
- });
+ composition.SetDatabaseServerMessengerOptions(GetDefaultOptions);
+ composition.SetServerMessenger();
}
}
@@ -128,7 +118,7 @@ namespace Umbraco.Web.Compose
}
public void Initialize()
- {
+ {
//We will start the whole process when a successful request is made
if (_registrar != null || _messenger != null)
UmbracoModule.RouteAttempt += RegisterBackgroundTasksOnce;