Search code examples
c#dependency-injectionazure-service-fabricactor

Azure service fabric actor dependency injection


Is there any way to inject dependencies in to the Azure Service Fabric Actor's constructor?


Solution

  • Having had a bit of a dig-around in this area with dotPeek a while back (trying to resolve actors from an Autofac lifetime scope per-invocation), I think the trick is to create your own implementation of StatelessActorServiceFactory, and your own extension method to register the actor with it. Although the factory class is marked as internal, its interface (IStatelessServiceFactory) and the service type it creates (StatelessActorServiceInstance) are both public. Unfortunately, it doesn't look like StatelessActorServiceInstance was designed to be extensible (I'm hoping this is just an oversight).

    Unfortunately, it looks like WcfActorCommunicationProvider is also marked as internal so you'll pretty much have to create your own pipeline from scratch:

    1. Implement your own IStatelessServiceFactory
    2. Implement your own IStatelessServiceInstance, IActorService
    3. Implement your own IActorCommunicationProvider
    4. Implement your own IActorHost

    Doesn't really seem worth the effort anymore, does it? :-/

    That's where I gave up for now. I don't think it's worth trying to roll-your-own for now given the relative immaturity of the public API, since if this sort of functionality will show up at all, they'll probably do so in a way that'll break anything your implement yourself.