Skip to content

Commit

Permalink
pull request comment
Browse files Browse the repository at this point in the history
Signed-off-by: Siri Varma Vegiraju <[email protected]>
  • Loading branch information
svegiraju-microsoft committed Sep 24, 2024
1 parent 87eedfd commit 404da07
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void RegisterActor<TActor>(string actorTypeName, Action<ActorRegistration
/// <typeparam name="TActor">Type of actor.</typeparam>
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> configure = null)
where TActorInterface : Actor
where TActorInterface : IActor
where TActor : Actor
{
RegisterActor<TActorInterface, TActor>(actorTypeName: null, configure);
Expand All @@ -88,7 +88,7 @@ public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> con
/// <param name="typeOptions">An optional <see cref="ActorRuntimeOptions"/> that defines values for this type alone.</param>
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptions, Action<ActorRegistration> configure = null)
where TActorInterface : Actor
where TActorInterface : IActor
where TActor : Actor
{
RegisterActor(typeof(TActorInterface), typeof(TActor), null, typeOptions, configure);
Expand All @@ -103,7 +103,7 @@ public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptio
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
/// <remarks>The value of <paramref name="actorTypeName"/> will have precedence over the default actor type name derived from the actor implementation type or any type name set via <see cref="ActorAttribute"/>.</remarks>
public void RegisterActor<TActorInterface, TActor>(string actorTypeName, Action<ActorRegistration> configure = null)
where TActorInterface : Actor
where TActorInterface : IActor
where TActor : Actor
{
RegisterActor(typeof(TActorInterface), typeof(TActor), actorTypeName, null, configure);
Expand Down
2 changes: 1 addition & 1 deletion src/Dapr.Actors/Runtime/ActorTypeInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static ActorTypeInformation Get(Type actorInterfaceType, Type actorType,

private static ActorTypeInformation GetInternal(Type actorInterfaceType, Type actorType, string actorTypeName)
{
if (actorInterfaceType != default && !actorInterfaceType.IsActor())
if (actorInterfaceType != default && !actorInterfaceType.IsActorInterface())
{
throw new ArgumentException(
string.Format(
Expand Down
49 changes: 48 additions & 1 deletion test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@

using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Dapr.Actors.Client;
using Dapr.Actors.Runtime;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -88,6 +89,25 @@ public void CanAccessProxyFactoryWithCustomJsonOptions()
Assert.Same(jsonOptions, factory.DefaultOptions.JsonSerializerOptions);
}

[Fact]
public void CanRegisterActorsToSpecificInterface()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddOptions();
services.AddActors(options =>
{
options.Actors.RegisterActor<IMyActor, InternalMyActor>();
});

var runtime = services.BuildServiceProvider().GetRequiredService<ActorRuntime>();

Assert.Collection(
runtime.RegisteredActors.Select(r => r.Type.ActorTypeName).OrderBy(t => t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor1), actorTypeName: null).ActorTypeName, t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor2), actorTypeName: null).ActorTypeName, t));
}

private interface ITestActor : IActor
{
}
Expand All @@ -107,5 +127,32 @@ public TestActor2(ActorHost host)
{
}
}

public interface IMyActor : IActor
{
Task SomeMethod();
}

public interface IInternalMyActor : IMyActor
{
void SomeInternalMethod();
}

public class InternalMyActor : Actor, IInternalMyActor
{
public InternalMyActor(ActorHost host)
: base(host)
{
}

public void SomeInternalMethod()
{
}

public Task SomeMethod()
{
return Task.CompletedTask;
}
}
}
}

0 comments on commit 404da07

Please sign in to comment.