How to get connection string from head project's app.config/appsettings.json in a class library

耗尽温柔 提交于 2020-01-24 17:33:26

问题


When writing a C# class library that accesses a database, my preferred method of getting a connection string from a head project's app.config/appsettings.json is to have the DB access classes depend on some IConnectionString interface that is registered in an IOC container by the head project.

I am currently using F# however, and the above is not a particularly functional approach. Neither is having a static variable on a static class set by the Startup class of the head project (though it's dead simple and boilerplate-free, so that's my plan B). A complicating matter is that the head project is not F#, so that places limits on things like partial application at the top level of the program.

Is there a robust, boilerplate-free (and preferably functional) way to get a connection string from a C# head project's app.config/appsettings.json down to the instantiation of the data context in a reusable library?

来源:https://stackoverflow.com/questions/46580602/how-to-get-connection-string-from-head-projects-app-config-appsettings-json-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!