❔ What's the difference between `IConfiguration.Get` and `IConfiguration.Bind`?
The docs say
Get
"Attempts to bind the configuration instance to a new instance of type T. If this configuration section has a value, that will be used. Otherwise binding by matching property names against configuration keys recursively." And Bind
"Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively." The description of IConfigurationSection.Value
is only "Gets or sets the section value."
What does IConfigurationSection.Value
mean and what's the difference between IConfiguration.Get
and IConfiguration.Bind
?26 Replies
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
appsettings.json:
src/Foo/FooOptions.cs:
src/Foo/FooServiceCollectionExtensions.cs:
Program.cs / Startup.cs:
Bar.cs:
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
I don't understand what you meant by "a single value." I mean, if I have an options class, then does an instance of that class count as "a single value"? And the documentation never mentions this "a single value" thing, it only says that the only difference between
Get
and Bind
is that Get
"Attempts to bind the configuration instance to a new instance of type T. If this configuration section has a value, that will be used."
This example didn't really answer my questions though, but raised more. What's BindConfiguration
and what's the difference between it and IOptionsBuilder.Bind
?
I also still don't understand what IConfigurationSection.Value
means. If it's a section, then isn't it supposed to contain multiple values? Then why would it have a value itself?Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Sorry, but I looked all over and the docs only contained the minimal amount of information and that's why I asked here.
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
For most of these methods the docs only has a single sentence describing them
ConfigurationBinder.Bind Method (Microsoft.Extensions.Configuration)
Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively.
For example the docs for
Bind
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
ASP.NET documentation
Learn to use ASP.NET Core to create web apps and services that are fast, secure, cross-platform, and cloud-based. Browse tutorials, sample code, fundamentals, API reference and more.
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Thank you. I'll read them and come back if I have more questions.
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Because you would have to inject the whole
IConfiguration
?Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Accidentally used a super reaction lmao
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
What's "bonne"? Did you mean bind?
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Tbh I didn't read them because MS "article documentations" have always made me think they are bad
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
So is this an API doc or a doc?
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.