tags:

views:

39

answers:

1

Hi There,

I have a WCF service written. I want it to pick up some "global settings" upon startup. The WCF service will run under IIS.

Here's how I am doing it, but I want to make sure this is the correct way. Can an expert comment?

  1. I put the relevant data in web.config. Now I don't believe I can access this in my WCF class as such, so...

  2. I've created a Global.asax file, and in its Application_Start method, I read in the relevant data into an object, which I place into the AppDomain using AppDomain.CurrentDomain.SetData("MySettings", settingsObj);

  3. Then in my WCF Service Implementation class I have a static constructor. This reads the relevant global object from the AppDomain using AppDomain.CurrentDomain.GetData("MySettings");

This all seems to work, but I'm wondering if this is the correct way? I understand why the WCF service implementation has no access to the HttpContext.

Thanks, Dermot.

A: 

I wouldn't bother using GetData and SetData methods. When I need the values I would just pull them from the config file with ConfigurationManager.AppSettings["your_key"], or inject them into the service instance constructor by implementing a custom IInstanceProvider.

Darin Dimitrov
My Settings object is something I read in from an XML file in Application_Start. It is a complex object, not just a string, So I don't believe I can put it into AppSettings
dermdaly