views:

140

answers:

1

Hello there,

My WCF Service is hosted in Windows Service and
I have added some keys in the appSettings section of Windows Service app.config.

Now, I want these keys to be available at more than one code file in WCF Library.
Is there any way I can define WCF Service level variable, so that I can avoid -

ConfigurationSettings.AppSettings["xxx"]

at all the places where I need to use the appSettings' key.
Instead I want to set them at one place and use the variable whenever needed.

Thank you!

+1  A: 

Use Dependency Injection to inject these variables into your service. That would also decouple your service from the configuration system (a good thing, IMO).

Here is a decription on how to implement Constructor Injection with WCF

Define a class (a Parameter Object) that encapsulates the knowledge you want to make available and inject an instance of that class into your WCF service.

You can populate the Parameter Object from .config when you wire up the dependencies, but now you are only doing it a single place.

Mark Seemann