# Extending - Loaders

It's very easy to add custom providers. Remember that .NET creates a <mark style="color:blue;">**ConfigurationSource**</mark> that implements and returns a <mark style="color:blue;">**ConfigurationProvider**</mark>.&#x20;

You can see this pattern here: [Implement a custom configuration provider](https://docs.microsoft.com/en-us/dotnet/core/extensions/custom-configuration-provider).

### Custom Implementation

To implement a custom source and provider only requires a single line of code.

1. Call the ConfigureConfiguration method.&#x20;
2. This callback sends you two parameters:
   1. <mark style="color:blue;">**IConfigurationBuilder**</mark> This builder allows you to add a custom source.
   2. <mark style="color:blue;">**EnivronmentString**</mark> the string variable that is the current environment.&#x20;
3. Simply add a new instance of the source. (See **line 5**)

{% code lineNumbers="true" %}

```csharp
PerigeeApplication.ApplicationNoInit("DemoApp", (c) => {
    
    //Add ConfigurationSource to the builder
    c.ConfigureConfiguration((builder, EnvStr) => {
        builder.Add(new SQLConfigurationSource("connectionString", "select [name], [value] from dbo.configs", "sql"));
    });

    //Reload all providers
    c.ReloadProviders();

    //Reload the specific provider
    c.ReloadProvidersOfType(typeof(SQLConfigurationProvider));
    
    string MyValueFromSQL = c.GetValue<string>("sql:MyValue");
    
});
```

{% endcode %}

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 a SQL database, 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, query, and prefix.&#x20;

{% hint style="success" %}
Because this works with `IDBConnection`, it works with MSSQL, PostGres, MySql... etc. Just supply the appropriate connection and it will work!
{% endhint %}

{% code overflow="wrap" %}

```csharp
PerigeeApplication.ApplicationNoInit("DemoApp", (c) => {

    //Configure the SQL Property loader using SqlConnection
    c.ConfigureSqlPropertyLoader(
        () => new SqlConnection(c.GetConnectionString("main")),
        "SELECT [Key],[Value] FROM [dbo].[PropertyStore]");

    string MyValueFromSQL = c.GetValue<string>("sql:MyValue");
    
});
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.perigee.software/perigee-and-beyond/extending-loaders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
