问题
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