当前位置: 移动技术网 > IT编程>开发语言>.net > .net core 发布linux报错“The configured user limit (128) on the number of inotify instances has been reached”

.net core 发布linux报错“The configured user limit (128) on the number of inotify instances has been reached”

2019年01月10日  | 移动技术网IT编程  | 我要评论

思想汇报2012,差强人意是什么意思,公益海报设计大赛

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网