How to check options for null?
I have this:
in controller:
all I want is check options from startup for null but I can't just write
if(options == null)
11 Replies
According to the docs for
GetSection
, it returns "The specified ConfigurationSection object, or null if the section does not exist.", however the return type is object
and not object?
. You can probably just ignore the warning because the return type is annotated incorrectly.hmmm
okay, I'll ignore, thanks
You could also bind the configuration to a class at startup and inject that class.
That also allows you to do validation.
Options pattern in ASP.NET Core
Discover how to use the options pattern to represent groups of related settings in ASP.NET Core apps.
Unknown User•11mo 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•11mo ago
Message Not Public
Sign In & Join Server To View
Didn't .NET 8 also add a Source Gen for Options Validations?
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
is it possible to test that "My" section is exist?
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View