public static IBot CreateBot(string skillName, IServiceProvider serviceProvider) { var manifests = StartupHelpers.GetSkillManifestInstances(serviceProvider); var foundManifest = manifests.Find(x => x.name.Equals(skillName)); if (foundManifest == null) { throw new ArgumentException($"Manifest details for skill: {skillName} could not be found out of ${manifests.Count} available manifests"); } if (foundManifest.RelatedDialogType == null) { throw new ArgumentException($"Manifest details for skill: {skillName} were found but RelatedDialogType was null"); } var dialog = (Dialog)serviceProvider.GetService(foundManifest.RelatedDialogType); var skillBotBase = (SkillBotBase)serviceProvider.GetService(typeof(SkillBotBase)); skillBotBase.SetDialog(dialog); return(skillBotBase); }
public void ConfigureBotsAndDialogsAndManfest(IServiceCollection services) { var skillDialogs = StartupHelpers.GetDialogsToDependencyInject(); //register dialogs foreach (var dialog in skillDialogs) { services.AddTransient(dialog); } services.AddTransient <SkillBotBase>(); services.AddOptions <SkillManifestOptions>().Bind(Configuration.GetSection(SkillManifestOptions.SkillManifest)); var skillManifests = StartupHelpers.GetSkillManifestToDependencyInject(); //register bots foreach (var manifest in skillManifests) { services.AddSingleton(manifest); } }