ASP.NET Core managed config

Reading config is pretty straight forward task that most applications need. For many years I used Nini, which scratched that itch fairly well. With the advent of better libraries its not too difficult to deserialize your favorite formatted config file into a class.

With .Net Core we finally got some decent/easy to use config system built in by the help of the Options pattern. In short, reading config by deserializing sections of appsettings.json into DI-hosted objects.



In Startup.cs ConfigureServices method:

This would require a couple of classes, for example:

And a corresponding config section

If config section/values do not exist it will not produce any error.


Recall config object by IOptions<object> and use its “Value” property to extract object.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: