How to read web.config file in .Net Core app

后端 未结 6 1462
逝去的感伤
逝去的感伤 2020-12-01 15:51

I have created a .Net Core API and I referenced a .Net framework application to it. The referenced Application connects to a data base and its connection string is stored in

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 16:44

    The problem here is that the OP has a data access layer project library that targets the full .Net Framework that contains code which depends on the ConfigurationManager. ConfigurationManager knows nothing about configuration in .Net Core and thus cannot access values from the default configuration implementation, i.e. appsettings.json. Some answers note that you can add an app.config file to the .Net Core client, but this smells if we don't hold our nose.

    The better solution would be to inject the connection string into the data access library. Especially if that library will be used by multiple clients.

提交回复
热议问题