我目前正在尝试使用akka.net,但他们使用HOCON的配置与配置 我们的应用的app.json中通常使用的json语法不同。 有谁知道如何在当前的app.json配置中使用HOCON?Akka.net asp.net 5 Hocon的mvc 6配置
2
A
回答
1
你可以做的是把HOCON在自己的文本文件,然后执行以下操作:
/// <summary>
/// Used to load HOCON definitions from a dedicated HOCON file
/// </summary>
public static class HoconLoader
{
/// <summary>
/// Parses a HOCON <see cref="Config" /> object from an underlying file
/// </summary>
/// <param name="path">The path to the HOCON file.</param>
/// <returns>A parsed <see cref="Config" /> object.</returns>
public static Config FromFile(string path)
{
return ConfigurationFactory.ParseString(File.ReadAllText(path));
}
}
然后传递hocon对象到ActorSystem.Create(字符串名称,配置配置)
不要忘记tp使文件“总是复制”或“如果更新”复制
0
我使用ConfigurationFactory.FromObject和一些具有我感兴趣的属性从appsettings读取akka配置的类。
var config = ConfigurationFactory.FromObject(new { akka = configuration.GetSection("Akka").Get<AkkaConfig>() });
actorSystem = ActorSystem.Create("Stimpy", config);
请注意,我一直没有弄清楚如何从appsettings解析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"
}
}
}
}
相关问题
- 1. Akka.Net的完整HOCON配置
- 2. 如何使用Appsetting配置Akka.Net 1.3.0在Asp.net核心配置
- 3. asp.net 5/mvc 6/model binder/angular
- 4. IPAddress null for MVC 6 ASP.NET 5
- 5. ASP.NET MVC 6中的Application_PreSendRequestHeaders和Application_BeginRequest(ASP.NET 5)
- 6. 区分MVC和WebAPI在ASP.NET 5/MVC 6
- 7. 在ASP.NET 5/asp.net中替换@helper mvc 6
- 8. 如何为asp.net MVC配置StructureMap 5
- 9. 使用ASP.NET MVC配置Autofac 5
- 10. 在ASP.NET 5中的Google OAuth MVC 6
- 11. 登录并注册ASP.NET MVC 5/6
- 12. ASP.NET 5 MVC 6 System.Management.Automation问题与DNX
- 13. ASP.NET 5 MVC 6 + Rest API身份
- 14. 在asp.net 5/mvc 6 PushStreamContent不工作
- 15. 在ASP.NET 5中组合ViewComponents MVC 6
- 16. RenderPartial()从哪里进入ASP.Net 5 MVC 6?
- 17. ASP.NET 5 MVC 6 XML响应标头
- 18. ASP.NET 5 MVC 6和Entity Framework 7问题
- 19. ASP.NET 5 MVC 6中会有SSRS reportviewer吗?
- 20. 应用程序设置的自定义类ASP.Net MVC 5 6
- 21. 使用.NET Core for framework net46的AKKA.NET配置
- 22. ASP.NET 5(vNext) - 配置
- 23. ASP.NET 5和MVC
- 24. MVC 4 ASP.NET配置
- 25. ASP.Net MVC 3配置
- 26. SQLDepedency ASP.NET MVC 6
- 27. taghelpers Intellisense在测试版5中缺少Asp.net 5 MVC 6
- 28. asp.net 5&mvc 6如何在dnx core 5中使用PersianCalendar?
- 29. 在asp.net 5中使用Linq to SQL 5 MVC 6
- 30. Asp.net MVC 5路由
您使用.NET的核心? – profesor79
@ profesor79是的,我正在使用.net核心 – HBbaale
在akka.net问这个问题gitter room https://gitter.im/akkadotnet/akka.net – profesor79