I am build ing an ASP.NET application and the pages and user controls interact with a library of custom business objects for getting data, etc...
In addition, I have designed things (so far) so that the business objects could be used by a winForms application if the client should decide to go down that path as well.
Finally, I am a big fan of declaring TraceSwitches in the application's config file (either web or app) because of the flexibility of being able to turn these switches on or off at runtime. The downside to these traceswitches is that you must instantiate a new TraceSwitch object when you want to determine the current switch setting. If your code uses a "reasonable" number of trace messages, it seems that instantiating a TraceSwitch object on every call could be an expensive proposition.
With that in mind, I have been considering options to minimize the number of TraceSwitch instantiations.
One thought was to create a "thread-safe" Singleton class in my business object library. This would statisfy my desire for something that could be called by the web app or the business tier, but I am concerned about performance. My understanding is that all requests within the aspnet_wp would be funneled through this instance, and that would probably be very detrimental.
Another option is to create an instance of the TraceSwitch object in the HttpCache. This should perform much better than the Singleton, and all of the UserControls and current aspx page could access this instance. The downside here is that I still do not have a solution for the business tier (unless I just assume that there is an HttpContext to hook into...but that breaks my hopes of porting to WinForms).
A solution to this is greatly appreciated!