I have a class library that was written in .NET 5 and used the Microsoft.AspNetCore package, which is now deprecated. After upgrading my library to .NET 7 I'm getting this error:
'OptionsBuilder<AamSettings>' does not contain a definition for 'Bind' and no accessible extension method 'Bind' accepting a first argument of type 'OptionsBuilder<AamSettings>' could be found (are you missing a using directive or an assembly reference?)
If I look at the OptionsBuilderExtensions docs I see an extension method for Bind listed as being part of the Microsoft.Extensions.DependencyInjection namespace. My library includes that NuGet package, and the file has a using Microsoft.Extensions.DependencyInjection
line at the top of the file.
What am I missing in order to be able to call Bind
?
public static IServiceCollection AddAamClient(this IServiceCollection services, AamClientRegistrationOptions options)
{
services
.AddOptions<AamSettings>()
.Bind(options.Configuration.GetRequiredSection(options.ConfigurationSectionName))
with a reference to Microsoft.Extensions.Options.ConfigurationExtensions
you could use:
services
.AddOptions<AamSettings>()
.BindConfiguration(options.ConfigurationSectionName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With