Is this the correct way to configure "Global settings" in WCF Serviced, Delivered through IIS
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 开发者_如何学Cwant to make sure this is the correct way. Can an expert comment?
I put the relevant data in web.config. Now I don't believe I can access this in my WCF class as such, so...
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 theAppDomain
usingAppDomain.CurrentDomain.SetData("MySettings", settingsObj);
Then in my WCF Service Implementation class I have a static constructor. This reads the relevant global object from the
AppDomain
usingAppDomain.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.
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.
精彩评论