Type-DB as a Settings Provider

In a .Net Core project you can feel the need to have a settings "database" that will store all your application settings, that can be hot changed by the user.

Introduction

Imagine that your app have an admin dashboard and you want to store all your app settings, you can by example use Type-DB.

Code Sample

This sample store the DateTime at the runtime that is returned in the view, the good things with Type-DB is that you can setup persistence and when your settings will be updated, they will be persisted each time (because we use PersistenceType.Iteration)

// In Startup.cs
public Instance Instance { get; }
public Database Settings { get; }
public Startup(IConfiguration configuration)
{
Instance = new TypeDB.Core(Mode.Standalone)
.UsePersistence(new Persistence
{
Type = PersistenceType.Iteration,
Location = Persistence.TemporaryLocation
})
.Connect();
Settings = Instance.OpenDatabase("settings", true);
Settings.Set("date_time", DateTime.Now);
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<Database>(Settings);
services.AddMvc();
}
// In your Controller or PageModel
public IndexModel(Database settings)
{
_settings = settings;
}
public void OnGet()
{
ViewData["DateTime"] = _settings.Get<DateTime>("date_time");
}

Get a full example of this use case here: https://github.com/Type-DB/Core/tree/master/Type-DB.Core.Samples/Web

Read more about Persistence here: