Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/ModularPipelines/Engine/OptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ internal class OptionsProvider : IOptionsProvider
/// </summary>
private static readonly ConcurrentDictionary<Type, Func<object, object?>> ValueGetterCache = new();

/// <summary>
/// Cache of constructed IOptions&lt;T&gt; types to avoid repeated MakeGenericType calls.
/// </summary>
private static readonly ConcurrentDictionary<Type, Type> IOptionsTypeCache = new();

/// <summary>
/// Set of generic type definitions that indicate an options-related type.
/// Using a HashSet for O(1) lookup instead of multiple IsAssignableTo calls.
Expand Down Expand Up @@ -53,8 +58,11 @@ public OptionsProvider(IPipelineServiceContainerWrapper pipelineServiceContainer
.Distinct()
.ToList();

foreach (var option in _cachedOptionTypes.Select(t => _serviceProvider.GetService(typeof(IOptions<>).MakeGenericType(t))))
foreach (var t in _cachedOptionTypes)
{
var optionsType = IOptionsTypeCache.GetOrAdd(t, static innerType => typeof(IOptions<>).MakeGenericType(innerType));
var option = _serviceProvider.GetService(optionsType);

if (option is null)
{
continue;
Expand Down
Loading