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?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Eli Pulsifer
  • 713
  • 9
  • 25

3 Answers3

1

I believe you can achieve that by facilitating the Polymorphism in the Reliable Actors framework:

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

Another way to segregate that comes in mind is to break the public and internal functionality into more actors.

Rotem Varon
  • 1,597
  • 1
  • 15
  • 32
  • That's a good article but it doesn't explain how to gain access to a specific interface. Unless I missed something... – Eli Pulsifer Oct 07 '16 at 16:00
  • @EliPulsifer In the article "interface is used to generate a proxy class that can be used by clients to communicate with your actors" that means you can create with ActorProxy.Create the desired interface (public or internal) – Rotem Varon Oct 07 '16 at 16:25
  • That's what I thought as well but each concrete actor type has a single service Uri. When you have two interfaces that derive from IActor at the top level you get a compile time error requiring the use of the ActorService attribute to define the one service name to be used in the service Uri. Calling ActorService.Create generates the Uri from the interface type and will only work with a single interface. – Eli Pulsifer Oct 07 '16 at 20:25
1

When you have more than one interface, the runtime cannot generate the default name for the service. You need to apply https://msdn.microsoft.com/en-us/library/azure/microsoft.servicefabric.actors.runtime.actorserviceattribute.aspx

[ActorService(Name="MyActorService")] to your actor implementation. You can then create the actor proxy with this servicename using https://msdn.microsoft.com/en-us/library/azure/mt694503.aspx method.

VipulM-MSFT
  • 476
  • 3
  • 5
0

I found the answer with a little experimentation.

You can use any interface you want as long as the serviceUri specified in ActorProxy.Create call is the Uri to the actor. So, for my example above the following code will give access to the IInternalInterface.

ActorProxy.Create<IInternalInterface>(actorId, ActorNameFormat.GetFabricServiceUri(typeof(IPublicInterface)));
Eli Pulsifer
  • 713
  • 9
  • 25