I am using a autofac json file which has all my dependencies listed. For reference below is the json file.
{
"defaultAssembly": "DigitalAssistant.Wharf",
"components": [
{
"type": "DigitalAssistant.Dialogs.RootDialog, DigitalAssistant.Wharf",
"services": [
{
"type": "Microsoft.Bot.Builder.Dialogs.IDialog, Microsoft.Bot.Builder"
}
],
"injectProperties": true,
"instanceScope": "perlifetimescope"
}
]
}
My RootDialog class is as below:
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
// Calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// Return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters");
context.Wait(MessageReceivedAsync);
}
}
and inside the MessageController.cs, am resolving the dependency as below:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.GetActivityType() == ActivityTypes.Message)
{
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var dialog = scope.Resolve<IDialog<object>>();
await Conversation.SendAsync(activity, () => dialog);
}
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
The problem is, when is register the module through below code in Global.asax:
var config = new ConfigurationBuilder();
config.AddJsonFile("autofac.json");
var module = new ConfigurationModule(config.Build());
builder.RegisterModule(module);
it gives as error as The type DigitalAssistant.Dialogs.RootDialog is not assignable to service Microsoft.Bot.Builder.Dialogs.IDialog.
What am i missing here, please help.
Try adding the additional handeling while deserializing using the key-FiberModule.Key_DoNotSerialize like this
Or maybe you can try this approach.
In GlobalAsax.cs
In TestModule.cs
In MessagesController.cs