Is there a method that throws an exception if a config value is not present in appsettings?
Hello,
Getting configuration values from
appsettings.json
is done via calling builder.Configuration["name"]
. This way few of my services might get a null property, without throwing error before build.
Is there an existing method that will throw an exception if the config value is null
?9 Replies
you could make a simple extension method for this
Compile-time options validation source generation - .NET
Learn how to utilize compile-time source generation for validating options.
ty I will read
Thank you
This is just what I needed
Unknown User•3mo 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•3mo ago
Message Not Public
Sign In & Join Server To View
Than you
ty