Skip to content

Database Configuration Source

Tricklebyte edited this page Jan 26, 2020 · 15 revisions

IConfigurationBuilderExtensions.AddDbSource Method

Default Settings

Where an overload does not supply a specific parameter, the following defaults will apply.
All defaults may be overridden by using the IConfiguration input parameter overload

Tablename = ConfigSetting
Database table name where the configuration setting data is stored

KeyCol = SettingKey
Database table column name for the configuration setting key

ValCol = SettingValue
Database table column name for the configuration setting value

AppIdCol = AppId
Database table column name used to identify the client application

AppIdVal = Calling Assembly (Client Application Project Name)
Used as the search filter parameter when calling the API. The API should return settings for this client only, based on the value of AppId.

SqlCommandTimeout = 0
Timeout value in seconds used by the SQL Command. (0 = infinite)

Overloads

AddDbSource (IConfigurationBuilder, String)

Adds the DbClient configuration source to the builder
May be used when initializing the Host before any other configuration or services have been loaded.
The calling assembly name (client project name) will be used as the default AppId.

public static IConfigurationBuilder AddDbSource(this IConfigurationBuilder builder, string connStringVar)

Parameters

connStringVar String
Name of Environment Variable containing the SQL Server connection string


AddDbSource (IConfigurationBuilder, String, Boolean)

Adds the DbClient configuration source to the builder
May be used when initializing the Host before any services have been loaded by DI.

public static IConfigurationBuilder AddDbSource(this IConfigurationBuilder builder, string connStringVar, bool optional)

Parameters

connStringVar String
Name of Environment Variable containing the SQL Server connection string

optional Boolean
When false, an exception will be thrown if the client is unable to connect to the database and execute the query.


AddDbSource (IConfigurationBuilder, String, String)

Adds the DbClient configuration source to the builder
May be used when initializing the Host before any services have been loaded by DI.

public static IConfigurationBuilder AddDbSource(this IConfigurationBuilder builder, string connStringVar, string appId)

Parameters

connStringVar String
Name of Environment Variable containing the SQL Server connection string

appId String
Used as the search filter parameter when calling the API. The API should return settings for this client only, based on the value of AppId.


AddDbSource (IConfigurationBuilder, String, String, Boolean)

Adds the DbClient configuration source to the builder
May be used when initializing the Host before any services have been loaded by DI.

public static IConfigurationBuilder AddDbSource(this IConfigurationBuilder builder, string connStringVar, string appId, bool optional)

Parameters

connStringVar String
Name of Environment Variable containing the SQL Server connection string

appId String
Used as the search filter parameter when calling the API. The API should return settings for this client only, based on the value of AppId.

optional Boolean
When false, an exception will be thrown if the client is unable to connect to the database and execute the query.


AddDbSource (IConfigurationBuilder, IConfiguration, [Boolean])

Adds the DbClient configuration source to the builder
May be used when initializing the Host before any services have been loaded by DI.

public static IConfigurationBuilder AddDbSource(this IConfigurationBuilder builder, IConfiguration config, bool optional = false)

Parameters

config IConfiguration
Instance of IConfiguration - must contain configuration section ConfigOptions:DbSource

optional Boolean (optional)
default: false An exception will be thrown if the client is unable to connect to the database and execute the query.

Configuration Section ConfigOptions:DbSource

{
"ConfigOptions": {
    "DbSource": {
     "ConnString": "Server = (localdb)\\mssqllocaldb;Database=ConfigDb;Trusted_Connection=True;MultipleActiveResultSets=True;",
      "TableName": "ConfigSetting",
      "KeyCol": "SettingKey",
      "ValCol": "SettingVal",
      "AppIdCol": "AppId",
      "AppIdVal": "CustomAppName",
      "SqlCommandTimeout": "0",	
    }
  }
}

Refer to the Db Config Client Sample Project for a fully configured example.

SQL Setup scripts are also provided in the Samples/SQL directory.