2019-01-03 21:00:28 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-10-30 11:16:17 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using Umbraco.Cms.Core.Logging;
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Core.Composing
|
2019-01-03 21:00:28 +01:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Builds a <see cref="ComponentCollection"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ComponentCollectionBuilder : OrderedCollectionBuilderBase<ComponentCollectionBuilder, ComponentCollection, IComponent>
|
|
|
|
|
|
{
|
|
|
|
|
|
private const int LogThresholdMilliseconds = 100;
|
|
|
|
|
|
|
|
|
|
|
|
private IProfilingLogger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public ComponentCollectionBuilder()
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
protected override ComponentCollectionBuilder This => this;
|
|
|
|
|
|
|
2020-10-30 11:16:17 +00:00
|
|
|
|
protected override IEnumerable<IComponent> CreateItems(IServiceProvider factory)
|
2019-01-03 21:00:28 +01:00
|
|
|
|
{
|
2020-10-27 10:53:01 +00:00
|
|
|
|
_logger = factory.GetRequiredService<IProfilingLogger>();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
|
|
using (_logger.DebugDuration<ComponentCollectionBuilder>($"Creating components. (log when >{LogThresholdMilliseconds}ms)", "Created."))
|
|
|
|
|
|
{
|
|
|
|
|
|
return base.CreateItems(factory);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-30 11:16:17 +00:00
|
|
|
|
protected override IComponent CreateItem(IServiceProvider factory, Type itemType)
|
2019-01-03 21:00:28 +01:00
|
|
|
|
{
|
2019-02-22 19:13:25 +01:00
|
|
|
|
using (_logger.DebugDuration<ComponentCollectionBuilder>($"Creating {itemType.FullName}.", $"Created {itemType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds))
|
2019-01-03 21:00:28 +01:00
|
|
|
|
{
|
|
|
|
|
|
return base.CreateItem(factory, itemType);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|