Skip to content

Commit c463186

Browse files
Address more changes
Signed-off-by: Siri Varma Vegiraju <[email protected]>
1 parent 404da07 commit c463186

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void RegisterActor<TActor>(string actorTypeName, Action<ActorRegistration
7575
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
7676
public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> configure = null)
7777
where TActorInterface : IActor
78-
where TActor : Actor
78+
where TActor : Actor, TActorInterface
7979
{
8080
RegisterActor<TActorInterface, TActor>(actorTypeName: null, configure);
8181
}
@@ -89,7 +89,7 @@ public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> con
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)
9191
where TActorInterface : IActor
92-
where TActor : Actor
92+
where TActor : Actor, TActorInterface
9393
{
9494
RegisterActor(typeof(TActorInterface), typeof(TActor), null, typeOptions, configure);
9595
}
@@ -104,7 +104,7 @@ public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptio
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)
106106
where TActorInterface : IActor
107-
where TActor : Actor
107+
where TActor : Actor, TActorInterface
108108
{
109109
RegisterActor(typeof(TActorInterface), typeof(TActor), actorTypeName, null, configure);
110110
}

src/Dapr.Actors/Runtime/ActorTypeExtensions.cs

+1-1
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.

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

+29-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// limitations under the License.
1212
// ------------------------------------------------------------------------
1313

14+
using System;
1415
using System.Linq;
1516
using System.Text.Json;
1617
using System.Threading.Tasks;
@@ -104,8 +105,33 @@ public void CanRegisterActorsToSpecificInterface()
104105

105106
Assert.Collection(
106107
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));
108+
t => Assert.Equal(ActorTypeInformation.Get(typeof(IMyActor), typeof(InternalMyActor), actorTypeName: null).ActorTypeName, t));
109+
110+
Assert.Collection(
111+
runtime.RegisteredActors.Select(r => r.Type.InterfaceTypes.First()).OrderBy(t => t),
112+
t => Assert.Equal(ActorTypeInformation.Get(typeof(IMyActor), typeof(InternalMyActor), actorTypeName: null).InterfaceTypes.First(), t));
113+
114+
Assert.True(runtime.RegisteredActors.First().Type.InterfaceTypes.Count() == 1);
115+
}
116+
117+
[Fact]
118+
public void RegisterActorThrowsArgumentExceptionWhenAnyInterfaceInTheChainIsNotIActor()
119+
{
120+
var services = new ServiceCollection();
121+
services.AddLogging();
122+
services.AddOptions();
123+
services.AddActors(options =>
124+
{
125+
Assert.Throws<ArgumentException>(() => options.Actors.RegisterActor<INonActor1, InternalMyActor>());
126+
});
127+
}
128+
129+
private interface INonActor
130+
{
131+
}
132+
133+
private interface INonActor1 : INonActor, IActor
134+
{
109135
}
110136

111137
private interface ITestActor : IActor
@@ -138,7 +164,7 @@ public interface IInternalMyActor : IMyActor
138164
void SomeInternalMethod();
139165
}
140166

141-
public class InternalMyActor : Actor, IInternalMyActor
167+
public class InternalMyActor : Actor, IInternalMyActor, INonActor1
142168
{
143169
public InternalMyActor(ActorHost host)
144170
: base(host)

0 commit comments

Comments
 (0)