// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices( IServiceCollection services ) { services.AddControllersWithViews(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); var nginxConfigFileService = new NginxConfigFileService(); var nginxLauncher = this.Configuration.GetValue <bool>("NginxLauncher"); var nginxServiceName = this.Configuration.GetValue <string>("NginxServiceName"); var configNginxSection = this.Configuration.GetSection("Nginx"); var processFileDir = configNginxSection.GetValue <string>("ProcessFileDir"); var processFileName = configNginxSection.GetValue <string>("ProcessFileName"); nginxConfigFileService.Watch( configNginxSection.GetValue <string>("ConfigFileDir"), configNginxSection.GetValue <string>("ConfigFileName"), configNginxSection.GetValue <int>("ConfigFileWatchDebounceTimeMs")); if (nginxLauncher) { void processRestart() => WindowsProcessHelper.Restart( processFileDir, processFileName); processRestart(); nginxConfigFileService.UpstreamsChangedEvent += (s, e) => processRestart(); } else { void serviceRestart() => WindowsServiceHelper.Restart( nginxServiceName, processFileName); serviceRestart(); nginxConfigFileService.UpstreamsChangedEvent += (s, e) => serviceRestart(); } services.AddSingleton <INginxConfigFileService>(nginxConfigFileService); // adding as singleton ensures the connection stays active once constructed services.AddSingleton <INginxHubClient, NginxHubClient>(); services.AddSignalR(); }
public static async Task Main(string[] args) { try { var builder = CreateHostBuilder(args); using var host = builder.Build(); await host.StartAsync().ConfigureAwait(false); // create hub client after building host, to ensure all hub dependencies are setup var client = (INginxHubClient)host.Services.GetService(typeof(INginxHubClient)); await client.Connect("nginxHub").ConfigureAwait(false); await host.WaitForShutdownAsync().ConfigureAwait(false); } finally { WindowsProcessHelper.Stop(); } }