3

Is there a way to create an actor that has two interfaces? I want to define the public interface in the Interfaces assembly and the internal interface in the actor assembly. The reason is to separate methods that clients should use and methods that the system should use.

For example:

class MyActor
    : Actor
    , IPublicInterface
    , IInternalInterface
{
    ...
}

It looks like this is not possible because the ActorService attribute only allows for a single name.

Is there a better way (that works) to segregate public and internal methods?

4

3 回答 3

1

我相信您可以通过促进 Reliable Actors 框架中的多态性来实现这一点:

https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-polymorphism/

想到的另一种隔离方法是将公共和内部功能分解为更多参与者。

于 2016-10-07T15:51:05.307 回答
1

当您有多个接口时,运行时无法为服务生成默认名称。您需要申请https://msdn.microsoft.com/en-us/library/azure/microsoft.servicefabric.actors.runtime.actorserviceattribute.aspx

[ActorService(Name="MyActorService")] 到你的演员实现。然后,您可以使用https://msdn.microsoft.com/en-us/library/azure/mt694503.aspx方法创建具有此服务名称的参与者代理。

于 2016-10-20T04:16:02.710 回答
0

我通过一些实验找到了答案。

您可以使用任何您想要的接口,只要在 ActorProxy.Create 调用中指定的 serviceUri 是演员的 Uri。因此,对于我上面的示例,以下代码将提供对 IInternalInterface 的访问权限。

ActorProxy.Create<IInternalInterface>(actorId, ActorNameFormat.GetFabricServiceUri(typeof(IPublicInterface)));
于 2016-10-07T15:59:31.530 回答