How to get appsettings config data in program ?
Hi i need to register an object in ServiceCollection that require information from the AzureStorageConfig
8 Replies
Then bind the configuration to your class.
You need another nuget for that iirc,
Microsoft.Extensions.Configuration.Binder
.
You would do something like
var myConfiguration = configuration.Get<MyClass>("MySection")
I tried it but when request the BlobContainer these 2 null
I dont know how to use the binding
@TotechsStrypper
var settings = configuration.GetSection("MyConfigurationNode").Get<MySettingsClass>();
So in your case, just builder.Configuration
rather than configuration
.services.AddSingleton(provider => {
var options = provider.GetRequiredService<IOptions<MyClass>>();
return new BlobContainerClient(blahblahblah);
});
I personally wouldn't read directly from configuration in a non configuration map class unless there was no other option.
@TotechsStrypper $options
I use the service provider to get the job done