5

I'm slightly confused how AKKA.NET will be configured in a .NET Core application, where App.config has been replaced by project.json.

Will AKKA.NET still look for an App.Config? Or should I put the HOCON configuration inside project.json somehow?

What is the recommended practice?

Edit: A bit more trial-and-error has verifiedd that it is possible to add an App.config file to a .NET Core project and include a hocon section as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
  </configSections>
  <akka>
    <hocon>
    <![CDATA[
        akka {
                actor {
                    serializers {
                      wire = "Akka.Serialization.WireSerializer, Akka.Serialization.Wire"
                    }
                        serialization-bindings {
                        "System.Object" = wire
                        }
                    }
                }
    ]]>
    </hocon>
  </akka>
</configuration>

I'm still curious about finding out what is the recommended practice.

Nikola Schou
  • 2,386
  • 3
  • 23
  • 47

3 Answers3

2

As far as I can tell, there is no recommended practice at the moment. Akka .NET will announce plans to support .NET Core when .NET Core starts to at least faintly resemble something stable. Aaron Stannard wrote a blog post back in May explaining why it makes no sense for him to commit to a deadline supporting .NET Core when the .NET Core team is incapable of properly setting expectations from their end. I don't know if things have changed since then though.

Gigi
  • 28,163
  • 29
  • 106
  • 188
2

I really struggled to find a complete answer to this. However, I now have a working solution for me and wanted to share.

I wanted something that looked like a config file (so xml) this also helped with Visual Studio (particularly VS2019) not knowing what hocon is and complaining.

Here's my akka-hocon.conf file which lives in the project root.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <akka>
    <hocon>
      <![CDATA[          
          akka.persistence{
            ...
          }
      ]]>
    </hocon>
  </akka>
</configuration>

In the startup I then pass the hocon extracted from the CDATA to the ActorSystem like so:

var hoconFile = XElement.Parse(File.ReadAllText(Directory.GetCurrentDirectory() + "\\akka-hocon.conf"));
var config = ConfigurationFactory.ParseString(hoconFile.Descendants("hocon").Single().Value);
var actorSystem = ActorSystem.Create("SomeSystemName", config);
4imble
  • 13,979
  • 15
  • 70
  • 125
  • This maybe overkill and no use to anyone but I took your approach and wrapped it up in a NuGet package which can be found at https://www.nuget.org/packages/CJTech.HoconConfigReader/ – Chris May 29 '20 at 07:33
1

Update: Akka.NET supports .NET Standard 1.6 as of Akka.NET v1.3.0, which was released in August 2017.

See the full release notes here: https://github.com/akkadotnet/akka.net/releases/tag/v1.3.0

Aaronontheweb
  • 8,224
  • 6
  • 32
  • 61
  • 1
    But there is nothing about configuration there. – Hav Feb 09 '18 at 09:47
  • 1
    Yeah, we're working on a native solution for the new .NET Core configuration stuff. Didn't ship with one out of the box since .NET Core dropped support for App.config and a built-in solution wasn't clear at the time. – Aaronontheweb Feb 20 '18 at 19:35
  • Keen to know if anything has changed since that, I'm struggling to find any guidance of how to setup the Hocon in a .net core console app. @Aaronontheweb – Vinicius Paiva Aug 06 '18 at 09:53