Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WithExtensions support #91

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Akka.Hosting/AkkaHostingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Akka.Actor;
using Akka.Actor.Setup;
using Akka.Configuration;
Expand Down Expand Up @@ -145,5 +146,31 @@ public static AkkaConfigurationBuilder WithActors(this AkkaConfigurationBuilder
return builder.StartActors(actorStarter);
}

/// <summary>
/// Adds a list of Akka.NET extensions that will be started automatically when the <see cref="ActorSystem"/>
/// starts up.
/// </summary>
/// <example>
/// <code>
/// // Starts distributed pub-sub, cluster metrics, and cluster bootstrap extensions at start-up
/// builder.WithExtensions(
/// typeof(DistributedPubSubExtensionProvider),
/// typeof(ClusterMetricsExtensionProvider),
/// typeof(ClusterBootstrapProvider));
/// </code>
/// </example>
/// <param name="builder">The builder instance being configured.</param>
/// <param name="extensions">A list of extension providers that will be automatically started
/// when the <see cref="ActorSystem"/> starts</param>
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder WithExtensions(
this AkkaConfigurationBuilder builder,
params Type[] extensions)
{
builder.AddHocon(
$"akka.extensions=[{string.Join(", ", extensions.Select(s => $"\"{s.AssemblyQualifiedName}\""))}]",
HoconAddMode.Prepend);
return builder;
}
}
}