Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Servus.Akka.Tests/ActorRefInjectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ResolvingTestActor()
[Fact]
public void Test1()
{
var a = Host.Services.GetService<IActorRef<ResolvingTestActor>>();
var a = Host.Services.GetService<ActorRef<ResolvingTestActor>>();
a.Tell("hello");
ExpectMsg("hello");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Akka.Hosting;
using Akka.Util;

namespace Servus.Akka;
namespace Servus.Akka.DependencyInjection;

public class ActorRef<TActor>(IActorRegistry registry) : IActorRef<TActor>
public sealed class ActorRef<TActor>(IActorRegistry registry) : IActorRef
where TActor : ActorBase
{
private readonly IActorRef _actorRef = registry.Get<TActor>();
Expand All @@ -13,10 +13,10 @@ public class ActorRef<TActor>(IActorRegistry registry) : IActorRef<TActor>

public bool Equals(IActorRef? other) => _actorRef.Equals(other);

public int CompareTo(IActorRef? other) => _actorRef.CompareTo(other);

public ISurrogate ToSurrogate(ActorSystem system) => _actorRef.ToSurrogate(system);

public int CompareTo(IActorRef? other) => _actorRef.CompareTo(other);

public int CompareTo(object? obj) => _actorRef.CompareTo(obj);

public ActorPath Path => _actorRef.Path;
Expand Down
7 changes: 0 additions & 7 deletions src/Servus.Akka/IActorRef.cs

This file was deleted.

21 changes: 21 additions & 0 deletions src/Servus.Akka/RegistryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Akka.Actor;
using Akka.Hosting;

namespace Servus.Akka;

public static class RegistryExtensions
{
public static IActorRef GetActor<T>(this IActorContext context) => context.System.GetActor<T>();
public static IActorRef GetActor<T>(this ActorSystem system) => system.GetRegistry().Get<T>();

public static bool TryGetActor<T>(this IActorContext context, out IActorRef actor) => context.System.TryGetActor<T>(out actor);
public static bool TryGetActor<T>(this ActorSystem system, out IActorRef actor) => system.GetRegistry().TryGet<T>(out actor);

public static bool TryGetActor(this IActorContext context, Type key, out IActorRef actor) => context.System.TryGetActor(key, out actor);
public static bool TryGetActor(this ActorSystem system, Type key, out IActorRef actor) => system.GetRegistry().TryGet(key, out actor);

public static Task<IActorRef> GetAsync<T>(this IActorContext context) => context.System.GetAsync<T>();
public static Task<IActorRef> GetAsync<T>(this ActorSystem system) => system.GetRegistry().GetAsync<T>();

public static IReadOnlyActorRegistry GetRegistry(this ActorSystem system) => ActorRegistry.For(system);
}
6 changes: 3 additions & 3 deletions src/Servus.Akka/Servus.Akka.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.Hosting" Version="1.5.44" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Servus.Core" Version="0.29.0-alpha.1" />
<PackageReference Include="Akka.Hosting" Version="[1.5.0,)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="[6.0.0,)" />
<PackageReference Include="Servus.Core" Version="[0.33.1,)" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/Servus.Akka/Startup/ActorRefProviderStartupContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Extensions.Hosting;
using Servus.Akka.DependencyInjection;
using Servus.Core.Application.Startup;

namespace Servus.Akka.Startup;

public class ActorRefProviderStartupContainer : IHostBuilderSetupContainer
{
public void ConfigureHostBuilder(IHostBuilder builder)
{
builder.UseServiceProviderFactory(new ActorRefProviderFactory());
}
}
Loading