Reputation: 21
I've been searching for a day and a half now and still can't find a solution.
For a bot I'm making it is necessary to do a few api calls with the received data from the client. However I can't figure out how to dependency injection in a constructor that inherits from DialogContainer.
I've tried to use property injection and constructor injection from autofac. I tried to add a second constructor who does the DI but the result was that the needed surface were null. And the same for the property injection, the services always return null.
When using a dialog in BotFramework v4, I've noticed you have to do the conversation in the constructor. I assume the reason why it won't work is because all the bot logic is in a constructor so autofac isn't able to properly wire up the services.
Upvotes: 2
Views: 552
Reputation: 843
This is an active topic for botframework-v4 on GitHub right now. Here is a good link to the GH repo summarizing the situation. There is an excellent comment written by drub0y.
Essentially, middleware is only run once when initializing the constructor, and there isn't currently a way to inject scoped dependencies.
Since this is still an active topic, I'm optimistic that there will be new information available on scoped dependency injection in the near future.
Upvotes: 2