Ask or search…
⌃K
Links

Extending - Loaders

It's very easy to add custom providers.
It's very easy to add custom providers. Remember that .NET creates a ConfigurationSource that implements and returns a ConfigurationProvider.
You can see this pattern here: Implement a custom configuration provider.

Custom Implementation

To implement a custom source and provider only requires a single line of code.
  1. 1.
    Call the ConfigureConfiguration method.
  2. 2.
    This callback sends you two parameters:
    1. 1.
      IConfigurationBuilder This builder allows you to add a custom source.
    2. 2.
      EnivronmentString the string variable that is the current environment.
  3. 3.
    Simply add a new instance of the source. (See line 5)
1
PerigeeApplication.ApplicationNoInit("DemoApp", (c) => {
2
3
//Add ConfigurationSource to the builder
4
c.ConfigureConfiguration((builder, EnvStr) => {
5
builder.Add(new SQLConfigurationSource("connectionString", "select [name], [value] from dbo.configs", "sql"));
6
});
7
​
8
//Reload all providers
9
c.ReloadProviders();
10
​
11
//Reload the specific provider
12
c.ReloadProvidersOfType(typeof(SQLConfigurationProvider));
13
14
string MyValueFromSQL = c.GetValue<string>("sql:MyValue");
15
16
});
You can see how easy it is in the future to reload the providers. You can reload all of them or specific types by supplying that type information.

Using the built in SQL Provider

If you're trying to load values from MSSQL then Perigee ships with a loader ready to go in only a single line of code. Simply call the configuration method and supply the connection string, query, and prefix.
PerigeeApplication.ApplicationNoInit("DemoApp", (c) => {
​
//Configure the SQL Property loader
c.ConfigurePropertyLoader_SQL("connectionString", "select [name], [value] from dbo.configs", "sql");
string MyValueFromSQL = c.GetValue<string>("sql:MyValue");
});