Skip to content

NotIlya4/NotIlya.SqlConnectionString.Extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

📦 NotIlya.SqlConnectionString.Extensions NuGet Version

Several extensions for IConfiguration that help retrieve connection strings, primarily designed for SQL Server (MSSQL) as I'm using SqlConnectionStringBuilder under the hood.

Quickstart

You can have config like this:

{
  "SqlConnectionString": {
    "Server": "localhost,1433",
    "Database": "TestDb"
  }
}

Or like this:

{
  "SqlConnectionString": "localhost,1433;Database=TestDb"
}

And you can get it using config.GetSqlConnectionString().

Custom section

To specify your own section use key parameter in any method:

{
  "SqlServer": {
    "Server": "localhost,1433",
    "Database": "TestDb"
  }
}

Get it by config.GetSqlConnectionString("SqlServer").

Development defaults

There is also method that has predefined defaults for development environments. Your empty config:

{
  
}

Using this config.GetDevelopmentSqlConnectionString() empty config will be equivalent to:

{
  "SqlConnectionString": {
    "Server": "localhost,1433",
    "User Id": "SA",
    "Password": "1tsJusT@S@mpleP@ssword!",
    "MultipleActiveResultSets": true,
    "TrustServerCertificate": true
  }
}

Of course you can override any of this values by providing them in config.

SqlConnectionStringBuilder

My extensions built on top of SqlConnectionStringBuilder and instead of raw connection string you can get builder. Instead of GetSqlConnectionString use GetSqlConnectionStringBuilder and instead of GetDevelopmentSqlConnectionString use GetDevelopmentSqlConnectionStringBuilder.

About

📦 Extension for IConfiguration to get sql connection string

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages