Skip to content
Colin Mackay edited this page Feb 15, 2022 · 1 revision

To set up the provider you will need to:

  • Create a table in your database to store the configuration information.
  • Set up the provider in your application.

Setting up the database.

You will need to set up a table in your SQL Server. You can add it to an existing database or create a dedicated database for the configuration settings. The provider only needs read access to the table where the configuration data is stored.

SQL Script Template

CREATE SCHEMA Stravaig;
GO
CREATE TABLE Stravaig.AppConfiguration
(
    ConfigKey NVARCHAR(450) PRIMARY KEY CLUSTERED,
    ConfigValue NVARCHAR(MAX)
);
GO

The schema and table names are configurable, so you don't need to use the names given above. However, the column names must remain as they are.

Setting up the application

To set up the SQL Server configuration from existing configuration (i.e. from the configuration providers that appear before this provider up to that point). Any configuration providers added after the call to AddSqlServer will not have their data used to configuration the SQL Server provider.

await Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration(builder =>
    {
        builder.AddSqlServer(opts =>
        {
            // Will pull connection string, schema and table names from the 
            // configuration system up to this point.
            opts.FromExistingConfiguration();
        });
    })

with the corresponding information in appsettings.json, e.g.:

{
    "ConnectionStrings": {
        "ConfigDB": "*** Found in Secret Store ***"
    },
    "Stravaig": {
        "AppConfiguration": {
            "SchemaName": "Stravaig",
            "TableName": "AppConfiguration",
            "RefreshSeconds": 90,
            "ConnectionStringName": "ConfigDB",
            "CommandTimeout": 10
        }
    }
}

See Configuration Settings for more information.

Clone this wiki locally