Skip to content

Mousavi310/Mousavi.Extensions.Configuration.SqlServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mousavi.Extensions.Configuration.SqlServer

This repository helps you to read your configuration from a SQL Server database. To add the provider in your ASP.NET Core application. First install the NuGet:

dotnet add package Mousavi.Extensions.Configuration.SqlServer --version 0.3.4-g3467e37824

And then configure the provider:

 public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })
                .ConfigureAppConfiguration((context, builder) =>
                    {
                        //Add this 
                        builder.AddSqlServer(
                            "Server=localhost;Database=Example;User Id=sa;Password=your(#SecurePassword!123)");
                    });

And in your console application:

var configuration1 = new ConfigurationBuilder()
                .AddSqlServer("Server=localhost;Database=Example;User Id=sa;Password=your(#SecurePassword!123)")
                .Build();

You can choose the name of table, schema, key column, value column:

builder.AddSqlServer(
                sqlBuilder => sqlBuilder
                    .UseConnectionString(
                        "Server=localhost;Database=Example;User Id=sa;Password=your(#SecurePassword!123)")
                    .WithSchema("dbo")
                    .WithKeyColumn("[Key]")
                    .WithValueColumn("[Value]"));

Refresh Configuration

If you want refresh configuration data, you can specify refresh interval:

builder.AddSqlServer(
                "Server=localhost;Database=Example;User Id=sa;Password=your(#SecurePassword!123)",
                TimeSpan.FromSeconds(5));

or

builder.AddSqlServer(
                sqlBuilder => sqlBuilder
                    .UseConnectionString(
                        "Server=localhost;Database=Example;User Id=sa;Password=your(#SecurePassword!123)")
                    .EnablePeriodicalAutoRefresh(TimeSpan.FromSeconds(5)));

Using the above configuration, the provider reload configuration from the database every 5 seconds. You can see the samples directory for more information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages