vendredi 25 septembre 2015

What's this Lambda configuration "pattern" called?

Im seeing this pattern in many different Nuget-packages where you pass in a lambda expression, this is an example from TopShelf, does this configuration pattern has a name? I really like it and want to read more about it.

public class Program
{
    public static void Main()
    {
        HostFactory.Run(x =>                                 //1
        {
            x.Service<TownCrier>(s =>                        //2
            {
               s.ConstructUsing(name=> new TownCrier());     //3
               s.WhenStarted(tc => tc.Start());              //4
               s.WhenStopped(tc => tc.Stop());               //5
            });
            x.RunAsLocalSystem();                            //6

            x.SetDescription("Sample Topshelf Host");        //7
            x.SetDisplayName("Stuff");                       //8
            x.SetServiceName("Stuff");                       //9
        });                                                  //10
    }
}

This is how the HostFactory.Run method looks

public static TopshelfExitCode Run(Action<HostConfigurator> configureCallback)
{
    try
    {
        return New(configureCallback)
            .Run();
    }
    catch (Exception ex)
    {
        HostLogger.Get(typeof(HostFactory))
                  .Error("The service terminated abnormally", ex);
        HostLogger.Shutdown();

        return TopshelfExitCode.AbnormalExit;
    }
}

Aucun commentaire:

Enregistrer un commentaire