Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions uSync.AutoTemplates/AutoTemplateComposer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Umbraco.Cms.Core.Composing;
using System.Linq;

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

namespace uSync.AutoTemplates;
Expand All @@ -7,6 +9,8 @@ public class AutoTemplateComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AdduSyncAutoTemplates();
// only load when the backoffice is enabled.
if (builder.Services.Any(s => s.ServiceType == typeof(IBackOfficeEnabledMarker)))
builder.AdduSyncAutoTemplates();
}
}
19 changes: 17 additions & 2 deletions uSync.BackOffice/HealthChecks/SyncFolderIntegrityChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ namespace uSync.BackOffice.HealthChecks;
Group = "uSync")]
public class SyncFolderIntegrityChecks : HealthCheck
{
private readonly ISyncConfigService _configService;
private readonly ISyncFileService _fileService;
private readonly ISyncConfigService? _configService;
private readonly ISyncFileService? _fileService;


public SyncFolderIntegrityChecks() { }

/// <summary>
/// Constructor
Expand All @@ -41,6 +44,18 @@ public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
/// <inheritdoc/>
public override Task<IEnumerable<HealthCheckStatus>> GetStatusAsync()
{
if (_configService is null || _fileService is null)
{
return Task.FromResult((IEnumerable<HealthCheckStatus>)new List<HealthCheckStatus>
{
new HealthCheckStatus("uSync services not available")
{
Description = "The uSync services are not available, this likely means the site has no backoffice loaded.",
ResultType = StatusResultType.Info
}
});
}

var items = new List<HealthCheckStatus>
{
CheckuSyncFolder(),
Expand Down
18 changes: 13 additions & 5 deletions uSync.BackOffice/uSyncBackOfficeComposer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

using Microsoft.Extensions.Logging;

using System.Linq;

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

using uSync.Core.Extensions;

namespace uSync.BackOffice;

/// <summary>
Expand All @@ -12,10 +18,12 @@ public class uSyncBackOfficeComposer : IComposer
/// <inheritdoc/>
public void Compose(IUmbracoBuilder builder)
{
// the composers add uSync, but the extension methods
// will only add the values if uSync hasn't already
// been added, so you can for example add uSync to your
// startup.cs file. and then the composers don't fire
builder.AdduSync();
if (builder.IsUmbracoBackOfficeEnabled() is true) {
// the composers add uSync, but the extension methods
// will only add the values if uSync hasn't already
// been added, so you can for example add uSync to your
// startup.cs file. and then the composers don't fire
builder.AdduSync();
}
}
}
4 changes: 4 additions & 0 deletions uSync.Backoffice.Management.Api/ApiComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using uSync.Backoffice.Management.Api.Configuration;
using uSync.Backoffice.Management.Api.Services;
using uSync.BackOffice;
using uSync.Core.Extensions;

namespace uSync.Backoffice.Management.Api;

Expand All @@ -15,6 +16,9 @@ public class ApiComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
if (builder.IsUmbracoBackOfficeEnabled() is false)
return;

builder.Services.AddSingleton<IOperationIdHandler, uSyncCustomOperationHandler>();

builder.Services.ConfigureOptions<ConfigSyncApiSwaggerGenOptions>();
Expand Down
9 changes: 7 additions & 2 deletions uSync.Backoffice.Management.Client/uSyncManifestReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using uSync.BackOffice.Configuration;
using uSync.BackOffice.Extensions;
using uSync.Core.Extensions;

namespace uSync.Backoffice.Management.Client;

Expand All @@ -18,8 +19,12 @@ public class uSyncManifestComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddSingleton<IPackageManifestReader, uSyncManifestReader>();
builder.Services.AddSingleton<IPackageManifestReader, SyncSectionManifestReader>();
if (builder.IsUmbracoBackOfficeEnabled())
{
// only load this when the backoffice is enabled.
builder.Services.AddSingleton<IPackageManifestReader, uSyncManifestReader>();
builder.Services.AddSingleton<IPackageManifestReader, SyncSectionManifestReader>();
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions uSync.Core/Extensions/SyncBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Umbraco.Cms.Core.DependencyInjection;

namespace uSync.Core.Extensions;

public static class SyncBuilderExtensions
{
public static bool IsUmbracoBackOfficeEnabled(this IUmbracoBuilder builder)
=> builder.Services.Any(s => s.ServiceType == typeof(IBackOfficeEnabledMarker));
}
5 changes: 5 additions & 0 deletions uSync.History/uSyncHistoryComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using uSync.BackOffice;
using uSync.BackOffice.Extensions;
using uSync.Core.Extensions;
using uSync.History.Service;

namespace uSync.History
Expand All @@ -26,6 +27,10 @@ public class uSyncHistoryComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// don't load if the backoffice is not loaded as part of the project.
if (builder.IsUmbracoBackOfficeEnabled() is false)
return;

builder.Services.AddSingleton<ISyncHistoryService, SyncHistoryService>();

builder.AddNotificationAsyncHandler<uSyncImportCompletedNotification, uSyncHistoryNotificationHandler>();
Expand Down
Loading