Azure service fabric actor dependency injection

前端 未结 6 976
予麋鹿
予麋鹿 2021-01-01 14:17

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

6条回答
  •  悲哀的现实
    2021-01-01 15:07

    I know this is old but for documentations' sake DI is now supported in the Reliable Actor framework just like you would expect.

    public class ActorOne : Actor, IMyActor{
    
    private readonly IDependency _dependency;
    
    public ActorOne(IDependency dependency)
    {
        _dependency = dependency;
    }}
    

    And then you register the Actor with its dependency with the Service Fabric like this:

    using (FabricRuntime fRuntime = FabricRuntime.Create()){
    
    fRuntime.RegisterActor(() => new ActorOne(new MyDependency());
    Thread.Sleep(Timeout.Infinite);}
    

提交回复
热议问题