Reputation: 131
I have a web service, say MyWebService
, and I need to host it on a windows service, say MyWindowsService
. So in OnStart
method in MyWindowsService
, I start MyWebService
. When MyWindowsService
starts, I need to send a log message (from within MyWindowsService
) to a listener saying the application has been started. Such a log message is generated by a LogGenerator
.
In MyWebService
, it also needs to send log messages to the listener as well when certain events are triggered, and those log messages (sent from within MyWebService
) are also generated by LogGenerator
.
The LogGenerator
has a few properties to be configured. Now I am facing some issues.
I do not know whether I need to construct an instance of LogGenerator
, configure this instance in MyWindowsService
, then pass it to MyWebService
. If so, then how I can pass an object to the web service from its hosting windows service. Or,
I construct an instance of LogGenerator
in MyWindowsService
and then I construct a second one in MyWebService
, so I do not need to pass any object to the web service. Or,
I can make LogGenerator
and all its properties and methods static, so I do not need to create any instances at all. If so, is it thread safe when I create log messages?
Thank you for any input !!!
Upvotes: 0
Views: 95
Reputation: 2380
You could use the singleton pattern when starting the web service to identify it and add event listeners on the windows service. Of course, this only works if you have only one instance of the web service.
Upvotes: 1