https://stackoverflow.com/questions/45875981/error-while-reading-json-file-in-dotnet-core-the-configured-user-limit-128-on

var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true);

You are creating file watchers, every time you access an setting. The 3rd parameter is reloadOnChange.

You have to make sure,

var configuration = builder.Build()

is only called once in your application and store it in a place where you can access it (preferably AVOID static fields for it).

Or just disable the file watcher.

  var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, false);

or cleaner:

var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", optional: true, reloadOnChange: false);

Best way is to abstract hat behind an interface and use dependency injection.

public interface IConfigurationManager
{
T GetAppConfig<T>(string key, T defaultValue = default(T));
} public class ConfigurationManager : IConfigurationManager
{
private readonly IConfigurationRoot config; public ConfigurationManager(IConfigurationRoot config)
=> this.config ?? throw new ArgumentNullException(nameof(config)); public T GetAppConfig<T>(string key, T defaultValue = default(T))
{
T setting = (T)Convert.ChangeType(configuration[key], typeof(T));
value = setting;
if (setting == null)
value = defaultValue;
}
}

Then instantiate and register it

services.AddSingleton<IConfigurationManager>(new ConfigurationManager(this.Configuration));

and inject it into your services via constructor

.net core 发布linux报错“The configured user limit (128) on the number of inotify instances has been reached”的更多相关文章

  1. 单元测试过多,导致The configured user limit (128) on the number of inotify instances has been reached.

    最近在一个asp.net core web项目中使用TDD的方式开发,结果单元测试超过128个之后,在CI中报错了:"The configured user limit (128) on t ...

  2. VSCode 出现错误 System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.

    方案一: sudo vim /etc/sysctl.conf 增加下面内容(环境变量) fs.inotify.max_user_watches = 1638400 fs.inotify.max_use ...

  3. 【docker】【redis】2.docker上设置redis集群---Redis Cluster部署【集群服务】【解决在docker中redis启动后,状态为Restarting,日志报错:Configured to not listen anywhere, exiting.问题】【Waiting for the cluster to join...问题】

    参考地址:https://www.cnblogs.com/zhoujinyi/p/6477133.html https://www.cnblogs.com/cxbhakim/p/9151720.htm ...

  4. eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“

    你的位置:首页 > Java编程 > eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“ eclipse发布项目报错:Multipl ...

  5. 64位linux报错Could not initialize class java.awt.image.BufferedImage

    最近碰到一个问题: 64位linux报错Could not initialize class java.awt.image.BufferedImage 在WIN平台下运行正常BufferedImage ...

  6. Linux报错之ping: www.baidu.com: Name or service not known

    Linux报错之ping: www.baidu.com: Name or service not known 出现这个以后,首先去ping下主机Ip,发现能ping通,但是出现另一个问题Destina ...

  7. Linux报错

    Linux报错 ------------------- 在VMware虚拟机中配置yum源时,执行 mount /dev/cdrom /mnt/cdrom 出现 mount: no medium fo ...

  8. iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容

    iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...

  9. FXP登录Linux报错

    1.用FXP登录Linux报错: [info] subsystem request for sftp failed, subsystem not found.[右] [execute] /usr/li ...

随机推荐

  1. ztree实现中国省市区树形,可多选

    首先表 CREATE TABLE `sys_area` ( `id` INT(11) NOT NULL COMMENT '编号', `parent_id` INT(11) NOT NULL COMME ...

  2. CentOS7 下安装GUI图形界面GNOME

    在安装Gnome包之前,需要检查一下网络是否有网络(使用ping www.baidu.com) 一.先装X windows,-y表示参数同意所有软件安装操,当出现 Complete!说明这里安装成功了 ...

  3. java程序员经常使用的Intellij Idea插件

    大概从去年年初开始慢慢抛弃习惯多年的eclipse,开始使用Intellij Idea,以下是我使用过的一些Intellij Idea插件: 1.lombok https://plugins.jetb ...

  4. 阿里云服务器配置phpstudy实现域名访问【图文教程】

    首先,运行phpStudy,确保Apache和MySql启动,绿色代表正常启动状态. 然后配置站点域名,打开phpStudy的站点域名管理,1.设置域名(你有的域名,最后需要域名解析):2.设置文件的 ...

  5. 7A - Max Sum

    Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. F ...

  6. [基础篇] 01_MySQL的安装与配置

  7. NodeManager介绍

    原文链接: http://blog.csdn.net/zhangzhebjut/article/details/37730013 参考文档: https://blog.csdn.net/u013384 ...

  8. window环境下修改postgrep密码

    本机window7 64位系统,安装的PostgreSQL 9.3 默认安装是没有设置密码的,使用pgAdmin III登陆需要登陆密码. 我们使用默认安装的工具 SQL Shell 来操作. 我们依 ...

  9. PostgreSQL时间段查询

    1.今日 select * from "表名" where to_date("时间字段"::text,'yyyy-mm-dd')=current_date 2. ...

  10. Git与SVN的区别(面试常问)

    1.Git是分布式的,而SVN不是分布式的 2.Git把内容按元数据方式存储,而SVN是按文件 3.Git没有一个全局版本号,SVN有,目前为止这是SVN相比Git缺少的最大的一个特征 4.Git的内 ...