diff --git a/src/Umbraco.Core/Actions/ActionCollection.cs b/src/Umbraco.Core/Actions/ActionCollection.cs index 3987e89305..2084df3dad 100644 --- a/src/Umbraco.Core/Actions/ActionCollection.cs +++ b/src/Umbraco.Core/Actions/ActionCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Models.Membership; @@ -8,15 +9,12 @@ namespace Umbraco.Cms.Core.Actions { public class ActionCollection : BuilderCollectionBase { - public ActionCollection(IEnumerable items) - : base(items) - { } + public ActionCollection(Func> items) : base(items) + { + } public T GetAction() - where T : IAction - { - return this.OfType().FirstOrDefault(); - } + where T : IAction => this.OfType().FirstOrDefault(); public IEnumerable GetByLetters(IEnumerable letters) { diff --git a/src/Umbraco.Core/Cache/CacheRefresherCollection.cs b/src/Umbraco.Core/Cache/CacheRefresherCollection.cs index 2c9007cbe9..a61dd81368 100644 --- a/src/Umbraco.Core/Cache/CacheRefresherCollection.cs +++ b/src/Umbraco.Core/Cache/CacheRefresherCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Composing; @@ -7,11 +7,11 @@ namespace Umbraco.Cms.Core.Cache { public class CacheRefresherCollection : BuilderCollectionBase { - public CacheRefresherCollection(IEnumerable items) - : base(items) - { } + public CacheRefresherCollection(Func> items) : base(items) + { + } public ICacheRefresher this[Guid id] - => this.FirstOrDefault(x => x.RefresherUniqueId == id); + => this.FirstOrDefault(x => x.RefresherUniqueId == id); } } diff --git a/src/Umbraco.Core/Composing/BuilderCollectionBase.cs b/src/Umbraco.Core/Composing/BuilderCollectionBase.cs index a5bf33f9c1..1af9511fb7 100644 --- a/src/Umbraco.Core/Composing/BuilderCollectionBase.cs +++ b/src/Umbraco.Core/Composing/BuilderCollectionBase.cs @@ -1,43 +1,34 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; -using System.Linq; namespace Umbraco.Cms.Core.Composing { + /// /// Provides a base class for builder collections. /// /// The type of the items. public abstract class BuilderCollectionBase : IBuilderCollection { - private readonly TItem[] _items; + private readonly LazyReadOnlyCollection _items; - /// /// Initializes a new instance of the with items. /// /// The items. - protected BuilderCollectionBase(IEnumerable items) - { - _items = items.ToArray(); - } + public BuilderCollectionBase(Func> items) => _items = new LazyReadOnlyCollection(items); /// - public int Count => _items.Length; + public int Count => _items.Count; /// /// Gets an enumerator. /// - public IEnumerator GetEnumerator() - { - return ((IEnumerable) _items).GetEnumerator(); - } + public IEnumerator GetEnumerator() => ((IEnumerable)_items).GetEnumerator(); /// /// Gets an enumerator. /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/src/Umbraco.Core/Composing/CollectionBuilderBase.cs b/src/Umbraco.Core/Composing/CollectionBuilderBase.cs index ab33a6ebef..81d80bb57c 100644 --- a/src/Umbraco.Core/Composing/CollectionBuilderBase.cs +++ b/src/Umbraco.Core/Composing/CollectionBuilderBase.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Composing /// The type of the collection. /// The type of the items. public abstract class CollectionBuilderBase : ICollectionBuilder - where TBuilder: CollectionBuilderBase + where TBuilder : CollectionBuilderBase where TCollection : class, IBuilderCollection { private readonly List _types = new List(); @@ -73,7 +73,8 @@ namespace Umbraco.Cms.Core.Composing { lock (_locker) { - if (_registeredTypes != null) return; + if (_registeredTypes != null) + return; var types = GetRegisteringTypes(_types).ToArray(); @@ -110,7 +111,7 @@ namespace Umbraco.Cms.Core.Composing /// Creates a collection item. /// protected virtual TItem CreateItem(IServiceProvider factory, Type itemType) - => (TItem) factory.GetRequiredService(itemType); + => (TItem)factory.GetRequiredService(itemType); /// /// Creates a collection. @@ -118,9 +119,10 @@ namespace Umbraco.Cms.Core.Composing /// A collection. /// Creates a new collection each time it is invoked. public virtual TCollection CreateCollection(IServiceProvider factory) - { - return factory.CreateInstance( CreateItems(factory)); - } + => factory.CreateInstance(CreateItemsFactory(factory)); + + // used to resolve a Func> parameter + private Func> CreateItemsFactory(IServiceProvider factory) => () => CreateItems(factory); protected Type EnsureType(Type type, string action) { @@ -139,7 +141,7 @@ namespace Umbraco.Cms.Core.Composing public virtual bool Has() where T : TItem { - return _types.Contains(typeof (T)); + return _types.Contains(typeof(T)); } /// diff --git a/src/Umbraco.Core/Composing/ComponentCollection.cs b/src/Umbraco.Core/Composing/ComponentCollection.cs index 1cd505027b..c39dd503e0 100644 --- a/src/Umbraco.Core/Composing/ComponentCollection.cs +++ b/src/Umbraco.Core/Composing/ComponentCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Composing private readonly IProfilingLogger _profilingLogger; private readonly ILogger _logger; - public ComponentCollection(IEnumerable items, IProfilingLogger profilingLogger, ILogger logger) + public ComponentCollection(Func> items, IProfilingLogger profilingLogger, ILogger logger) : base(items) { _profilingLogger = profilingLogger; diff --git a/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs b/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs new file mode 100644 index 0000000000..7fee8eaf26 --- /dev/null +++ b/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Umbraco.Cms.Core.Composing +{ + public sealed class LazyReadOnlyCollection : IReadOnlyCollection + { + private readonly Lazy> _lazyCollection; + private int? _count; + + public LazyReadOnlyCollection(Lazy> lazyCollection) => _lazyCollection = lazyCollection; + + public LazyReadOnlyCollection(Func> lazyCollection) => _lazyCollection = new Lazy>(lazyCollection); + + public IEnumerable Value => EnsureCollection(); + + private IEnumerable EnsureCollection() + { + if (_lazyCollection == null) + { + _count = 0; + return Enumerable.Empty(); + } + + IEnumerable val = _lazyCollection.Value; + if (_count == null) + { + _count = val.Count(); + } + return val; + } + + public int Count + { + get + { + EnsureCollection(); + return _count.Value; + } + } + + public IEnumerator GetEnumerator() => Value.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} diff --git a/src/Umbraco.Core/Composing/TypeCollectionBuilderBase.cs b/src/Umbraco.Core/Composing/TypeCollectionBuilderBase.cs index 0bebf8bf8b..40ce3d8a46 100644 --- a/src/Umbraco.Core/Composing/TypeCollectionBuilderBase.cs +++ b/src/Umbraco.Core/Composing/TypeCollectionBuilderBase.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Umbraco.Extensions; @@ -37,7 +37,11 @@ namespace Umbraco.Cms.Core.Composing public TBuilder Add(IEnumerable types) { - foreach (var type in types) Add(type); + foreach (var type in types) + { + Add(type); + } + return This; } @@ -54,13 +58,12 @@ namespace Umbraco.Cms.Core.Composing } public TCollection CreateCollection(IServiceProvider factory) - { - return factory.CreateInstance(_types); - } + => factory.CreateInstance(CreateItemsFactory()); public void RegisterWith(IServiceCollection services) - { - services.Add(new ServiceDescriptor(typeof(TCollection), CreateCollection, ServiceLifetime.Singleton)); - } + => services.Add(new ServiceDescriptor(typeof(TCollection), CreateCollection, ServiceLifetime.Singleton)); + + // used to resolve a Func> parameter + private Func> CreateItemsFactory() => () => _types; } } diff --git a/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs b/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs index d8b3e04772..0c6e6f0f68 100644 --- a/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs +++ b/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Composing; @@ -14,7 +15,7 @@ namespace Umbraco.Cms.Core.ContentApps private readonly ILogger _logger; private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - public ContentAppFactoryCollection(IEnumerable items, ILogger logger, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) + public ContentAppFactoryCollection(Func> items, ILogger logger, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) : base(items) { _logger = logger; diff --git a/src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs b/src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs index 3c35054e9b..ff1223d983 100644 --- a/src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs +++ b/src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.DependencyInjection; @@ -21,7 +21,9 @@ namespace Umbraco.Cms.Core.ContentApps // get the logger factory just-in-time - see note below for manifest parser var loggerFactory = factory.GetRequiredService(); var backOfficeSecurityAccessor = factory.GetRequiredService(); - return new ContentAppFactoryCollection(CreateItems(factory), loggerFactory.CreateLogger(), backOfficeSecurityAccessor); + return new ContentAppFactoryCollection( + () => CreateItems(factory), + loggerFactory.CreateLogger(), backOfficeSecurityAccessor); } protected override IEnumerable CreateItems(IServiceProvider factory) diff --git a/src/Umbraco.Core/Dashboards/DashboardCollection.cs b/src/Umbraco.Core/Dashboards/DashboardCollection.cs index 9fa13f1d3d..e5c8378139 100644 --- a/src/Umbraco.Core/Dashboards/DashboardCollection.cs +++ b/src/Umbraco.Core/Dashboards/DashboardCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Dashboards { public class DashboardCollection : BuilderCollectionBase { - public DashboardCollection(IEnumerable items) - : base(items) - { } + public DashboardCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Editors/EditorValidatorCollection.cs b/src/Umbraco.Core/Editors/EditorValidatorCollection.cs index 3b07be5553..91bc3e191b 100644 --- a/src/Umbraco.Core/Editors/EditorValidatorCollection.cs +++ b/src/Umbraco.Core/Editors/EditorValidatorCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Editors { public class EditorValidatorCollection : BuilderCollectionBase { - public EditorValidatorCollection(IEnumerable items) - : base(items) - { } + public EditorValidatorCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/HealthChecks/HealthCheckCollection.cs b/src/Umbraco.Core/HealthChecks/HealthCheckCollection.cs index 2987ff1112..bcbee9036b 100644 --- a/src/Umbraco.Core/HealthChecks/HealthCheckCollection.cs +++ b/src/Umbraco.Core/HealthChecks/HealthCheckCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.HealthChecks { public class HealthCheckCollection : BuilderCollectionBase { - public HealthCheckCollection(IEnumerable items) - : base(items) - { } + public HealthCheckCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/HealthChecks/HealthCheckNotificationMethodCollection.cs b/src/Umbraco.Core/HealthChecks/HealthCheckNotificationMethodCollection.cs index 7fa8486df6..af964857d8 100644 --- a/src/Umbraco.Core/HealthChecks/HealthCheckNotificationMethodCollection.cs +++ b/src/Umbraco.Core/HealthChecks/HealthCheckNotificationMethodCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.HealthChecks.NotificationMethods; @@ -6,8 +7,8 @@ namespace Umbraco.Cms.Core.HealthChecks { public class HealthCheckNotificationMethodCollection : BuilderCollectionBase { - public HealthCheckNotificationMethodCollection(IEnumerable items) - : base(items) - { } + public HealthCheckNotificationMethodCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs b/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs index 20a3468c36..9c692f69b3 100644 --- a/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs +++ b/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Manifest @@ -8,12 +9,9 @@ namespace Umbraco.Cms.Core.Manifest /// public class ManifestFilterCollection : BuilderCollectionBase { - /// - /// Initializes a new instance of the class. - /// - public ManifestFilterCollection(IEnumerable items) - : base(items) - { } + public ManifestFilterCollection(Func> items) : base(items) + { + } /// /// Filters package manifests. diff --git a/src/Umbraco.Core/Mapping/MapDefinitionCollection.cs b/src/Umbraco.Core/Mapping/MapDefinitionCollection.cs index d9cc08ad43..27d4ad73d0 100644 --- a/src/Umbraco.Core/Mapping/MapDefinitionCollection.cs +++ b/src/Umbraco.Core/Mapping/MapDefinitionCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Mapping { public class MapDefinitionCollection : BuilderCollectionBase { - public MapDefinitionCollection(IEnumerable items) - : base(items) - { } + public MapDefinitionCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollection.cs b/src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollection.cs index 490ff64357..615d16f51c 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollection.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Media.EmbedProviders { public class EmbedProvidersCollection : BuilderCollectionBase { - public EmbedProvidersCollection(IEnumerable items) - : base(items) - { } + public EmbedProvidersCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/PropertyEditors/DataEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/DataEditorCollection.cs index d4ddc21827..0c4ca93fc1 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditorCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.PropertyEditors { public class DataEditorCollection : BuilderCollectionBase { - public DataEditorCollection(IEnumerable items) - : base(items) - { } + public DataEditorCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs b/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs index 9a9efa5e2c..a83f925dd3 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; @@ -7,9 +7,9 @@ namespace Umbraco.Cms.Core.PropertyEditors { public class DataValueReferenceFactoryCollection : BuilderCollectionBase { - public DataValueReferenceFactoryCollection(IEnumerable items) - : base(items) - { } + public DataValueReferenceFactoryCollection(System.Func> items) : base(items) + { + } // TODO: We could further reduce circular dependencies with PropertyEditorCollection by not having IDataValueReference implemented // by property editors and instead just use the already built in IDataValueReferenceFactory and/or refactor that into a more normal collection diff --git a/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs b/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs index 45a2dc51bb..9e26362bc2 100644 --- a/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Composing; @@ -8,9 +8,9 @@ namespace Umbraco.Cms.Core.PropertyEditors { public class ManifestValueValidatorCollection : BuilderCollectionBase { - public ManifestValueValidatorCollection(IEnumerable items) - : base(items) - { } + public ManifestValueValidatorCollection(Func> items) : base(items) + { + } public IManifestValueValidator Create(string name) { diff --git a/src/Umbraco.Core/PropertyEditors/MediaUrlGeneratorCollection.cs b/src/Umbraco.Core/PropertyEditors/MediaUrlGeneratorCollection.cs index cd3a36c607..7e01f6b1cb 100644 --- a/src/Umbraco.Core/PropertyEditors/MediaUrlGeneratorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/MediaUrlGeneratorCollection.cs @@ -6,7 +6,7 @@ namespace Umbraco.Cms.Core.PropertyEditors { public class MediaUrlGeneratorCollection : BuilderCollectionBase { - public MediaUrlGeneratorCollection(IEnumerable items) : base(items) + public MediaUrlGeneratorCollection(System.Func> items) : base(items) { } diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs index 5ad20665f4..039de8cb6a 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Manifest; @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public class ParameterEditorCollection : BuilderCollectionBase { public ParameterEditorCollection(DataEditorCollection dataEditors, IManifestParser manifestParser) - : base(dataEditors + : base(() => dataEditors .Where(x => (x.Type & EditorType.MacroParameter) > 0) .Union(manifestParser.Manifest.PropertyEditors)) { } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs index e5b6e96c7b..4b551d3257 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs @@ -7,13 +7,13 @@ namespace Umbraco.Cms.Core.PropertyEditors public class PropertyEditorCollection : BuilderCollectionBase { public PropertyEditorCollection(DataEditorCollection dataEditors, IManifestParser manifestParser) - : base(dataEditors + : base(() => dataEditors .Where(x => (x.Type & EditorType.PropertyValue) > 0) .Union(manifestParser.Manifest.PropertyEditors)) { } public PropertyEditorCollection(DataEditorCollection dataEditors) - : base(dataEditors + : base(() => dataEditors .Where(x => (x.Type & EditorType.PropertyValue) > 0)) { } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterCollection.cs index 136967e7ab..a60ba4a6e5 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Composing; @@ -8,9 +8,9 @@ namespace Umbraco.Cms.Core.PropertyEditors { public class PropertyValueConverterCollection : BuilderCollectionBase { - public PropertyValueConverterCollection(IEnumerable items) - : base(items) - { } + public PropertyValueConverterCollection(Func> items) : base(items) + { + } private readonly object _locker = new object(); private Dictionary _defaultConverters; diff --git a/src/Umbraco.Core/Routing/ContentFinderCollection.cs b/src/Umbraco.Core/Routing/ContentFinderCollection.cs index d63c269f50..8965d9d447 100644 --- a/src/Umbraco.Core/Routing/ContentFinderCollection.cs +++ b/src/Umbraco.Core/Routing/ContentFinderCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Routing { public class ContentFinderCollection : BuilderCollectionBase { - public ContentFinderCollection(IEnumerable items) - : base(items) - { } + public ContentFinderCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Routing/MediaUrlProviderCollection.cs b/src/Umbraco.Core/Routing/MediaUrlProviderCollection.cs index 0ac0ae265e..264be41d60 100644 --- a/src/Umbraco.Core/Routing/MediaUrlProviderCollection.cs +++ b/src/Umbraco.Core/Routing/MediaUrlProviderCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Routing { public class MediaUrlProviderCollection : BuilderCollectionBase { - public MediaUrlProviderCollection(IEnumerable items) - : base(items) - { } + public MediaUrlProviderCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Routing/UrlProviderCollection.cs b/src/Umbraco.Core/Routing/UrlProviderCollection.cs index 4a383f82bf..c17417c83c 100644 --- a/src/Umbraco.Core/Routing/UrlProviderCollection.cs +++ b/src/Umbraco.Core/Routing/UrlProviderCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Routing { public class UrlProviderCollection : BuilderCollectionBase { - public UrlProviderCollection(IEnumerable items) - : base(items) - { } + public UrlProviderCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Sections/SectionCollection.cs b/src/Umbraco.Core/Sections/SectionCollection.cs index a93b36a161..5ff0157d14 100644 --- a/src/Umbraco.Core/Sections/SectionCollection.cs +++ b/src/Umbraco.Core/Sections/SectionCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Sections { public class SectionCollection : BuilderCollectionBase { - public SectionCollection(IEnumerable items) - : base(items) - { } + public SectionCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Strings/UrlSegmentProviderCollection.cs b/src/Umbraco.Core/Strings/UrlSegmentProviderCollection.cs index 7307c8964a..551efc475a 100644 --- a/src/Umbraco.Core/Strings/UrlSegmentProviderCollection.cs +++ b/src/Umbraco.Core/Strings/UrlSegmentProviderCollection.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Strings { public class UrlSegmentProviderCollection : BuilderCollectionBase { - public UrlSegmentProviderCollection(IEnumerable items) - : base(items) - { } + public UrlSegmentProviderCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Tour/TourFilterCollection.cs b/src/Umbraco.Core/Tour/TourFilterCollection.cs index 5c55d0e0cd..2864abbced 100644 --- a/src/Umbraco.Core/Tour/TourFilterCollection.cs +++ b/src/Umbraco.Core/Tour/TourFilterCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Tour @@ -8,11 +9,8 @@ namespace Umbraco.Cms.Core.Tour /// public class TourFilterCollection : BuilderCollectionBase { - /// - /// Initializes a new instance of the class. - /// - public TourFilterCollection(IEnumerable items) - : base(items) - { } + public TourFilterCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/Trees/SearchableTreeCollection.cs b/src/Umbraco.Core/Trees/SearchableTreeCollection.cs index 8f1b20a7b1..ff42b5e8c3 100644 --- a/src/Umbraco.Core/Trees/SearchableTreeCollection.cs +++ b/src/Umbraco.Core/Trees/SearchableTreeCollection.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Trees { private readonly Dictionary _dictionary; - public SearchableTreeCollection(IEnumerable items, ITreeService treeService) + public SearchableTreeCollection(Func> items, ITreeService treeService) : base(items) { _dictionary = CreateDictionary(treeService); diff --git a/src/Umbraco.Core/Trees/TreeCollection.cs b/src/Umbraco.Core/Trees/TreeCollection.cs index 45a405217f..59fa99819c 100644 --- a/src/Umbraco.Core/Trees/TreeCollection.cs +++ b/src/Umbraco.Core/Trees/TreeCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Trees @@ -8,8 +9,9 @@ namespace Umbraco.Cms.Core.Trees /// public class TreeCollection : BuilderCollectionBase { - public TreeCollection(IEnumerable items) - : base(items) - { } + + public TreeCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/UmbracoApiControllerTypeCollection.cs b/src/Umbraco.Core/UmbracoApiControllerTypeCollection.cs index 9ff5073d17..66ad608881 100644 --- a/src/Umbraco.Core/UmbracoApiControllerTypeCollection.cs +++ b/src/Umbraco.Core/UmbracoApiControllerTypeCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Umbraco.Cms.Core.Composing; @@ -6,8 +6,8 @@ namespace Umbraco.Cms.Core { public class UmbracoApiControllerTypeCollection : BuilderCollectionBase { - public UmbracoApiControllerTypeCollection(IEnumerable items) - : base(items) - { } + public UmbracoApiControllerTypeCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Core/WebAssets/CustomBackOfficeAssetsCollection.cs b/src/Umbraco.Core/WebAssets/CustomBackOfficeAssetsCollection.cs index 8648a59d32..2595afe40e 100644 --- a/src/Umbraco.Core/WebAssets/CustomBackOfficeAssetsCollection.cs +++ b/src/Umbraco.Core/WebAssets/CustomBackOfficeAssetsCollection.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Umbraco.Cms.Core.Composing; @@ -5,8 +6,8 @@ namespace Umbraco.Cms.Core.WebAssets { public class CustomBackOfficeAssetsCollection : BuilderCollectionBase { - public CustomBackOfficeAssetsCollection(IEnumerable items) - : base(items) - { } + public CustomBackOfficeAssetsCollection(Func> items) : base(items) + { + } } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs index 5f9d87269d..ca4ec9bfe1 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorCollection.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Composing; @@ -9,11 +11,10 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes { private readonly ILogger _logger; - public PreValueMigratorCollection(IEnumerable items, ILogger logger) + public PreValueMigratorCollection(Func> items, ILogger logger) : base(items) { _logger = logger; - _logger.LogDebug("Migrators: " + string.Join(", ", items.Select(x => x.GetType().Name))); } public IPreValueMigrator GetMigrator(string editorAlias) diff --git a/src/Umbraco.Infrastructure/Packaging/PackageMigrationPlanCollection.cs b/src/Umbraco.Infrastructure/Packaging/PackageMigrationPlanCollection.cs index 2a17add2e6..aa390dcaa4 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageMigrationPlanCollection.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageMigrationPlanCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Core.Packaging @@ -8,7 +9,7 @@ namespace Umbraco.Cms.Core.Packaging /// public class PackageMigrationPlanCollection : BuilderCollectionBase { - public PackageMigrationPlanCollection(IEnumerable items) : base(items) + public PackageMigrationPlanCollection(Func> items) : base(items) { } } diff --git a/src/Umbraco.Infrastructure/Persistence/DbProviderFactoryCreator.cs b/src/Umbraco.Infrastructure/Persistence/DbProviderFactoryCreator.cs index 8814c01761..797400b7cc 100644 --- a/src/Umbraco.Infrastructure/Persistence/DbProviderFactoryCreator.cs +++ b/src/Umbraco.Infrastructure/Persistence/DbProviderFactoryCreator.cs @@ -1,8 +1,9 @@ -using System; +using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using NPoco; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; namespace Umbraco.Cms.Infrastructure.Persistence @@ -73,7 +74,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence return mapperFactory.Mappers; } - return new NPocoMapperCollection(Array.Empty()); + return new NPocoMapperCollection(() => Enumerable.Empty()); } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Mappers/MapperCollection.cs b/src/Umbraco.Infrastructure/Persistence/Mappers/MapperCollection.cs index a719308443..feaacd714b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Mappers/MapperCollection.cs +++ b/src/Umbraco.Infrastructure/Persistence/Mappers/MapperCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using Umbraco.Cms.Core.Composing; @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Mappers { public class MapperCollection : BuilderCollectionBase, IMapperCollection { - public MapperCollection(IEnumerable items) + public MapperCollection(Func> items) : base(items) { diff --git a/src/Umbraco.Infrastructure/Persistence/NPocoMapperCollection.cs b/src/Umbraco.Infrastructure/Persistence/NPocoMapperCollection.cs index a1b61198d3..3d71c0225e 100644 --- a/src/Umbraco.Infrastructure/Persistence/NPocoMapperCollection.cs +++ b/src/Umbraco.Infrastructure/Persistence/NPocoMapperCollection.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using NPoco; using Umbraco.Cms.Core.Composing; @@ -6,7 +7,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence { public sealed class NPocoMapperCollection : BuilderCollectionBase { - public NPocoMapperCollection(IEnumerable items) : base(items) + public NPocoMapperCollection(Func> items) : base(items) { } } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 2055006415..c72e11f595 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -37,7 +37,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement where TEntity : class, IContentBase where TRepository : class, IRepository { - private readonly Lazy _propertyEditors; private readonly DataValueReferenceFactoryCollection _dataValueReferenceFactories; private readonly IEventAggregator _eventAggregator; @@ -58,7 +57,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement ILanguageRepository languageRepository, IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, - Lazy propertyEditors, + PropertyEditorCollection propertyEditors, DataValueReferenceFactoryCollection dataValueReferenceFactories, IDataTypeService dataTypeService, IEventAggregator eventAggregator) @@ -68,7 +67,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement LanguageRepository = languageRepository; RelationRepository = relationRepository; RelationTypeRepository = relationTypeRepository; - _propertyEditors = propertyEditors; + PropertyEditors = propertyEditors; _dataValueReferenceFactories = dataValueReferenceFactories; _eventAggregator = eventAggregator; } @@ -85,7 +84,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement protected IRelationRepository RelationRepository { get; } protected IRelationTypeRepository RelationTypeRepository { get; } - protected PropertyEditorCollection PropertyEditors => _propertyEditors.Value; + protected PropertyEditorCollection PropertyEditors { get; } #region Versions diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs index 001f2db000..f70048c4f9 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs @@ -29,14 +29,14 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement /// internal class DataTypeRepository : EntityRepositoryBase, IDataTypeRepository { - private readonly Lazy _editors; + private readonly PropertyEditorCollection _editors; private readonly IConfigurationEditorJsonSerializer _serializer; private readonly ILogger _dataTypeLogger; public DataTypeRepository( IScopeAccessor scopeAccessor, AppCaches cache, - Lazy editors, + PropertyEditorCollection editors, ILogger logger, ILoggerFactory loggerFactory, IConfigurationEditorJsonSerializer serializer) @@ -68,7 +68,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement } var dtos = Database.Fetch(dataTypeSql); - return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, _dataTypeLogger, _serializer)).ToArray(); + return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors, _dataTypeLogger, _serializer)).ToArray(); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -79,7 +79,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement var dtos = Database.Fetch(sql); - return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, _dataTypeLogger, _serializer)).ToArray(); + return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors, _dataTypeLogger, _serializer)).ToArray(); } #endregion diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs index 828c521f93..79663c292e 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Events; @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement ILanguageRepository languageRepository, IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, - Lazy propertyEditorCollection, + PropertyEditorCollection propertyEditorCollection, IDataTypeService dataTypeService, DataValueReferenceFactoryCollection dataValueReferenceFactories, IJsonSerializer serializer, diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs index b246839440..b4a4599d14 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs @@ -64,7 +64,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement ILanguageRepository languageRepository, IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, - Lazy propertyEditors, + PropertyEditorCollection propertyEditors, DataValueReferenceFactoryCollection dataValueReferenceFactories, IDataTypeService dataTypeService, IJsonSerializer serializer, diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs index b69907d71b..cc188787ba 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement ILanguageRepository languageRepository, IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, - Lazy propertyEditorCollection, + PropertyEditorCollection propertyEditorCollection, MediaUrlGeneratorCollection mediaUrlGenerators, DataValueReferenceFactoryCollection dataValueReferenceFactories, IDataTypeService dataTypeService, diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs index 698d0fffa7..cc1ce7aec0 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, IPasswordHasher passwordHasher, - Lazy propertyEditors, + PropertyEditorCollection propertyEditors, DataValueReferenceFactoryCollection dataValueReferenceFactories, IDataTypeService dataTypeService, IJsonSerializer serializer, diff --git a/src/Umbraco.Infrastructure/Persistence/SqlContext.cs b/src/Umbraco.Infrastructure/Persistence/SqlContext.cs index e1ced4f375..f1f3233a45 100644 --- a/src/Umbraco.Infrastructure/Persistence/SqlContext.cs +++ b/src/Umbraco.Infrastructure/Persistence/SqlContext.cs @@ -1,6 +1,7 @@ -using System; +using System; using System.Linq; using NPoco; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Infrastructure.Persistence.Mappers; using Umbraco.Cms.Infrastructure.Persistence.Querying; @@ -14,8 +15,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence /// public class SqlContext : ISqlContext { - private readonly Lazy _mappers; - /// /// Initializes a new instance of the class. /// @@ -23,21 +22,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence /// The Poco data factory. /// The database type. /// The mappers. - public SqlContext(ISqlSyntaxProvider sqlSyntax, DatabaseType databaseType, IPocoDataFactory pocoDataFactory, IMapperCollection mappers = null) - : this(sqlSyntax, databaseType, pocoDataFactory, new Lazy(() => mappers ?? new MapperCollection(Enumerable.Empty()))) - { } - - /// - /// Initializes a new instance of the class. - /// - /// The sql syntax provider. - /// The Poco data factory. - /// The database type. - /// The mappers. - public SqlContext(ISqlSyntaxProvider sqlSyntax, DatabaseType databaseType, IPocoDataFactory pocoDataFactory, Lazy mappers) + public SqlContext(ISqlSyntaxProvider sqlSyntax, DatabaseType databaseType, IPocoDataFactory pocoDataFactory, IMapperCollection mappers = null) { // for tests - _mappers = mappers; + Mappers = mappers; SqlSyntax = sqlSyntax ?? throw new ArgumentNullException(nameof(sqlSyntax)); PocoDataFactory = pocoDataFactory ?? throw new ArgumentNullException(nameof(pocoDataFactory)); @@ -67,6 +55,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence public IPocoDataFactory PocoDataFactory { get; } /// - public IMapperCollection Mappers => _mappers.Value; + public IMapperCollection Mappers { get; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/SqlServerDbProviderFactoryCreator.cs b/src/Umbraco.Infrastructure/Persistence/SqlServerDbProviderFactoryCreator.cs index c6c0c6b0bb..756490c531 100644 --- a/src/Umbraco.Infrastructure/Persistence/SqlServerDbProviderFactoryCreator.cs +++ b/src/Umbraco.Infrastructure/Persistence/SqlServerDbProviderFactoryCreator.cs @@ -1,7 +1,9 @@ -using System; +using System; using System.Data.Common; +using System.Linq; using Microsoft.Extensions.Options; using NPoco; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; @@ -49,10 +51,9 @@ namespace Umbraco.Cms.Infrastructure.Persistence } public void CreateDatabase(string providerName) - { - throw new NotSupportedException("Embedded databases are not supported"); - } + => throw new NotSupportedException("Embedded databases are not supported"); - public NPocoMapperCollection ProviderSpecificMappers(string providerName) => new NPocoMapperCollection(Array.Empty()); + public NPocoMapperCollection ProviderSpecificMappers(string providerName) + => new NPocoMapperCollection(() => Enumerable.Empty()); } } diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index 0f973101e3..03977a0abe 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence private readonly DatabaseSchemaCreatorFactory _databaseSchemaCreatorFactory; private readonly NPocoMapperCollection _npocoMappers; private readonly IOptions _globalSettings; - private readonly Lazy _mappers; + private readonly IMapperCollection _mappers; private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; @@ -81,7 +81,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence ILoggerFactory loggerFactory, IOptions globalSettings, IOptions connectionStrings, - Lazy mappers, + IMapperCollection mappers, IDbProviderFactoryCreator dbProviderFactoryCreator, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, NPocoMapperCollection npocoMappers) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs index 49cc6b2902..550a64b14d 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System; @@ -26,18 +26,14 @@ namespace Umbraco.Cms.Core.PropertyEditors { public const string ContentTypeKeyPropertyKey = "contentTypeKey"; public const string UdiPropertyKey = "udi"; - private readonly Lazy _propertyEditors; public BlockEditorPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, - Lazy propertyEditors) + PropertyEditorCollection propertyEditors) : base(dataValueEditorFactory) - { - _propertyEditors = propertyEditors; - } + => PropertyEditors = propertyEditors; - // has to be lazy else circular dep in ctor - private PropertyEditorCollection PropertyEditors => _propertyEditors.Value; + private PropertyEditorCollection PropertyEditors { get; } #region Value Editor diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs index 469d908cb3..0955aa5198 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System; @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public BlockListPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, - Lazy propertyEditors, + PropertyEditorCollection propertyEditors, IIOHelper ioHelper) : base(dataValueEditorFactory, propertyEditors) { diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index dc25007e7c..f206e063a3 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NPoco; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Runtime; @@ -61,7 +62,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime loggerFactory, _globalSettings, connectionStrings, - new Lazy(() => new MapperCollection(Enumerable.Empty())), + new MapperCollection(() => Enumerable.Empty()), dbProviderFactoryCreator, databaseSchemaCreatorFactory, npocoMappers); diff --git a/src/Umbraco.Persistence.SqlCe/SqlCeSpecificMapperFactory.cs b/src/Umbraco.Persistence.SqlCe/SqlCeSpecificMapperFactory.cs index 0e53561929..3646218fce 100644 --- a/src/Umbraco.Persistence.SqlCe/SqlCeSpecificMapperFactory.cs +++ b/src/Umbraco.Persistence.SqlCe/SqlCeSpecificMapperFactory.cs @@ -1,4 +1,4 @@ -using Umbraco.Cms.Core; +using Umbraco.Cms.Core; using Umbraco.Cms.Infrastructure.Persistence; namespace Umbraco.Cms.Persistence.SqlCe @@ -6,6 +6,6 @@ namespace Umbraco.Cms.Persistence.SqlCe public class SqlCeSpecificMapperFactory : IProviderSpecificMapperFactory { public string ProviderName => Constants.DatabaseProviders.SqlCe; - public NPocoMapperCollection Mappers => new NPocoMapperCollection(new[] {new SqlCeImageMapper()}); + public NPocoMapperCollection Mappers => new NPocoMapperCollection(() => new[] {new SqlCeImageMapper()}); } } diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs index 5d546cb8d5..b36f7e90d1 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Moq; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PropertyEditors; @@ -34,7 +35,7 @@ namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent }; dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield); - var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeServiceMock.Object); + var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(() => Enumerable.Empty()), dataTypeServiceMock.Object); Default = factory.CreatePropertyType("*", 666); } diff --git a/src/Umbraco.Tests.Integration/Testing/TestUmbracoDatabaseFactoryProvider.cs b/src/Umbraco.Tests.Integration/Testing/TestUmbracoDatabaseFactoryProvider.cs index 344a616e76..8d702e82d8 100644 --- a/src/Umbraco.Tests.Integration/Testing/TestUmbracoDatabaseFactoryProvider.cs +++ b/src/Umbraco.Tests.Integration/Testing/TestUmbracoDatabaseFactoryProvider.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing private readonly ILoggerFactory _loggerFactory; private readonly IOptions _globalSettings; private readonly IOptions _connectionStrings; - private readonly Lazy _mappers; + private readonly IMapperCollection _mappers; private readonly IDbProviderFactoryCreator _dbProviderFactoryCreator; private readonly DatabaseSchemaCreatorFactory _databaseSchemaCreatorFactory; private readonly NPocoMapperCollection _npocoMappers; @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing ILoggerFactory loggerFactory, IOptions globalSettings, IOptions connectionStrings, - Lazy mappers, + IMapperCollection mappers, IDbProviderFactoryCreator dbProviderFactoryCreator, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, NPocoMapperCollection npocoMappers) diff --git a/src/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexInitializer.cs b/src/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexInitializer.cs index c0a1b1700c..987ba90070 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexInitializer.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexInitializer.cs @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine { var contentValueSetBuilder = new ContentValueSetBuilder( _propertyEditors, - new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(_shortStringHelper) }), + new UrlSegmentProviderCollection(() => new[] { new DefaultUrlSegmentProvider(_shortStringHelper) }), GetMockUserService(), _shortStringHelper, _scopeProvider, @@ -85,7 +85,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine { var mediaValueSetBuilder = new MediaValueSetBuilder( _propertyEditors, - new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(_shortStringHelper) }), + new UrlSegmentProviderCollection(() => new[] { new DefaultUrlSegmentProvider(_shortStringHelper) }), _mediaUrlGenerators, GetMockUserService(), _shortStringHelper, diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs index 8cf2c8c932..a7e1641839 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs @@ -10,6 +10,7 @@ using Moq; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.IO; @@ -99,8 +100,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos appCaches ??= AppCaches; DocumentRepository ctRepository = CreateRepository(scopeAccessor, out contentTypeRepository, out TemplateRepository tr); - var editors = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty())); - dtdRepository = new DataTypeRepository(scopeAccessor, appCaches, new Lazy(() => editors), LoggerFactory.CreateLogger(), LoggerFactory, ConfigurationEditorJsonSerializer); + var editors = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty())); + dtdRepository = new DataTypeRepository(scopeAccessor, appCaches, editors, LoggerFactory.CreateLogger(), LoggerFactory, ConfigurationEditorJsonSerializer); return ctRepository; } @@ -121,8 +122,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger()); var entityRepository = new EntityRepository(scopeAccessor, AppCaches.Disabled); var relationRepository = new RelationRepository(scopeAccessor, LoggerFactory.CreateLogger(), relationTypeRepository, entityRepository); - var propertyEditors = new Lazy(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty()))); - var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty()); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty())); + var dataValueReferences = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); var repository = new DocumentRepository( scopeAccessor, appCaches, @@ -775,7 +776,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // One variant (by culture) content type named "umbVariantTextPage" // with properties, every 2nd one being variant (by culture), the other being invariant - ContentType variantCt = ContentTypeBuilder.CreateSimpleContentType("umbVariantTextpage", "Variant Textpage", defaultTemplateId: template.Id); + ContentType variantCt = ContentTypeBuilder.CreateSimpleContentType("umbVariantTextpage", "Variant Textpage", defaultTemplateId: template.Id); variantCt.Variations = ContentVariation.Culture; var propTypes = variantCt.PropertyTypes.ToList(); for (int i = 0; i < propTypes.Count; i++) diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs index 2d7e6937ec..fc98b8ef10 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs @@ -9,6 +9,7 @@ using Moq; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; @@ -63,9 +64,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger()); var entityRepository = new EntityRepository(scopeAccessor, AppCaches.Disabled); var relationRepository = new RelationRepository(scopeAccessor, LoggerFactory.CreateLogger(), relationTypeRepository, entityRepository); - var propertyEditors = new Lazy(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty()))); - var mediaUrlGenerators = new MediaUrlGeneratorCollection(Enumerable.Empty()); - var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty()); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty())); + var mediaUrlGenerators = new MediaUrlGeneratorCollection(() => Enumerable.Empty()); + var dataValueReferences = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); var repository = new MediaRepository(scopeAccessor, appCaches, LoggerFactory.CreateLogger(), LoggerFactory, mediaTypeRepository, tagRepository, Mock.Of(), relationRepository, relationTypeRepository, propertyEditors, mediaUrlGenerators, dataValueReferences, DataTypeService, JsonSerializer, Mock.Of()); return repository; } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs index 57d64638fb..d8bf4be14a 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs @@ -12,6 +12,7 @@ using NPoco; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; @@ -55,8 +56,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos ITagRepository tagRepo = GetRequiredService(); IRelationTypeRepository relationTypeRepository = GetRequiredService(); IRelationRepository relationRepository = GetRequiredService(); - var propertyEditors = new Lazy(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty()))); - var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty()); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty())); + var dataValueReferences = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); return new MemberRepository( accessor, AppCaches.Disabled, diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs index f9587179dd..d137ef8d05 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs @@ -11,6 +11,7 @@ using Moq; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Hosting; @@ -267,8 +268,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var relationTypeRepository = new RelationTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger()); var entityRepository = new EntityRepository(scopeAccessor, AppCaches.Disabled); var relationRepository = new RelationRepository(scopeAccessor, LoggerFactory.CreateLogger(), relationTypeRepository, entityRepository); - var propertyEditors = new Lazy(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty()))); - var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty()); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => Enumerable.Empty())); + var dataValueReferences = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); var contentRepo = new DocumentRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger(), LoggerFactory, contentTypeRepository, templateRepository, tagRepository, languageRepository, relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, dataTypeService, serializer, Mock.Of()); Template template = TemplateBuilder.CreateTextPageTemplate(); diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs index 2d81228257..eb10bb010a 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs @@ -8,6 +8,7 @@ using System.Threading; using NPoco; using NUnit.Framework; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Models.Membership; @@ -107,7 +108,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services member = MemberService.GetById(member.Id); Assert.AreEqual("xemail", member.Email); - var contentTypeFactory = new PublishedContentTypeFactory(new NoopPublishedModelFactory(), new PropertyValueConverterCollection(Enumerable.Empty()), GetRequiredService()); + var contentTypeFactory = new PublishedContentTypeFactory(new NoopPublishedModelFactory(), new PropertyValueConverterCollection(() => Enumerable.Empty()), GetRequiredService()); var pmemberType = new PublishedContentType(memberType, contentTypeFactory); var publishedSnapshotAccessor = new TestPublishedSnapshotAccessor(); diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index 3e728a96c9..178d480102 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -2,6 +2,7 @@ // See LICENSE for more details. using System; +using System.Linq; using AutoFixture; using AutoFixture.AutoMoq; using AutoFixture.Kernel; @@ -11,6 +12,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using Moq; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Hosting; @@ -74,7 +76,7 @@ namespace Umbraco.Cms.Tests.UnitTests.AutoFixture Options.Create(new GlobalSettings()), Mock.Of(x => x.ToAbsolute(It.IsAny()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty), Mock.Of(x => x.Level == RuntimeLevel.Run), - new UmbracoApiControllerTypeCollection(Array.Empty())))); + new UmbracoApiControllerTypeCollection(() => Enumerable.Empty())))); fixture.Customize(u => u.FromFactory( () => new PreviewRoutes( diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs index db739d9369..023c9ad952 100644 --- a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs +++ b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs @@ -47,7 +47,7 @@ namespace Umbraco.Cms.Tests.UnitTests.TestHelpers }; var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init()); var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); - SqlContext = new SqlContext(sqlSyntax, DatabaseType.SqlServer2012, pocoDataFactory, new Lazy(() => factory.GetRequiredService())); + SqlContext = new SqlContext(sqlSyntax, DatabaseType.SqlServer2012, pocoDataFactory, factory.GetRequiredService()); Mappers = factory.GetRequiredService(); } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs index 0273690f09..7397e06d1d 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache.DistributedCache ServerRegistrar = new TestServerRegistrar(); ServerMessenger = new TestServerMessenger(); - var cacheRefresherCollection = new CacheRefresherCollection(new[] + var cacheRefresherCollection = new CacheRefresherCollection(() => new[] { new TestCacheRefresher() }); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs index 71498bfba8..0c9b94a978 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs @@ -49,13 +49,13 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Components ILogger logger = loggerFactory.CreateLogger("GenericLogger"); var globalSettings = new GlobalSettings(); var connectionStrings = new ConnectionStrings(); - var mapperCollection = new NPocoMapperCollection(new[] { new NullableDateMapper() }); + var mapperCollection = new NPocoMapperCollection(() => new[] { new NullableDateMapper() }); var f = new UmbracoDatabaseFactory( loggerFactory.CreateLogger(), loggerFactory, Options.Create(globalSettings), Options.Create(connectionStrings), - new Lazy(() => new MapperCollection(Enumerable.Empty())), + new MapperCollection(() => Enumerable.Empty()), TestHelper.DbProviderFactoryCreator, new DatabaseSchemaCreatorFactory(loggerFactory.CreateLogger(), loggerFactory, new UmbracoVersion(), Mock.Of()), mapperCollection); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs index 5fe93ecf42..ad9a19b3f8 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs @@ -537,8 +537,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Composing // ReSharper disable once ClassNeverInstantiated.Local private class TestCollection : BuilderCollectionBase { - public TestCollection(IEnumerable items) - : base(items) + public TestCollection(Func> items) : base(items) { } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs index 0a45415647..ec36e1c670 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs @@ -184,8 +184,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Composing // ReSharper disable once ClassNeverInstantiated.Local private class TestCollection : BuilderCollectionBase { - public TestCollection(IEnumerable items) - : base(items) + public TestCollection(Func> items) : base(items) { } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs index 93c8e21eed..c93e5087b7 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs @@ -12,6 +12,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NUnit.Framework; using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Dashboards; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Manifest; @@ -44,8 +45,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Manifest NullLoggerFactory loggerFactory = NullLoggerFactory.Instance; _parser = new ManifestParser( AppCaches.Disabled, - new ManifestValueValidatorCollection(validators), - new ManifestFilterCollection(Array.Empty()), + new ManifestValueValidatorCollection(() => validators), + new ManifestFilterCollection(() => Enumerable.Empty()), loggerFactory.CreateLogger(), _ioHelper, TestHelper.GetHostingEnvironment(), diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs index 4c0853aaf0..892ef696c3 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs @@ -599,7 +599,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models Mock.Get(dataTypeService).Setup(x => x.GetDataType(It.Is(y => y == Constants.DataTypes.Textbox))) .Returns(new DataType(textBoxEditor, serializer)); - var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(new[] { textBoxEditor })); + var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(() => new[] { textBoxEditor })); return new PropertyValidationService( propertyEditorCollection, dataTypeService, diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PendingPackageMigrationsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PendingPackageMigrationsTests.cs index d726cf32f8..119b95d545 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PendingPackageMigrationsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PendingPackageMigrationsTests.cs @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Packaging private PendingPackageMigrations GetPendingPackageMigrations() => new PendingPackageMigrations( Mock.Of>(), - new PackageMigrationPlanCollection(new[] + new PackageMigrationPlanCollection(() => new[] { new TestPackageMigrationPlan() })); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs index 86496fdead..944b35023f 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Moq; using NUnit.Framework; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; @@ -36,13 +37,13 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors [Test] public void GetAllReferences_All_Variants_With_IDataValueReferenceFactory() { - var collection = new DataValueReferenceFactoryCollection(new TestDataValueReferenceFactory().Yield()); + var collection = new DataValueReferenceFactoryCollection(() => new TestDataValueReferenceFactory().Yield()); // label does not implement IDataValueReference var labelEditor = new LabelPropertyEditor( DataValueEditorFactory, IOHelper); - var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(labelEditor.Yield())); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => labelEditor.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi3 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); @@ -102,13 +103,13 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors [Test] public void GetAllReferences_All_Variants_With_IDataValueReference_Editor() { - var collection = new DataValueReferenceFactoryCollection(Enumerable.Empty()); + var collection = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); // mediaPicker does implement IDataValueReference var mediaPicker = new MediaPickerPropertyEditor( DataValueEditorFactory, IOHelper); - var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(mediaPicker.Yield())); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => mediaPicker.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi3 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); @@ -168,13 +169,13 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors [Test] public void GetAllReferences_Invariant_With_IDataValueReference_Editor() { - var collection = new DataValueReferenceFactoryCollection(Enumerable.Empty()); + var collection = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); // mediaPicker does implement IDataValueReference var mediaPicker = new MediaPickerPropertyEditor( DataValueEditorFactory, IOHelper); - var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(mediaPicker.Yield())); + var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => mediaPicker.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi3 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs index 06d34a8fa1..f6edb2a105 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs @@ -102,7 +102,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors var publishedPropType = new PublishedPropertyType( new PublishedContentType(Guid.NewGuid(), 1234, "test", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing), new PropertyType(Mock.Of(), "test", ValueStorageType.Nvarchar) { DataTypeId = 123 }, - new PropertyValueConverterCollection(Enumerable.Empty()), + new PropertyValueConverterCollection(() => Enumerable.Empty()), Mock.Of(), mockPublishedContentTypeFactory.Object); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs index e73d29f251..76a536c2e0 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published [Test] public void SimpleConverter1Test() { - var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] + var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { new SimpleConverter1(), }); @@ -107,7 +107,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot).Returns(publishedSnapshotMock.Object); IPublishedSnapshotAccessor publishedSnapshotAccessor = publishedSnapshotAccessorMock.Object; - var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] + var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { new SimpleConverter2(publishedSnapshotAccessor), }); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs index daa3dbdab2..5f5de0cf4e 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published PropertyEditorCollection editors = null; var editor = new NestedContentPropertyEditor(Mock.Of(),Mock.Of()); - editors = new PropertyEditorCollection(new DataEditorCollection(new DataEditor[] { editor })); + editors = new PropertyEditorCollection(new DataEditorCollection(() => new DataEditor[] { editor })); var serializer = new ConfigurationEditorJsonSerializer(); @@ -126,7 +126,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published .Setup(x => x.PublishedSnapshot) .Returns(publishedSnapshot.Object); - var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] + var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { new NestedContentSingleValueConverter(publishedSnapshotAccessor.Object, publishedModelFactory.Object, proflog), new NestedContentManyValueConverter(publishedSnapshotAccessor.Object, publishedModelFactory.Object, proflog), diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/PropertyCacheLevelTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/PropertyCacheLevelTests.cs index edb8cd17ee..a57355afd9 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/PropertyCacheLevelTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/PropertyCacheLevelTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published { var converter = new CacheConverter1(cacheLevel); - var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] + var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { converter, }); @@ -119,7 +119,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published { var converter = new CacheConverter1(converterCacheLevel); - var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] + var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { converter, }); @@ -199,7 +199,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published { var converter = new CacheConverter1(PropertyCacheLevel.Unknown); - var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] + var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { converter, }); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlImageSourceParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlImageSourceParserTests.cs index ba338cdf31..4d0e643d7f 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlImageSourceParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlImageSourceParserTests.cs @@ -82,8 +82,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Templates var publishedUrlProvider = new UrlProvider( umbracoContextAccessor, Options.Create(webRoutingSettings), - new UrlProviderCollection(Enumerable.Empty()), - new MediaUrlProviderCollection(new[] { mediaUrlProvider.Object }), + new UrlProviderCollection(() => Enumerable.Empty()), + new MediaUrlProviderCollection(() => new[] { mediaUrlProvider.Object }), Mock.Of()); using (UmbracoContextReference reference = umbracoContextFactory.EnsureUmbracoContext()) { diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlLocalLinkParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlLocalLinkParserTests.cs index b3c4d96328..670f528bbd 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlLocalLinkParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Templates/HtmlLocalLinkParserTests.cs @@ -79,8 +79,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Templates var publishedUrlProvider = new UrlProvider( umbracoContextAccessor, Microsoft.Extensions.Options.Options.Create(webRoutingSettings), - new UrlProviderCollection(new[] { contentUrlProvider.Object }), - new MediaUrlProviderCollection(new[] { mediaUrlProvider.Object }), + new UrlProviderCollection(() => new[] { contentUrlProvider.Object }), + new MediaUrlProviderCollection(() => new[] { mediaUrlProvider.Object }), Mock.Of()); using (UmbracoContextReference reference = umbracoContextFactory.EnsureUmbracoContext()) { diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/HealthCheckNotifierTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/HealthCheckNotifierTests.cs index 60c0a7476a..f128d49128 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/HealthCheckNotifierTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/HealthCheckNotifierTests.cs @@ -124,7 +124,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices new DisabledHealthCheckSettings { Id = Guid.Parse(Check2Id) } } }; - var checks = new HealthCheckCollection(new List + var checks = new HealthCheckCollection(() => new List { new TestHealthCheck1(), new TestHealthCheck2(), @@ -133,7 +133,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices _mockNotificationMethod = new Mock(); _mockNotificationMethod.SetupGet(x => x.Enabled).Returns(notificationEnabled); - var notifications = new HealthCheckNotificationMethodCollection(new List { _mockNotificationMethod.Object }); + var notifications = new HealthCheckNotificationMethodCollection(() => new List { _mockNotificationMethod.Object }); var mockRunTimeState = new Mock(); mockRunTimeState.SetupGet(x => x.Level).Returns(runtimeLevel); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs index 0db64a6ec9..9c8f9da75d 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Test] public void SimpleMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition1(), }); @@ -67,7 +67,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Test] public void EnumerableMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition1(), }); @@ -101,7 +101,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Test] public void InheritedMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition1(), }); @@ -126,7 +126,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Test] public void CollectionsMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition2(), }); @@ -141,7 +141,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Explicit] public void ConcurrentMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition1(), new MapperDefinition3(), @@ -201,7 +201,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Test] public void EnumMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition4(), }); @@ -225,7 +225,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping [Test] public void NullPropertyMap() { - var definitions = new MapDefinitionCollection(new IMapDefinition[] + var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition5(), }); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberManagerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberManagerTests.cs index c8f90050e2..fabe1f3a0c 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberManagerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberManagerTests.cs @@ -49,7 +49,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Security _fakeMemberStore = new MemberUserStore( _mockMemberService.Object, - new UmbracoMapper(new MapDefinitionCollection(mapDefinitions), scopeProvider), + new UmbracoMapper(new MapDefinitionCollection(() => mapDefinitions), scopeProvider), scopeProvider, new IdentityErrorDescriber(), Mock.Of()); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs index 3fdb3c27f9..96d25d4d04 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Security return new MemberUserStore( _mockMemberService.Object, - new UmbracoMapper(new MapDefinitionCollection(new List()), mockScopeProvider.Object), + new UmbracoMapper(new MapDefinitionCollection(() => new List()), mockScopeProvider.Object), mockScopeProvider.Object, new IdentityErrorDescriber(), Mock.Of()); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs index dc70e1e8ce..bfbe6258cc 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs @@ -43,7 +43,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Services Mock.Get(dataEditor).Setup(x => x.GetValueEditor(It.IsAny())) .Returns(new CustomTextOnlyValueEditor(new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox"), textService.Object, Mock.Of(), new JsonNetSerializer(), Mock.Of())); - var propEditors = new PropertyEditorCollection(new DataEditorCollection(new[] { dataEditor })); + var propEditors = new PropertyEditorCollection(new DataEditorCollection(() => new[] { dataEditor })); validationService = new PropertyValidationService(propEditors, dataTypeService.Object, Mock.Of()); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs index 8006bda3a4..cde267d7dc 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs @@ -453,7 +453,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers var mockContentAppFactoryCollection = new Mock>(); var hybridBackOfficeSecurityAccessor = new BackOfficeSecurityAccessor(httpContextAccessor); var contentAppFactoryCollection = new ContentAppFactoryCollection( - contentAppFactories.Object, + () => contentAppFactories.Object, mockContentAppFactoryCollection.Object, hybridBackOfficeSecurityAccessor); var mockUserService = new Mock(); @@ -471,7 +471,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers && x.Alias == Constants.PropertyEditors.Aliases.Label); Mock.Get(dataEditor).Setup(x => x.GetValueEditor()).Returns(new TextOnlyValueEditor( new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox"), textService.Object, Mock.Of(), Mock.Of(), Mock.Of())); - var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(new[] { dataEditor })); + var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(() => new[] { dataEditor })); IMapDefinition memberMapDefinition = new MemberMapDefinition( commonMapper, @@ -487,7 +487,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers contentTypeBaseServiceProvider.Object, propertyEditorCollection)); - var map = new MapDefinitionCollection(new List() + var map = new MapDefinitionCollection(() => new List() { new global::Umbraco.Cms.Core.Models.Mapping.MemberMapDefinition(), memberMapDefinition, diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs index 60185a1846..fa7e307c23 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Routing Options.Create(globalSettings), Mock.Of(x => x.ToAbsolute(It.IsAny()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty), Mock.Of(x => x.Level == level), - new UmbracoApiControllerTypeCollection(new[] { typeof(Testing1Controller) })); + new UmbracoApiControllerTypeCollection(() => new[] { typeof(Testing1Controller) })); return routes; } diff --git a/src/Umbraco.Web.BackOffice/Trees/TreeCollectionBuilder.cs b/src/Umbraco.Web.BackOffice/Trees/TreeCollectionBuilder.cs index 2257f80d88..37a857f78d 100644 --- a/src/Umbraco.Web.BackOffice/Trees/TreeCollectionBuilder.cs +++ b/src/Umbraco.Web.BackOffice/Trees/TreeCollectionBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Composing; @@ -14,7 +14,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees { private readonly List _trees = new List(); - public TreeCollection CreateCollection(IServiceProvider factory) => new TreeCollection(_trees); + public TreeCollection CreateCollection(IServiceProvider factory) => new TreeCollection(() => _trees); public void RegisterWith(IServiceCollection services) => services.Add(new ServiceDescriptor(typeof(TreeCollection), CreateCollection, ServiceLifetime.Singleton)); diff --git a/src/Umbraco.Web.Common/Controllers/UmbracoApiControllerTypeCollectionBuilder.cs b/src/Umbraco.Web.Common/Controllers/UmbracoApiControllerTypeCollectionBuilder.cs index 30dec7842b..9f0c353092 100644 --- a/src/Umbraco.Web.Common/Controllers/UmbracoApiControllerTypeCollectionBuilder.cs +++ b/src/Umbraco.Web.Common/Controllers/UmbracoApiControllerTypeCollectionBuilder.cs @@ -1,4 +1,4 @@ -using Umbraco.Cms.Core; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Composing; namespace Umbraco.Cms.Web.Common.Controllers diff --git a/src/Umbraco.Web.Website/Collections/SurfaceControllerTypeCollection.cs b/src/Umbraco.Web.Website/Collections/SurfaceControllerTypeCollection.cs index e77b11a3d8..95c9208df6 100644 --- a/src/Umbraco.Web.Website/Collections/SurfaceControllerTypeCollection.cs +++ b/src/Umbraco.Web.Website/Collections/SurfaceControllerTypeCollection.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Umbraco.Cms.Core.Composing; @@ -6,8 +6,8 @@ namespace Umbraco.Cms.Web.Website.Collections { public class SurfaceControllerTypeCollection : BuilderCollectionBase { - public SurfaceControllerTypeCollection(IEnumerable items) - : base(items) - { } + public SurfaceControllerTypeCollection(Func> items) : base(items) + { + } } }