2019-02-14 09:15:47 +01:00
|
|
|
|
using Umbraco.Core;
|
2019-01-03 21:00:28 +01:00
|
|
|
|
using Umbraco.Core.Composing;
|
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;
|
2019-01-03 21:00:28 +01:00
|
|
|
|
using Umbraco.Web.PublishedCache.NuCache.DataSource;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.NuCache
|
|
|
|
|
|
{
|
2020-02-06 14:09:16 +01:00
|
|
|
|
public class NuCacheComposer : ComponentComposer<NuCacheComponent>, IPublishedCacheComposer
|
2019-01-03 21:00:28 +01:00
|
|
|
|
{
|
2019-01-05 15:49:10 +01:00
|
|
|
|
public override void Compose(Composition composition)
|
2019-01-03 21:00:28 +01:00
|
|
|
|
{
|
2019-01-05 15:49:10 +01:00
|
|
|
|
base.Compose(composition);
|
|
|
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
|
// register the NuCache database data source
|
|
|
|
|
|
composition.Register<IDataSource, DatabaseDataSource>();
|
|
|
|
|
|
|
|
|
|
|
|
// register the NuCache published snapshot service
|
|
|
|
|
|
// must register default options, required in the service ctor
|
2019-07-17 22:51:14 +10:00
|
|
|
|
composition.Register(factory => new PublishedSnapshotServiceOptions());
|
2019-01-03 21:00:28 +01:00
|
|
|
|
composition.SetPublishedSnapshotService<PublishedSnapshotService>();
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
composition.RegisterUnique<IIdKeyMap>(factory =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var idkSvc = new IdKeyMap(factory.GetInstance<IScopeProvider>());
|
|
|
|
|
|
var publishedSnapshotService = factory.GetInstance<IPublishedSnapshotService>() as PublishedSnapshotService;
|
|
|
|
|
|
if (publishedSnapshotService != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
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-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
|
2019-01-03 21:00:28 +01:00
|
|
|
|
//composition.HealthChecks().Add<NuCacheIntegrityHealthCheck>();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-01-05 15:49:10 +01:00
|
|
|
|
}
|