using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+using System.Linq;
namespace Microsoft.Extensions.Options
{
IOptionsFactory<TOptions>
where TOptions : class
{
- private readonly IEnumerable<IConfigureOptions<TOptions>> _setups;
- private readonly IEnumerable<IPostConfigureOptions<TOptions>> _postConfigures;
- private readonly IEnumerable<IValidateOptions<TOptions>> _validations;
+ private readonly IConfigureOptions<TOptions>[] _setups;
+ private readonly IPostConfigureOptions<TOptions>[] _postConfigures;
+ private readonly IValidateOptions<TOptions>[] _validations;
/// <summary>
/// Initializes a new instance with the specified options configurations.
/// <param name="validations">The validations to run.</param>
public OptionsFactory(IEnumerable<IConfigureOptions<TOptions>> setups, IEnumerable<IPostConfigureOptions<TOptions>> postConfigures, IEnumerable<IValidateOptions<TOptions>> validations)
{
- _setups = setups;
- _postConfigures = postConfigures;
- _validations = validations;
+ _setups = setups as IConfigureOptions<TOptions>[] ?? setups.ToArray();
+ _postConfigures = postConfigures as IPostConfigureOptions<TOptions>[] ?? postConfigures.ToArray();
+ _validations = validations as IValidateOptions<TOptions>[] ?? validations.ToArray();
}
/// <summary>
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+using System.Linq;
using Microsoft.Extensions.Primitives;
namespace Microsoft.Extensions.Options
{
private readonly IOptionsMonitorCache<TOptions> _cache;
private readonly IOptionsFactory<TOptions> _factory;
- private readonly IEnumerable<IOptionsChangeTokenSource<TOptions>> _sources;
private readonly List<IDisposable> _registrations = new List<IDisposable>();
internal event Action<TOptions, string> _onChange;
public OptionsMonitor(IOptionsFactory<TOptions> factory, IEnumerable<IOptionsChangeTokenSource<TOptions>> sources, IOptionsMonitorCache<TOptions> cache)
{
_factory = factory;
- _sources = sources;
_cache = cache;
- foreach (IOptionsChangeTokenSource<TOptions> source in _sources)
+ foreach (IOptionsChangeTokenSource<TOptions> source in (sources as IOptionsChangeTokenSource<TOptions>[] ?? sources.ToArray()))
{
IDisposable registration = ChangeToken.OnChange(
() => source.GetChangeToken(),