Files
Umbraco-CMS/src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs

38 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Manifest;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Security;
namespace Umbraco.Cms.Core.ContentApps
{
2018-12-07 14:05:47 +01:00
public class ContentAppFactoryCollectionBuilder : OrderedCollectionBuilderBase<ContentAppFactoryCollectionBuilder, ContentAppFactoryCollection, IContentAppFactory>
{
2018-12-07 14:05:47 +01:00
protected override ContentAppFactoryCollectionBuilder This => this;
// need to inject dependencies in the collection, so override creation
public override ContentAppFactoryCollection CreateCollection(IServiceProvider factory)
{
// get the logger factory just-in-time - see note below for manifest parser
var loggerFactory = factory.GetRequiredService<ILoggerFactory>();
var backOfficeSecurityAccessor = factory.GetRequiredService<IBackOfficeSecurityAccessor>();
return new ContentAppFactoryCollection(CreateItems(factory), loggerFactory.CreateLogger<ContentAppFactoryCollection>(), backOfficeSecurityAccessor);
}
protected override IEnumerable<IContentAppFactory> CreateItems(IServiceProvider factory)
{
2018-09-20 18:51:46 +02:00
// get the manifest parser just-in-time - injecting it in the ctor would mean that
// simply getting the builder in order to configure the collection, would require
// its dependencies too, and that can create cycles or other oddities
var manifestParser = factory.GetRequiredService<IManifestParser>();
var ioHelper = factory.GetRequiredService<IIOHelper>();
return base.CreateItems(factory).Concat(manifestParser.Manifest.ContentApps.Select(x => new ManifestContentAppFactory(x, ioHelper)));
}
}
}