Skip to main content

Posts

Showing posts with the label IOption

Strongly typed Application configuration through EF SQL DB

The idea is to create a strongly typed application configuration by constructing concrete class and get the values populated from the database so that it is easier to change. This would allow admin to directly modify DB values for configuration. So, let's start with what we need. Application setting classes as needed Classes for application setting. It is just a POCO implementation. /// <summary> /// Entire application settings /// </summary> public class Setting { /// <summary> /// Gets or sets the setting version. /// </summary> /// <value> /// The setting version. /// </value> public int SettingVersion { get; set; } /// <summary> /// Gets or sets the name of the application. /// </summary> /// <value> /// The name of the application. /// </value> public string ApplicationName { get; ...

ASP.NET Core environment aware strongly typed configuration in MongoDB

This is targetted to save in MongoDB but the technique can be used in any targetted backend with key value setting based on  IConfigurationProvider Data property. Basically, the provided interface works based Data property having a type as IDictionary<string, string>. So, whatever class we create it has to be serialized based on same. We would simplify this by creating an abstract class to have certain serialization logic. This is sample setting for the application. If you check the structure,  Setting is the main class and nested items are Azure, Message, Email, Twilio. The key value needs to be composed based on parent and child classes separated by colons. Just like above, we need to populate settings from our different setting classes. Implementation can be grouped in these sections. - Application level configuration classes. - Registration of configuration on ASP.NET Core. - Environment level configuration, this would little mixed with abo...