Skip to content

Feature toggle

The disadvantage of using appsettings.json for configuration is changes require code change and deployment.

We can have a simple table containing keys and values for non-sensitive configurable values and feature toggles.

In Models.cs, add Setting.cs

csharp
public class SettingModel
{
    public int Id { get; set; }
    public string Key { get; set; }
    public string Value { get; set; }
    public string CreatedAt { get; set; }
    public DateTime CreatedBy { get; set; }
    public string UpdatedAt { get; set; }
    public DateTime UpdatedBy { get; set; }
}


Update DatabaseContext

csharp


Create migration file
dotnet ef migrations add CreateSettingTable

Run migrations
dotnet ef database update

Notice __EFMigrationsHistory has a new record

Seed settings

This time, we won't create model and update DatabaseContext because we want an empty migration file, run dotnet ef migrations add SeedSettingTable

In the generated migration file

csharp

Run the migrations dotnet ef database update

At this point, any dev can pull this project, create Postgres database, update appsettings and run migrations to create the tables with seed data.

Released under the MIT License.