user989056
user989056

Reputation: 1274

Best practice for referencing settings from a class library project in .net

I have multiple projects within my solution. I have a project that is dedicated to holding references a number of WCF Service References ( it holds references to, not implementatins of WCF services ), lets call this project 'GlobalWebServices'. I then have many executable applications which reference this GlobalWebServices project. When I execute these applications, and try to call the references web services, they naturally lose the configuration details for the ServiceReferences that I am wanting to call. The configuration settings belong to the Class Library project - 'GlobalWebServices'.

What is the best way to store these ServiceReference binding details? I don't want to copy each one into the executing application's .config file because it feels untidy, and I am replicating information. I don't want to hard code the ServiceReference bindings in the 'GlobalWebServices' application because I have already generated binding connection information for each of the services ( well... visual studio has kindly done it for me, but still ). Ideally : I would like the GlobalWebServices library to automatically include binding information ( currently stored in it's app.config ) into the class library when it is built.

What is the best practice solution for this?

Upvotes: 0

Views: 286

Answers (1)

Brian Ball
Brian Ball

Reputation: 12606

You can separate out different parts of your web.config using configSection.

There may be a better answer, but my first thought would be to have the config file in your Class Library project. Set the properties of the config file to "Content" and "Copy if Newer". This will allow you to have it in one location for source control. The downside of this option though is that once it's deployed, it is in several different locations, but that could also be good if the configuration needs to be different for each application that uses the configuration file.

I know it's possible to configure services programatically and then write out the configuration to a file. I would like to think that would mean you could go the other way, and have a separate XML file, and load the bindings and such from there without it being the app.config itself.

Upvotes: 1

Related Questions