Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (47 sloc) 1.72 KB
description
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.

Type-DB as a Settings Provider

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:

{% page-ref page="../features/persistence.md" %}

You can’t perform that action at this time.