I have this current project using WCF. I have my clients for presentation, and then the services (.svc), and the DAL which includes all operations in the db (no BLL). My problem is all of my methods in DAL uses a class library (ConnectionStringClass) which only contains the connectionstring. Eg:
public static long CreateUser(UserModel newUser) { using (sqlconnection conn = new sqlconnection(ConnectionStringClass)) { } }
I want that ConnectionStringClass be able to read to an app.config and the retrieve the connection string so i can easily change the connectionstring. However, I found out that app.config does not work for class libraries.
The other workaround I thought is to include the connectionstring as an argument to each method/service (e.g CreateUser(UserModel newUser, string ConnectionString). Yes, it is very ugly and not SOA-like.
Do you guys have any ideas/workaround so that i can use an app.config file for connectionstring without using it as an argument in a service call? Thanks!
I would recommend that you use the application's config file. That way you can use a different connection string for each application that uses the same library.
To do this, the connection string needs to be in the application's .config file, e.g. myapp.exe.config. This is then accessible to the class library as follows:
A good practice is to also define a configuration section that is specific to your class library. Then you can create an entry in the application's config file that determines which connection string to use.
Sorry ive just been able to respond right now. I've found a solution. Since im using WCF services, i can use web.config as my configuration file which is still accesible by my class libraries.