开发者

Is this the correct way to configure "Global settings" in WCF Serviced, Delivered through IIS

开发者 https://www.devze.com 2022-12-11 19:10 出处:网络
I have a WCF service written.I want it to pick up some \"global settings\" upon startup.The WCF service will run under 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?

  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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消