-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom handlers not override built in handlers correctly (#392)
* Fixed a bug in configuration (configuration values were case-sensitive). Added ability to disable default handlers for language client / language server. Added unit tests demonstrating Configuration.Binder, and Options usages * fixed an issue where the MedatR handler was being registered in the container for 'built-in' handlers, these were overriding any custom ones that were added later * added default request handler, and decorator to ensure that if a IRequestContext is given, then that handler is used. * removed some changes that are no longer needed * Removed extra dependencies, we can add these at another time * cleanup * removed unneeded code * Added additional assertions
- Loading branch information
1 parent
8b88655
commit 03d7b65
Showing
20 changed files
with
600 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#if false | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Configuration.Binder; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.Extensions.Configuration | ||
{ | ||
public static class ConfigureByConfigurationPathExtension | ||
{ | ||
/// <summary> | ||
/// Registers a injected configuration service 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> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static IServiceCollection Configure<TOptions>(this IServiceCollection services) | ||
where TOptions : class | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
return Configure<TOptions>(services, null); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service 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="sectionName">The name of the options instance.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, string? sectionName) | ||
where TOptions : class | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
services.AddOptions(); | ||
services.AddSingleton<IOptionsChangeTokenSource<TOptions>>( | ||
_ => new ConfigurationChangeTokenSource<TOptions>( | ||
Options.Options.DefaultName, | ||
sectionName == null ? _.GetRequiredService<IConfiguration>() : _.GetRequiredService<IConfiguration>().GetSection(sectionName) | ||
) | ||
); | ||
return services.AddSingleton<IConfigureOptions<TOptions>>( | ||
_ => new NamedConfigureFromConfigurationOptions<TOptions>( | ||
Options.Options.DefaultName, | ||
sectionName == null ? _.GetRequiredService<IConfiguration>() : _.GetRequiredService<IConfiguration>().GetSection(sectionName) | ||
) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service 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="configureBinder">Used to configure the <see cref="BinderOptions"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, Action<BinderOptions> configureBinder) | ||
where TOptions : class | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
return Configure<TOptions>(services, Options.Options.DefaultName, configureBinder); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service 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="sectionName">The name of the options instance.</param> | ||
/// <param name="configureBinder">Used to configure the <see cref="BinderOptions"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static IServiceCollection Configure<TOptions>(this IServiceCollection services, string sectionName, Action<BinderOptions> configureBinder) | ||
where TOptions : class | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
services.AddOptions(); | ||
services.AddSingleton<IOptionsChangeTokenSource<TOptions>>(_ => new ConfigurationChangeTokenSource<TOptions>(Options.Options.DefaultName, _.GetRequiredService<IConfiguration>().GetSection(sectionName))); | ||
return services.AddSingleton<IConfigureOptions<TOptions>>(_ => new NamedConfigureFromConfigurationOptions<TOptions>(Options.Options.DefaultName, _.GetRequiredService<IConfiguration>().GetSection(sectionName), configureBinder)); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service which TOptions will bind against. | ||
/// </summary> | ||
/// <typeparam name="TOptions">The type of options being configured.</typeparam> | ||
/// <param name="builder">The <see cref="OptionsBuilder<TOptions>"/> to configure.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static OptionsBuilder<TOptions> Configure<TOptions>(this OptionsBuilder<TOptions> builder) | ||
where TOptions : class | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
return Configure(builder, Options.Options.DefaultName); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service which TOptions will bind against. | ||
/// </summary> | ||
/// <typeparam name="TOptions">The type of options being configured.</typeparam> | ||
/// <param name="builder">The <see cref="OptionsBuilder<TOptions>"/> to configure.</param> | ||
/// <param name="sectionName">The name of the options instance.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static OptionsBuilder<TOptions> Configure<TOptions>(this OptionsBuilder<TOptions> builder, string sectionName) | ||
where TOptions : class | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
Configure<TOptions>(builder.Services, name); | ||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service which TOptions will bind against. | ||
/// </summary> | ||
/// <typeparam name="TOptions">The type of options being configured.</typeparam> | ||
/// <param name="builder">The <see cref="OptionsBuilder<TOptions>"/> to configure.</param> | ||
/// <param name="configureBinder">Used to configure the <see cref="BinderOptions"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static OptionsBuilder<TOptions> Configure<TOptions>(this OptionsBuilder<TOptions> builder, Action<BinderOptions> configureBinder) | ||
where TOptions : class | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
return Configure(builder, Options.Options.DefaultName, configureBinder); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a injected configuration service which TOptions will bind against. | ||
/// </summary> | ||
/// <typeparam name="TOptions">The type of options being configured.</typeparam> | ||
/// <param name="builder">The <see cref="OptionsBuilder<TOptions>"/> to configure.</param> | ||
/// <param name="sectionName">The name of the options instance.</param> | ||
/// <param name="configureBinder">Used to configure the <see cref="BinderOptions"/>.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
public static OptionsBuilder<TOptions> Configure<TOptions>(this OptionsBuilder<TOptions> builder, string sectionName, Action<BinderOptions> configureBinder) | ||
where TOptions : class | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
|
||
Configure<TOptions>(builder.Services, name, configureBinder); | ||
return builder; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.