Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created February 21, 2011 23:11
Show Gist options
  • Select an option

  • Save thecodejunkie/837889 to your computer and use it in GitHub Desktop.

Select an option

Save thecodejunkie/837889 to your computer and use it in GitHub Desktop.
Sample for how a nested closure could be used to configure a ServiceHost in Elasticity
class Program
{
static void Main(string[] args)
{
var scheduler =
new DefaultScheduler();
var host = new ServiceHost(scheduler, x => {
x.JobRequestQueue = "foo";
x.TaskResponseQueue = "bar";
});
}
}
public class ServiceHost
{
private readonly IScheduler scheduler;
private readonly ISchedulerConfiguration schedulerConfiguration;
public ServiceHost(IScheduler scheduler, ISchedulerConfiguration schedulerConfiguration)
{
this.scheduler = scheduler;
this.schedulerConfiguration = schedulerConfiguration;
}
public ServiceHost(IScheduler scheduler, Action<SchedulerConfigurationConfigurator> closure)
{
this.scheduler = scheduler;
var configuration =
new DefaultSchedulerConfiguration();
var configurator =
new SchedulerConfigurationConfigurator(configuration);
closure.Invoke(configurator);
this.schedulerConfiguration = configuration;
}
public class SchedulerConfigurationConfigurator
{
private readonly ISchedulerConfiguration schedulerConfiguration;
public SchedulerConfigurationConfigurator(ISchedulerConfiguration schedulerConfiguration)
{
this.schedulerConfiguration = schedulerConfiguration;
}
public string JobRequestQueue
{
set { this.schedulerConfiguration.JobRequestsQueue = value; }
}
public string TaskResponseQueue
{
set { this.schedulerConfiguration.JobRequestsQueue = value; }
}
}
}
public interface IScheduler
{
}
class DefaultScheduler : IScheduler
{
}
public interface ISchedulerConfiguration
{
string JobRequestsQueue { get; set; }
string TaskResponseQueue { get; set; }
}
public class DefaultSchedulerConfiguration : ISchedulerConfiguration
{
public string JobRequestsQueue { get; set; }
public string TaskResponseQueue { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment