Reputation: 13387
I am trying to build a bot using Microsoft Bot Framework and Autofac. I have a service which is shared between 2 Dialogs and the first Dialog instantiates the other based on a user response. Inside my Dialog I invoke this line:
await context.Forward(new StepDialog(_productProvider, _groups, _products, 0), ResumeAfter, new Activity { Text = category }, CancellationToken.None);
But I don't think this is right. In my controller, I do this:
// Create our scope
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, model))
{
// Create our conversation
await Conversation.SendAsync(model, () => scope.Resolve<IDialog<object>>());
};
So I assume that I have to do something similar to get the instance of my StepDialog while maintaining the reference to the ProductProvider (which is my service).
I thought about passing the scope into the constructor of my initial Dialog but I have read that is a bad idea, so how can I go about this?
Upvotes: 1
Views: 337
Reputation: 14787
One idea that I have seen working pretty well is to use a Dialog Factory; so you inject that into your dialog and use it to resolve other dialogs.
In the ContosoFlowers sample you will find a basic implementation of a Dialog Factory. Below some reference links:
Upvotes: 3