在WebApplicationFactory的配置源中关闭`ReloadOnChange`

问题描述 投票:0回答:1

这既是一个问题,也是一个答案。我已经解决了我的问题,但是似乎有点不对。

我最初的问题是在bitbucket管道中运行我的asp.net核心集成测试会导致System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.,有些解决方案要求通过sysctl更改某些设置,但这就是restricted by bitbucket,所以这对我来说不是一个选择。

these stackoverflow answers中所述,解决此问题的第二种方法是关闭reloadOnChange

我的新问题是,我们如何[[最佳为此进行测试WebApplicationFactory

一种对我有用的解决方案,它是最少的代码,看起来像是完全黑客。我遍历所有JsonConfigurationSource并将ReloadOnChange设置为false

完整解决方案:

public class TestApplicationFactory : WebApplicationFactory<Startup> { protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureAppConfiguration(config => { foreach (var source in config.Sources) { if (source is JsonConfigurationSource) { var jsonConfigSource = (JsonConfigurationSource) source; jsonConfigSource.ReloadOnChange = false; } } }); } }

我没有尝试过的另一种解决方案可能是override CreateWebHostBuilder()。但是,似乎CreateWebHostBuilder()中有更多代码和大量复制和粘贴。

我想念什么吗?有更好的方法吗?

c# asp.net-core bitbucket-pipelines
1个回答
0
投票
[default one在这里配置您的(主)应用程序。

您可以使用builder.ConfigureAppConfiguration(请参阅builder.ConfigureHostConfiguration)为

主机显式配置要读取的文件。

docs
主机配置已加载。从3.0开始的ASP.NET Core是基于通用主机(而不是以前版本的Web主机)构建的。
© www.soinside.com 2019 - 2024. All rights reserved.