Adding YAML Settings into ASP.NET Core Apps

Unlike traditional ASP.NET web apps using web.config for configuration, ASP.NET Core apps supports various file formats for it. When we actually see the source codes, configuration supports XML, JSON, INI, Azure Key Vault, in-memory collection, command line arguments and environment variables. However, another popular format, YAML is not officially supported in ASP.NET Core at the time of writing. In this post, we are going to walk through how we can import YAML settings file to support ASP.NET… [Keep reading] “Adding YAML Settings into ASP.NET Core Apps”

Deserialising .NET Core Configuration Settings

With System.Configuration.dll, we can add custom configSections into either App.config or Web.config files so that we can utilise strongly-typed configuration objects. On the other hand, .NET Core applications have replaced those App.config or Web.config with appsettings.json, which is more convenient for developers to use, especially for dependency injection (DI). In this post, we are going to walkthrough how we can deserialise the appsettings.json for DI purpose.

Basics

When we create an ASP.NET Core web application, we have a basic appsettings.json[Keep reading] “Deserialising .NET Core Configuration Settings”

Converting Web.config values into enum or List

While developing .NET applications, we always look for configuration values stored in either Web.config or App.config. We can simply use the <appSettings>…</appSettings> section which is converted to a dictionary or key/value pair object. Can we use a strongly-typed object for the configuration? Yes, we can. With the <configSections>…</configSections> node, we can convert configuration values into strongly-typed objects. This is a very useful feature in most cases. However, what if we have requirements like:

  • I want to convert a string value into an enum value, regardless of the case sensitivity.
[Keep reading] “Converting Web.config values into enum or List”