I am using vb
.net & asp.net 2005 and have a Windows Service and a Web Application.
I have a class named Utilities, object of which is created in the Windows Service (installed on one application server) and also from a Web Page (installed on other web server).
In the older versions of my project I used to implement #If Web = 1/0 Then #
compiler directives to compile and build code that was specific to my app server and for my web server and install those specific builds on their servers respectively.
Now a decision has been taken that we will use the Web = 1 directive ONLY (A single build for app and web). But the differentiated Codes must be maintained. The condition I am trying to differentiate here is, if it’s a web application that is calling the Utilities code then I must use HTTP Cache otherwise if it’s a windows service (win app) I make calls to database to fetch required values.
hence I need an alternative approach to the problem than Web = 1 directive.
A very layman approach would be passing a parameter (say IsWindows = True
) to Utilities while making Windows Application calls. So that it would tell the code if a windows service is calling it or a web page.
But do we have anything more sophisticated e.g. something in ApplicationServices
namespace that tells me whether the base application is windows or web?
I do not want to use AssemblyName or path properties as they would be very crude to use.
What about creating an object of ApplicationServices.WebUser
class … it should be equal to nothing when a windows application calls it … right?
If no then anything else which you guys can reckon?