Skip to content

Commit 404da07

Browse files
pull request comment
Signed-off-by: Siri Varma Vegiraju <[email protected]>
1 parent 87eedfd commit 404da07

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void RegisterActor<TActor>(string actorTypeName, Action<ActorRegistration
7474
/// <typeparam name="TActor">Type of actor.</typeparam>
7575
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
7676
public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> configure = null)
77-
where TActorInterface : Actor
77+
where TActorInterface : IActor
7878
where TActor : Actor
7979
{
8080
RegisterActor<TActorInterface, TActor>(actorTypeName: null, configure);
@@ -88,7 +88,7 @@ public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> con
8888
/// <param name="typeOptions">An optional <see cref="ActorRuntimeOptions"/> that defines values for this type alone.</param>
8989
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
9090
public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptions, Action<ActorRegistration> configure = null)
91-
where TActorInterface : Actor
91+
where TActorInterface : IActor
9292
where TActor : Actor
9393
{
9494
RegisterActor(typeof(TActorInterface), typeof(TActor), null, typeOptions, configure);
@@ -103,7 +103,7 @@ public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptio
103103
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
104104
/// <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>
105105
public void RegisterActor<TActorInterface, TActor>(string actorTypeName, Action<ActorRegistration> configure = null)
106-
where TActorInterface : Actor
106+
where TActorInterface : IActor
107107
where TActor : Actor
108108
{
109109
RegisterActor(typeof(TActorInterface), typeof(TActor), actorTypeName, null, configure);

src/Dapr.Actors/Runtime/ActorTypeInformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static ActorTypeInformation Get(Type actorInterfaceType, Type actorType,
143143

144144
private static ActorTypeInformation GetInternal(Type actorInterfaceType, Type actorType, string actorTypeName)
145145
{
146-
if (actorInterfaceType != default && !actorInterfaceType.IsActor())
146+
if (actorInterfaceType != default && !actorInterfaceType.IsActorInterface())
147147
{
148148
throw new ArgumentException(
149149
string.Format(

test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ------------------------------------------------------------------------
1+
// ------------------------------------------------------------------------
22
// Copyright 2021 The Dapr Authors
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313

1414
using System.Linq;
1515
using System.Text.Json;
16+
using System.Threading.Tasks;
1617
using Dapr.Actors.Client;
1718
using Dapr.Actors.Runtime;
1819
using Microsoft.Extensions.DependencyInjection;
@@ -88,6 +89,25 @@ public void CanAccessProxyFactoryWithCustomJsonOptions()
8889
Assert.Same(jsonOptions, factory.DefaultOptions.JsonSerializerOptions);
8990
}
9091

92+
[Fact]
93+
public void CanRegisterActorsToSpecificInterface()
94+
{
95+
var services = new ServiceCollection();
96+
services.AddLogging();
97+
services.AddOptions();
98+
services.AddActors(options =>
99+
{
100+
options.Actors.RegisterActor<IMyActor, InternalMyActor>();
101+
});
102+
103+
var runtime = services.BuildServiceProvider().GetRequiredService<ActorRuntime>();
104+
105+
Assert.Collection(
106+
runtime.RegisteredActors.Select(r => r.Type.ActorTypeName).OrderBy(t => t),
107+
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor1), actorTypeName: null).ActorTypeName, t),
108+
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor2), actorTypeName: null).ActorTypeName, t));
109+
}
110+
91111
private interface ITestActor : IActor
92112
{
93113
}
@@ -107,5 +127,32 @@ public TestActor2(ActorHost host)
107127
{
108128
}
109129
}
130+
131+
public interface IMyActor : IActor
132+
{
133+
Task SomeMethod();
134+
}
135+
136+
public interface IInternalMyActor : IMyActor
137+
{
138+
void SomeInternalMethod();
139+
}
140+
141+
public class InternalMyActor : Actor, IInternalMyActor
142+
{
143+
public InternalMyActor(ActorHost host)
144+
: base(host)
145+
{
146+
}
147+
148+
public void SomeInternalMethod()
149+
{
150+
}
151+
152+
public Task SomeMethod()
153+
{
154+
return Task.CompletedTask;
155+
}
156+
}
110157
}
111158
}

0 commit comments

Comments
 (0)