Many overloads of Configure method in .net core

 

~ 1 min read.

The DI in .net core is really neatly built and easy to use, but every once in a while I forgot in which nuget the Configure method I need is located. To be more precise the extension that adds the overload for Configure method that I keep forgetting where it is located is this one:

IServiceCollection Configure<TOptions>(this IServiceCollection services, IConfiguration config) where TOptions : class

VisualStudio is usually very helpful when it comes to figuring out .net dependencies and offers you with a choice to install it via nuget. Unfortunately in this case nothing happens and googling is not so straight forward as one would expect, so for the future reference I am writing this small reminder for myself :smiley_cat:

The nuget package that “hides” the method is called:

Microsoft.Extensions.Options.ConfigurationExtensions

and as a bonus here is the source code:

/// <summary>
/// Registers a configuration instance which TOptions will bind against.
/// </summary>
/// <typeparam name="TOptions">The type of options being configured.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <param name="config">The configuration being bound.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, IConfiguration config) where TOptions : class
    => services.Configure<TOptions>(Options.Options.DefaultName, config);

So, until I forgot this again :smiley_cat: