Azure service fabric actor dependency injection

前端 未结 6 933
予麋鹿
予麋鹿 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:10

    Why not just use some root element field in actor, and resolve it from container with injected dependencies in Actor's constructor? If this is a bad decision, please explain why:

    public class StatelessActor2 : Actor, IStatelessActor2
    {
        private ConfiguredContainer _container;
        private IRootElement _rootElement;
    
        public StatelessActor2()
    
        {
            _container = new ConfiguredContainer(); //... container is configured in it's constructor
            _rootElement = _container.Resolve();
        }
    
        public async Task DoWorkAsync()
        {
            // Working with a RootElement with all dependencies are injected..
            return await Task.FromResult(_rootElement.WorkingWithInjectedStuff());
        }
    }
    

提交回复
热议问题