diff --git a/src/Umbraco.Core/DependencyInjection/OrderedCollectionBuilderBase.cs b/src/Umbraco.Core/DependencyInjection/OrderedCollectionBuilderBase.cs index dc2dbe0ac9..96d0a85762 100644 --- a/src/Umbraco.Core/DependencyInjection/OrderedCollectionBuilderBase.cs +++ b/src/Umbraco.Core/DependencyInjection/OrderedCollectionBuilderBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using LightInject; namespace Umbraco.Core.DependencyInjection @@ -36,6 +37,24 @@ namespace Umbraco.Core.DependencyInjection return This; } + /// + /// Appends types to the collections. + /// + /// The types to append. + /// The builder. + public TBuilder Append(IEnumerable types) + { + Configure(list => + { + foreach (var type in types) + { + if (list.Contains(type)) list.Remove(type); + list.Add(type); + } + }); + return This; + } + /// /// Appends a type after another type. /// diff --git a/src/Umbraco.Core/DependencyInjection/WeightedCollectionBuilderBase.cs b/src/Umbraco.Core/DependencyInjection/WeightedCollectionBuilderBase.cs index b6a14cae20..46703e1bd3 100644 --- a/src/Umbraco.Core/DependencyInjection/WeightedCollectionBuilderBase.cs +++ b/src/Umbraco.Core/DependencyInjection/WeightedCollectionBuilderBase.cs @@ -37,6 +37,26 @@ namespace Umbraco.Core.DependencyInjection return This; } + /// + /// Adds types to the collection. + /// + /// The types to add. + /// The builder. + public TBuilder Add(IEnumerable types) + { + Configure(list => + { + foreach (var type in types) + { + // would be detected by CollectionBuilderBase when registering, anyways, but let's fail fast + if (typeof(TItem).IsAssignableFrom(type) == false) + throw new InvalidOperationException($"Cannot register type {type.FullName} as it does not inherit from/implement {typeof(TItem).FullName}."); + if (list.Contains(type) == false) list.Add(type); + } + }); + return This; + } + /// /// Removes a type from the collection. ///