Azure Service Fabric Actor依赖项注入 [英] Azure service fabric actor dependency injection

查看:86
本文介绍了Azure Service Fabric Actor依赖项注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将依赖项注入到Azure Service Fabric Actor的构造函数中?

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

推荐答案

前一阵子,在dotPeek上有一个关于这个方面的挖掘(试图从Autofac解决参与者)每次调用的生命周期范围),我认为诀窍是创建您自己的StatelessActorServiceFactory实现,以及您自己的扩展方法来向其注册actor。尽管工厂类被标记为内部类,但其接口(IStatelessServiceFactory)和它创建的服务类型(StatelessActorServiceInstance)都是公共的。不幸的是,StatelessActorServiceInstance看起来并不是可扩展的(我希望这只是一个疏忽)。

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).

不幸的是,看起来WcfActorCommunicationProvider也已被标记作为内部的,因此您几乎必须从头开始创建自己的管道:

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


  1. 实现自己的IStatelessServiceFactory

  2. 实施您自己的IStatelessServiceInstance,IActorService

  3. 实施您自己的IActorCommunicationProvider

  4. 实施您自己的IActorHost

  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? :-/

那是我现在放弃的地方。考虑到公共API的相对不成熟,我认为现在不值得尝试自己动手做,因为如果这种功能全部出现,他们可能会打破这种方式您自己实施的任何东西。

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.

这篇关于Azure Service Fabric Actor依赖项注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆