Hokka的Akka.net asp.net 5 MVC 6配置 [英] Akka.net asp.net 5 mvc 6 configuration for Hocon
问题描述
我目前正在尝试使用akka.net,但它们使用HOCON的配置与配置时通常在app.json中通常使用的json语法不同. 我们的应用程序. 有人知道如何在当前的app.json配置中使用HOCON吗?
I am currently trying to use akka.net but the configuration they use HOCON is a different syntax from the json syntax normally used in app.json when configuring our app. Does anyone know how to use HOCON with the current app.json configuration?
推荐答案
我使用ConfigurationFactory.FromObject和一些具有我感兴趣的属性的类,以从appsettings中读取akka-config.
I use ConfigurationFactory.FromObject and some classes that has the properties that I'm interested in to read the akka-config from appsettings.
var config = ConfigurationFactory.FromObject(new { akka = configuration.GetSection("Akka").Get<AkkaConfig>() });
actorSystem = ActorSystem.Create("Stimpy", config);
请注意,我没有费心找出如何从appsettings解析kebab-case属性.因此,我刚刚重命名了除连字符以外的属性.然后将JsonProperty属性设置为正确的名称,以便FromObject可以正确地反序列化它.
Notice that I haven't bothered to figure out how to parse kebab-case properties from appsettings. So I have just renamed the properties excluding the hyphens. Then set the JsonProperty-attribute to the correct name so that FromObject can deserialize it correctly.
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:
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"
}
}
}
}
这篇关于Hokka的Akka.net asp.net 5 MVC 6配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!