What is the difference between services.Configure() and services.AddOptions().Bind() when loading configuration in ASP.NET Core?

This was asked in a Github issue in November 2018 Question: AddOptions() vs. Multiple Configure(…). Both methods do the same job but AddOptions came later and allows more customizations.

Configure(Action configureOptions) and OptionsBuilder.Configure(Action configureOptions) will both end up doing the same thing:

services.AddSingleton<IConfigureOptions<TOptions>>(
    new ConfigureNamedOptions<TOptions>(name, configureOptions));

And OptionsBuilder.Bind(IConfiguration config) will actually call Configure(IConfiguration config) directly, so they are also equivalent.

So both APIs are interchangeable. And you can expect the services.Configure calls to continue to work. The options builder API came later to allow for a bit more control with various utility methods. But it’s not a replacement for the direct services.Configure API.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)