Home > other >  Is the following code using options pattern?
Is the following code using options pattern?

Time:07-07

I'm reading this article on Windows Services and came across some code that I'm wondering about.

static void Main(string[] args)
{
    HostFactory.Run(x =>
        {
            x.Service<LoggingService>();
            x.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromSeconds(10)));
            x.SetServiceName("TestService");
            x.StartAutomatically();
         }
    );
}

Is this Options pattern code? What does this code look like in another more intuitive way?

CodePudding user response:

Here is another way to write the same code....

public static void MyRun (System.ServiceProcess.ServiceBase service)
{
  service.Service<LoggingService>();
  service.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromSeconds(10)));
  service.SetServiceName("TestService");
  service.StartAutomatically();
};


static void Main(string[] args)
{
    HostFactory.Run(MyRun);
}

Is that clearer?

  •  Tags:  
  • c#
  • Related