Files
Umbraco-CMS/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2019-01-03 21:00:28 +01:00
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Logging;
2019-01-03 21:00:28 +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;
protected override IEnumerable<IComponent> CreateItems(IServiceProvider factory)
2019-01-03 21:00:28 +01: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);
}
}
protected override IComponent CreateItem(IServiceProvider factory, Type itemType)
2019-01-03 21:00:28 +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);
}
}
}
}