ConsoleConfigurationLibrary 1.0.0.3
See the version list below for details.
dotnet add package ConsoleConfigurationLibrary --version 1.0.0.3
NuGet\Install-Package ConsoleConfigurationLibrary -Version 1.0.0.3
<PackageReference Include="ConsoleConfigurationLibrary" Version="1.0.0.3" />
paket add ConsoleConfigurationLibrary --version 1.0.0.3
#r "nuget: ConsoleConfigurationLibrary, 1.0.0.3"
// Install ConsoleConfigurationLibrary as a Cake Addin #addin nuget:?package=ConsoleConfigurationLibrary&version=1.0.0.3 // Install ConsoleConfigurationLibrary as a Cake Tool #tool nuget:?package=ConsoleConfigurationLibrary&version=1.0.0.3
About
Provides easy access to connection strings in a Console project's appsettings.json file.
Example
With the following appsettings.json file
{
"ConnectionStrings": {
"MainConnection": "Data Source=.\\SQLEXPRESS;Initial Catalog=Chinook;Integrated Security=True;Encrypt=False",
"SecondaryConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=NorthWind2024;Integrated Security=True;Encrypt=False",
"OtherConnection": "Other"
}
}
Add this package to a console project then in Program.cs, call RegisterConnectionServices.Configure()
static async Task Main(string[] args)
{
await RegisterConnectionServices.Configure();
Console.ReadLine();
}
To access the MainConnectionString use AppConnections.Instance.MainConnection
as shown below, in this case using Dapper.
public static List<Track> TrackList(int albumId)
{
using SqlConnection cn = new(AppConnections.Instance.MainConnection);
return cn.Query<Track>(SqlStatements.TracksByAlbumId, new { AlbumId = albumId }).ToList();
}
Then for the second connection string
public static List<Categories> CategoryList()
{
using SqlConnection cn = new(AppConnections.Instance.SecondaryConnection);
return cn.Query<Categories>(SqlStatements.Categories).ToList();
}
And Other connection string follows the same as both of the above.
Working code samples
See the project ConsoleConfigurationApp.
- Run the scripts under the script folder before run the project.
Release notes
- 04/26/2024 no functionality change, simple refactor.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 8.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 8.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.Configuration.Xml (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added option for creating bogus data