configuration - Hocon 的 Akka.net asp.net 5 mvc 6 配置

标签 configuration asp.net-core-mvc asp.net-core-1.0 akka.net

我目前正在尝试使用 akka.net,但他们使用 HOCON 的配置与配置时 app.json 中通常使用的 json 语法不同。 我们的应用程序。 有谁知道如何在当前的 app.json 配置中使用 HOCON 吗?

最佳答案

我使用 ConfigurationFactory.FromObject 和一些具有我感兴趣的属性的类来从 appsettings 读取 akka-config。

var config = ConfigurationFactory.FromObject(new { akka = configuration.GetSection("Akka").Get<AkkaConfig>() });

actorSystem = ActorSystem.Create("Stimpy", config);

请注意,我没有费心去弄清楚如何从应用程序设置中解析 kebab-case 属性。所以我刚刚重命名了不包括连字符的属性。然后将 JsonProperty 属性设置为正确的名称,以便 FromObject 可以正确反序列化它。

public class AkkaConfig
{
    [JsonProperty(PropertyName = "log-config-on-start")]
    public string logconfigonstart { get; set; }
    [JsonProperty(PropertyName = "stdout-loglevel")]
    public string stdoutloglevel { get; set; }
    public string loglevel { get; set; }
    public string[] loggers { get; set; }
    public ActorConfig actor { get; set; }

    public class ActorConfig
    {
        public DebugConfig debug { get; set; }
        public Dictionary<string, string> serializers { get; set; }
        [JsonProperty(PropertyName = "serialization-bindings")]
        public Dictionary<string, string> serializationbindings { get; set; }

        public class DebugConfig
        {
            public string receive { get; set; }
            public string autoreceive { get; set; }
            public string lifecycle { get; set; }
            [JsonProperty(PropertyName = "event-stream")]
            public string eventstream { get; set; }
            public string unhandled { get; set; }
        }
    }
}

appsettings.json:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Trace"
    }
  },
  "Hosting": {
    "Url": "http://*:1890"
  },

  "Akka": {
    "logconfigonstart":"on",
    "stdoutloglevel":"INFO",
    "loglevel": "DEBUG",
    "loggers": [ "Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog" ],

    "actor": {
      "debug": {
        "receive": "on",
        "autoreceive": "on",
        "lifecycle": "on",
        "eventstream": "on",
        "unhandled": "on"
      },
      "serializers": {
        "hyperion": "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
      },
      "serializationbindings": {
        "System.Object": "hyperion"
      }
    }
  }
}

关于configuration - Hocon 的 Akka.net asp.net 5 mvc 6 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36699889/

相关文章:

linux - 使用 jboss 7.1 将图像显示为 url

Eclipse - 更改当前标签的开始和结束标签的背景颜色

asp.net-core - 在 web.config 中未检测到 system.identityModel

c# - ASP.NET Core 相当于 ASP.NET MVC 5 的 HttpException

javascript - 如何使用私有(private)方法正确配置 ES6 类的 eslint?

typescript - 在 NX monorepo : (cannot read undefined (reading 'projects' ) 中启动应用程序时出现问题

asp.net-core - 如何在我的 ASP.NET core WebApi 项目中全局启用 CORS

c# - 在完整的 .NET 框架上测试 Asp.Net Core

asp.net-core - .net 核心在单一操作方法上覆盖 Controller 级别授权属性

.net-core - 如何在 .NET Core 控制台应用程序中获取 "Manage User Secrets"?