Where should my application setting be in a .Net Core / EF Core class library project?

.net-core c# entity-framework entity-framework-core

Question

I am trying to store my database connection string in a config file so that I can change it depending on the deployment environment. My data access is using EF Core 1.1.0.

I have looked at some full .Net applications that use EF Core and use App.config to store and retrieve the connection string like this:

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString);
    }

However, when I try that approach in my .Net Core class library project by creating the same App.config file, when I hit the above line of code I get an "Object reference not set to an instance of an object." exception.

So my question is.. Where should these settings be stored in a .Net Core class library project and how are they then retrieved? Should it be App.config, project.json, appsettings.json or some other file??

1
2
11/28/2016 10:08:22 AM

Accepted Answer

When i look at this :

Entity Framework Core 1.0 Connection Strings

I think he used Json. Said it was easier, and managed to answer himself. Make sure your files see each other and it should be ok. Sorry if it didn't help.

1
5/23/2017 12:16:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow