3

I have added command line support to my topshelf program as follows:

HostFactory.Run(hostConfigurator =>
{
    hostConfigurator.AddCommandLineDefinition("params", f => { startParams = f; });    
    hostConfigurator.ApplyCommandLine(); 
}

And this works just fine.

When I install it as a service I was hoping in the installed service 'start parameters' it would serve the same purpose but it doesn't.

Can anyone tell me how to access the 'start parameters' from TopShelf?

I wish to install the same service multiple times (with different instance names) which are different by the start parameters and I also want to use it to pass in testing values.

I guess just simply accessing these programmatically for a standard service will probably point me in the right direction.

thanks.

Sandor Drieënhuizen
  • 5,950
  • 4
  • 35
  • 77
Neil Walker
  • 5,334
  • 10
  • 51
  • 75
  • See my answer [here](http://stackoverflow.com/questions/15245770/how-to-specify-command-line-options-for-service-in-topshelf/36044058#36044058) for how I got around this limitation – Amith Sewnarain Mar 16 '16 at 18:36

1 Answers1

1

Parameters related to Service installation, such as servicename, description, instancename etc. can be accessed as follows

HostFactory.Run(x =>
{
    x.Service((ServiceConfigurator<MyService> s) =>
    {
        s.ConstructUsing(settings =>
        {
            var instanceName= settings.InstanceName;
                return new MyService();
        });
    }
}

Or if your MyService implements ServiceControl

        HostFactory.Run(x =>
        {
            x.Service<MyService>((s) =>
            {
                var instanceName= s.InstanceName;

                return new MyService();
            });
         }
/***************************/

class MyService : ServiceControl
{
    public bool Start(HostControl hostControl) {  }

    public bool Stop(HostControl hostControl)  {  }
}

I'm not sure what you mean by "Start Parameters", if above is not what you want, try to explain with pseudo-code example what you are trying to achieve.

Sergej Popov
  • 2,745
  • 5
  • 31
  • 52