Service Fabric Actor Service Dependency Injection and Actor Events
<p>When an actor service spins up I would like to auto-subscribe to any of the events as <a href="https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-events/" rel="nofollow noreferrer">described in the documentation</a>. Manually subscribing to the events works. However when the service is instantiated is there a way to auto-subscribe the actor service, like in the OnActivateAsync()?</p>

<p>What I was trying to do was resolve this through dependency injection that on the instantiation of the MyActor class it passes in an Interface that the OnActivateAsync calls to subscribe events for the client. However I'm having problems with the dependency injection.</p>

<p>Using Microsoft.ServiceFabric.Actors.2.2.207 is supposed to support dependency injection in to actor services. Now when implementing the Microsoft.ServiceFabric.Actors.Runtime.Actor creates a default constructor with the ActorService and ActorId arguments.</p>

<p>I would like to add my own constructor that has an additional interface being passed in. How do you write the registration for the actor service to add the dependency? In the default Program.cs Main it provides this </p>

<pre><code>IMyInjectedInterface myInjectedInterface = null;

// inject interface instance to the UserActor
ActorRuntime.RegisterActorAsync&lt;MyActor&gt;(
   (context, actorType) =&gt; new ActorService(context, actorType, () =&gt; new MyActor(myInjectedInterface))).GetAwaiter().GetResult();
</code></pre>

<p>However on the line where it says "() => new MyActor(myInjectedInterface)" It tells me an error</p>

<blockquote>
  <p>Delegate 'Func' does not take 0
  arguments</p>
</blockquote>

<p>Looking at the constructor on the Actor class it has the following </p>

<p>MyActor.Cs</p>

<pre><code>internal class MyActor : Microsoft.ServiceFabric.Actors.Runtime.Actor, IMyActor
{
    private ActorService _actorService;
    private ActorId _actorId;
    private IMyInjectedInterface _myInjectedInterface;

    public SystemUserActor(IMyInjectedInterface myInjectedInterface, ActorService actorService = null, ActorId actorId = null) : base(actorService, actorId)
    {
        _actorService = actorService;
        _actorId = actorId;
        _myInjectedInterface = myInjectedInterface;
    }
}
</code></pre>

<p>1) How do I resolve the error I receive when trying to resolve the Actor Dependency?</p>

<blockquote>
  <p>Delegate 'Func' does not take 0
  arguments</p>
</blockquote>

<p>Bonus Question:</p>

<p>How do I resolve the IMyInjectedInterface for the interface instance to be injected into the actor service when called by my Stateless Service(calling client)?</p>