0.5.0
• Update Akka.NET from 1.4.41 to 1.4.43
• Add full options support to Akka.Persistence.SqlServer.Hosting
• Improved Akka.Remote.Hosting implementation
• Add a standardized option code pattern for Akka.Hosting developer
• Add Akka.Hosting.TestKit module for unit testing projects using Akka.Hosting
Full options support for Akka.Persistence.SqlServer.Hosting
You can now use an option class in Akka.Persistence.SqlServer.Hosting to replace HOCON configuration fully.
Add Akka.Hosting.TestKit
module
The biggest difference between Akka.Hosting.TestKit and Akka.TestKit is that, since the test is started asynchronously, the TestKit properties and methods would not be available in the unit test class constructor anymore. Since the spec depends on Microsoft HostBuilder
, configuration has to be broken down into steps. There are overridable methods that user can use to override virtually all of the setup process.
These are steps of what overridable methods gets called. Not all of the methods needs to be overriden, at the minimum, if you do not need a custom hosting environment, you need to override the ConfigureAkka
method.
-
ConfigureLogging(ILoggingBuilder)
Add custom logger and filtering rules on the
HostBuilder
level. -
ConfigureHostConfiguration(IConfigurationBuilder)
Inject any additional hosting environment configuration here, such as faking environment variables, in the
HostBuilder
level. -
ConfigureAppConfiguration(HostBuilderContext, IConfigurationBuilder)
Inject the application configuration.
-
ConfigureServices(HostBuilderContext, IServiceCollection)
Add additional services needed by the test, such as mocked up services used inside the dependency injection.
-
User defined HOCON configuration is injected by overriding the
Config
property, it is not passed as part of the constructor anymore. -
ConfigureAkka(AkkaConfigurationBuilder, IServiceProvider)
This is called inside
AddAkka
, use this to configure theAkkaConfigurationBuilder
-
BeforeTestStart()
This method is called after the TestKit is initialized. Move all of the codes that used to belong in the constructor here.
Akka.Hosting.TestKit
extends Akka.TestKit.TestKitBase
directly, all testing methods are available out of the box.
All of the properties, such as Sys
and TestActor
will be available once the unit test class is invoked.
Add a standardized option code pattern for Akka.Hosting developer
This new feature is intended for Akka.Hosting module developer only, it is used to standardize how Akka.Hosting addresses a very common HOCON configuration pattern. This allows for a HOCON-less programmatic setup replacement for the HOCON path used to configure the HOCON property.
The pattern:
# This HOCON property references to a config block below
akka.discovery.method = akka.discovery.config
akka.discovery.config {
class = "Akka.Discovery.Config.ConfigServiceDiscovery, Akka.Discovery"
# other options goes here
}
Example implementation:
// The base class for the option, needs to implement the IHoconOption template interface
public abstract class DiscoveryOptionBase : IHoconOption
{ }
// The actual option implementation
public class ConfigOption : DiscoveryOptionBase
{
// The path value in the akka.discovery.method property above
public string ConfigPath => "akka.discovery.config";
// The FQCN value in the akka.discovery.config.class property above
public Type Class => typeof(ConfigServiceDiscovery);
// Generate the same HOCON config as above
public void Apply(AkkaConfigurationBuilder builder, Setup setup = null)
{
// Modifies Akka.NET configuration either via HOCON or setup class
builder.AddHocon(
$"akka.discovery.method = {ConfigPath.ToHocon()}",
HoconAddMode.Prepend);
builder.AddHocon($"akka.discovery.config.class = {
Class.AssemblyQualifiedName.ToHocon()}",
HoconAddMode.Prepend);
// Rest of configuration goes here
}
}
// Akka.Hosting extension implementation
public static AkkaConfigurationBuilder WithDiscovery(
this AkkaConfigurationBuilder builder,
DiscoveryOptionBase discOption)
{
var setup = new DiscoverySetup();
// gets called here
discOption.Apply(builder, setup);
}