2020-12-09 22:43:49 +11:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-10-27 10:53:01 +00:00
|
|
|
using Umbraco.Core;
|
2019-01-03 21:00:28 +01:00
|
|
|
using Umbraco.Core.Composing;
|
2020-12-09 22:43:49 +11:00
|
|
|
using Umbraco.Core.DependencyInjection;
|
2020-01-23 18:10:21 +11:00
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
using Umbraco.Core.Scoping;
|
|
|
|
|
using Umbraco.Core.Services;
|
2020-01-30 20:05:16 +01:00
|
|
|
using Umbraco.Infrastructure.PublishedCache;
|
2020-12-09 22:43:49 +11:00
|
|
|
using Umbraco.Infrastructure.PublishedCache.Persistence;
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.NuCache
|
|
|
|
|
{
|
2020-12-09 22:43:49 +11:00
|
|
|
// TODO: We'll need to change this stuff to IUmbracoBuilder ext and control the order of things there,
|
|
|
|
|
// see comment in ModelsBuilderComposer which requires this weird IPublishedCacheComposer
|
|
|
|
|
public class NuCacheComposer : IComposer, IPublishedCacheComposer
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
2020-12-09 22:43:49 +11:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void Compose(IUmbracoBuilder builder)
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
|
|
|
|
// register the NuCache database data source
|
2020-12-09 22:43:49 +11:00
|
|
|
builder.Services.AddSingleton<INuCacheContentRepository, NuCacheContentRepository>();
|
|
|
|
|
builder.Services.AddSingleton<INuCacheContentService, NuCacheContentService>();
|
|
|
|
|
builder.Services.AddSingleton<PublishedSnapshotServiceEventHandler>();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
// register the NuCache published snapshot service
|
|
|
|
|
// must register default options, required in the service ctor
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddTransient(factory => new PublishedSnapshotServiceOptions());
|
|
|
|
|
builder.SetPublishedSnapshotService<PublishedSnapshotService>();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2020-01-23 18:10:21 +11:00
|
|
|
// replace this service since we want to improve the content/media
|
|
|
|
|
// mapping lookups if we are using nucache.
|
2020-12-09 22:43:49 +11:00
|
|
|
// TODO: Gotta wonder how much this does actually improve perf? It's a lot of weird code to make this happen so hope it's worth it
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IIdKeyMap>(factory =>
|
2020-01-23 18:10:21 +11:00
|
|
|
{
|
2020-10-27 10:53:01 +00:00
|
|
|
var idkSvc = new IdKeyMap(factory.GetRequiredService<IScopeProvider>());
|
2020-12-09 22:43:49 +11:00
|
|
|
if (factory.GetRequiredService<IPublishedSnapshotService>() is PublishedSnapshotService publishedSnapshotService)
|
2020-01-23 18:10:21 +11:00
|
|
|
{
|
|
|
|
|
idkSvc.SetMapper(UmbracoObjectTypes.Document, id => publishedSnapshotService.GetDocumentUid(id), uid => publishedSnapshotService.GetDocumentId(uid));
|
|
|
|
|
idkSvc.SetMapper(UmbracoObjectTypes.Media, id => publishedSnapshotService.GetMediaUid(id), uid => publishedSnapshotService.GetMediaId(uid));
|
2020-02-06 14:09:16 +01:00
|
|
|
}
|
2020-12-09 22:43:49 +11:00
|
|
|
|
2020-01-23 18:10:21 +11:00
|
|
|
return idkSvc;
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
// add the NuCache health check (hidden from type finder)
|
2019-01-26 10:52:19 -05:00
|
|
|
// TODO: no NuCache health check yet
|
2020-12-09 22:43:49 +11:00
|
|
|
// composition.HealthChecks().Add<NuCacheIntegrityHealthCheck>();
|
2019-01-03 21:00:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-01-05 15:49:10 +01:00
|
|
|
}
|