Fixing tests, more DependencyInjection namespace
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.DependencyInjection;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Infrastructure.PublishedCache.Persistence;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.NuCache;
|
||||
|
||||
namespace Umbraco.Infrastructure.PublishedCache.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IUmbracoBuilder"/> for the Umbraco's NuCache
|
||||
/// </summary>
|
||||
public static class UmbracoBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds Umbraco NuCache dependencies
|
||||
/// </summary>
|
||||
public static IUmbracoBuilder AddNuCache(this IUmbracoBuilder builder)
|
||||
{
|
||||
// register the NuCache database data source
|
||||
builder.Services.TryAddSingleton<INuCacheContentRepository, NuCacheContentRepository>();
|
||||
builder.Services.TryAddSingleton<INuCacheContentService, NuCacheContentService>();
|
||||
builder.Services.TryAddSingleton<PublishedSnapshotServiceEventHandler>();
|
||||
|
||||
// register the NuCache published snapshot service
|
||||
// must register default options, required in the service ctor
|
||||
builder.Services.TryAddTransient(factory => new PublishedSnapshotServiceOptions());
|
||||
builder.SetPublishedSnapshotService<PublishedSnapshotService>();
|
||||
|
||||
// Add as itself
|
||||
builder.Services.TryAddSingleton<PublishedSnapshotService>();
|
||||
builder.Services.TryAddSingleton<IPublishedSnapshotStatus, PublishedSnapshotStatus>();
|
||||
|
||||
// replace this service since we want to improve the content/media
|
||||
// mapping lookups if we are using nucache.
|
||||
// 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
|
||||
builder.Services.AddUnique<IIdKeyMap>(factory =>
|
||||
{
|
||||
var idkSvc = new IdKeyMap(factory.GetRequiredService<IScopeProvider>());
|
||||
if (factory.GetRequiredService<IPublishedSnapshotService>() is PublishedSnapshotService publishedSnapshotService)
|
||||
{
|
||||
idkSvc.SetMapper(UmbracoObjectTypes.Document, id => publishedSnapshotService.GetDocumentUid(id), uid => publishedSnapshotService.GetDocumentId(uid));
|
||||
idkSvc.SetMapper(UmbracoObjectTypes.Media, id => publishedSnapshotService.GetMediaUid(id), uid => publishedSnapshotService.GetMediaId(uid));
|
||||
}
|
||||
|
||||
return idkSvc;
|
||||
});
|
||||
|
||||
// add the NuCache health check (hidden from type finder)
|
||||
// TODO: no NuCache health check yet
|
||||
// composition.HealthChecks().Add<NuCacheIntegrityHealthCheck>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user