Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is the following code using options pattern?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading