From e59d489a0640f59df2d4957e23ce9bf7df0df0f9 Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Sun, 12 Sep 2021 00:29:47 -0500 Subject: [PATCH] fix: switched from default host builder to avoid directory scan on Linux --- src/MfGames.ToolBuilder/ToolBuilder.cs | 33 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/MfGames.ToolBuilder/ToolBuilder.cs b/src/MfGames.ToolBuilder/ToolBuilder.cs index cbd41f2..572e373 100644 --- a/src/MfGames.ToolBuilder/ToolBuilder.cs +++ b/src/MfGames.ToolBuilder/ToolBuilder.cs @@ -49,14 +49,31 @@ namespace MfGames.ToolBuilder this.loggingService.Configure(arguments); // Start up the basic configuration. - this.hostBuilder = Host - .CreateDefaultBuilder(arguments) - .UseConsoleLifetime() - .ConfigureAppConfiguration(this.ConfigureAppConfiguration) - .UseSerilog() - .UseServiceProviderFactory(new AutofacServiceProviderFactory()) - .ConfigureServices(this.ConfigureServices) - .ConfigureContainer(this.ConfigureContainer); + // + // Normally, we would use Host.CreateDefaultBuilder(args) to create + // this, but when run as a stand-alone application in someone's + // $HOME on Linux, this causes an inotify watcher to be registered + // on the entire directory tree (which takes a really long time). + // + // We also don't need most of the default features. + this.hostBuilder = + new HostBuilder() + .UseDefaultServiceProvider( + (context, options) => + { + bool isDevelopment = + context.HostingEnvironment.IsDevelopment(); + options.ValidateScopes = isDevelopment; + options.ValidateOnBuild = isDevelopment; + }) + .UseConsoleLifetime() + .ConfigureAppConfiguration(this.ConfigureAppConfiguration) + .UseSerilog() + .UseServiceProviderFactory( + new AutofacServiceProviderFactory()) + .ConfigureServices(this.ConfigureServices) + .ConfigureContainer( + this.ConfigureContainer); } ///