In my project, I have a service class.
class KLAService : IKLAService
{
CentralLogic centralLogic;
.....
}
Using this class, I set up the ServiceHost
like this:
centralLogic = new CentralLogic();
ServiceHost host = new ServiceHost(typeof(KLAService));
using (host)
{
host.Open();
Application app = new Application();
app.Run(new ConfigurationWPF.MainWindow(centralLogic));
host.Close();
}
As it might have become clear, I create one instance of the CentralLogic
class. This very instance is used in the UI but also in the host to manage other stuff in my solution.
The problem I'm having now, is to set the centralLogic
-variable in the KLAService
-class (or in the host
). I don't know how to do this. I've read about the plugin Ninject and how to inject objects in the service, but that's way out of my league and I can't help but think there is an easy way.
How can I achieve my goal the best?
EDIT: Another solution proposed was to start the ServiceHost and let CentralLogic
get created there instead of the other way around. That would mean the ServiceHost needs some sort of a constructor. I don't know what the best practice is nor how to achieve this. Any help is appreciated.