title: Turn `ReloadOnChange` off in config source for WebApplicationFactory
body: <p>This is both a question and an answer. I've fixed my problem, but it seems a bit wrong.</p>
  
  <p>My original problem is running my asp.net core integration tests in a bitbucket pipeline causes  <code>System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.</code> Some solutions call for changing some setting through <code>sysctl</code>, but that is <a href="https://confluence.atlassian.com/bitbucket/run-docker-commands-in-bitbucket-pipelines-879254331.html#RunDockercommandsinBitbucketPipelines-RunningDockercommands" rel="nofollow noreferrer">restricted by bitbucket</a>, so that isn't an option for me.</p>
  
  <p>The second way of fixing this, as noted in <a href="https://stackoverflow.com/questions/45875981/error-while-reading-json-file-in-dotnet-core-the-configured-user-limit-128-on">these stackoverflow answers</a>, is to turn <code>reloadOnChange</code> off.</p>
  
  <p>My new problem is now, how do we <em>best</em> do this for the test <code>WebApplicationFactory</code>?</p>
  
  <p>One solution that has worked for me, which is the least amount of code, seems like a total hack. I iterate through all the <code>JsonConfigurationSource</code> and set <code>ReloadOnChange</code> to <code>false</code>.</p>
  
  <p>Full solution:</p>
  
  <pre><code>public class TestApplicationFactory : WebApplicationFactory&lt;Startup&gt;
  {
      protected override void ConfigureWebHost(IWebHostBuilder builder)
      {
          builder.ConfigureAppConfiguration(config =&gt;
          {
              foreach (var source in config.Sources)
              {
                  if (source is JsonConfigurationSource)
                  {
                      var jsonConfigSource = (JsonConfigurationSource) source;
                      jsonConfigSource.ReloadOnChange = false;
                  }
              }
          });
      }
  }
  </code></pre>
  
  <p>Another solution, that I haven't tried, may be to <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.testing.webapplicationfactory-1.createwebhostbuilder?view=aspnetcore-3.0#Microsoft_AspNetCore_Mvc_Testing_WebApplicationFactory_1_CreateWebHostBuilder" rel="nofollow noreferrer">override <code>CreateWebHostBuilder()</code></a>. However, it seems like more code and a lot of copy and paste from the <a href="https://github.com/dotnet/aspnetcore/blob/v2.2.8/src/DefaultBuilder/src/WebHost.cs" rel="nofollow noreferrer">default one</a>.</p>
  
  <p>Am I missing something? Is there a better way to do this?</p>