Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add extension methods to IEnumerable<OptionsDescriptor<T>> #1787

@yishaigalatzer

Description

@yishaigalatzer

It is currently rather cumbersome to configure options in any of the lists in MvcOptions. The user has to write selector code to get to the descriptor objects, and then get the actual instance. For example

services.ConfigureOptions<MvcOptions>(options => 
    options.InputFormatters.Single(fd => fd.Instance is JsonInputFormatter).Instance.XXXX

Instead we should have a set of extension methods allowing easy access to the descriptors/instances

Here is an initial suggestion - @rynowak lets discuss and update

public static TInstance InstanceOf<TInstance>(this IEnumerable<OptionsDescriptor<TInstance>> collection);
public static TInstance InstanceOfOrDefault<TInstance>(this IEnumerable<OptionsDescriptor<TInstance>> collection);
public static IEnumerable<TInstance> InstancesOf<TInstance>(this IEnumerable<OptionsDescriptor<TInstance>> collection);
public static void RemoveTypesOf<TDescriptor>(this IList<OptionsDescriptor<TDescriptor>> collection);

perhaps we should also consider a replace in place extension, so a customized options can come in the exact same spot the one it replaced is in.
#1744

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions