I'm trying to port a Web Application from ASP.NET 4.5 to ASP.NET 5 / MVC 6 (Beta 8).
The application consists of a WebApp and a class library which encapsulates the DB access. In my new solution, the class library is of type Class Library (Package).
The DB access layer (class library) tries to find a connection string named MyConnection. In my old ASP.NET 4.5 application I used to define that connection string in web.config of the WebApp. Somehow this configuration found it's way to my class library so that my class library was able to access the connection string defined in the WebApp.
Now with ASP.NET 5 I analogously tried to define the connection string in appsettings.json like this:
{
"ConnectionStrings": {
"MyConnection": "server=localhost\\SQLEXPRESS;database=MyDb;Integrated Security=True"
}
}
But at runtime I get the following error:
Can't find a connection string with the name 'MyConnection'
So, unlike with old ASP.NET, here the configuration doesn't seem to make its way down to the referenced class library.
How can I make sure that my connection string is visible from my referenced class library?
ConfigurationManager.ConnectionStrings[...], right? The thing is that I'm using a third-party library which tries to access the connection string based on its name that way...