I am setting up my first .NET Core application. I am going to user Dapper (1.50.0-rc2) for the ORM.
I have added the following to my appsettings.json file
I have a sample Console App for .NET core on my GitHub repository
Setup phase
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
Build phase
Configuration = builder.Build();
Use phase
Configuration.GetConnectionString("DefaultConnection")
You can use this value for Dapper
P.S.
You need to add 3 dependencies into your project.json
"Microsoft.Extensions.Configuration": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final"
UPDATED
Specific solution
make Configuration static property and add private setter
public static IConfigurationRoot Configuration { get; private set; }
and change your extension
namespace GamesCore.Extensions
{
public class ScoreExtensions
{
private static string dataConnectionString = Startup.Configuration.GetConnectionString("DefaultConnection");
}
}
For .NET Core 2.0 everything is same and only project file is changed so you need to use following packages: