1

I want to use the WaitForSystemsManagerReloadToComplete() Extensions as documented in the "Reloading in AWS Lambda" section of this Read Me.

I believe I have written the right syntax to call it but since it is not an easy process to test I wanted to confirm the syntax. The code:

public class Program
{
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            return WebHost.CreateDefaultBuilder(args)
                      .ConfigureAppConfiguration(builder =>
                      {
                          builder
                            .AddSystemsManager("/AppName")
                            .Build()
                            .WaitForSystemsManagerReloadToComplete(TimeSpan.FromSeconds(5));
                      })
                      .UseStartup<Startup>();
        }
 }

My concern is that I although I call WaitForSystemsManagerReloadToComplete() in the Lambda Expression, I'm wondering if it affects the executing thread as designed.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Josh
  • 8,219
  • 13
  • 76
  • 123

1 Answers1

2

From looking at the samples on Github I would say that calling it in the expression is wrong. You should not have to build the configuration in the expression just to make that call. Instead move that code to the Startup and call it there.

public class Program {
    public static void Main(string[] args) {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
        return WebHost.CreateDefaultBuilder(args)
                  .ConfigureAppConfiguration(builder => {
                      builder.AddSystemsManager("/AppName");
                  })
                  .UseStartup<Startup>();
    }
}

Startup

public class Startup {
    public Startup(IConfiguration configuration) {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services) {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        //...
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
        if (env.IsDevelopment()) {
            app.UseDeveloperExceptionPage();
        }

        app.UseMvc();

        Configuration.WaitForSystemsManagerReloadToComplete(TimeSpan.FromSeconds(5));
    }
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • Good idea to call it later. I don't believe you need this line: services.Configure(Configuration.GetSection("settings")); – Josh May 31 '19 at 19:37
  • I copied it from the examples on the github. It really isn't needed in this case. – Nkosi May 31 '19 at 23:18