Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[VA][Skill] fix event, remove BuildServiceProvider (#2579)
Browse files Browse the repository at this point in the history
BuildServiceProvider and runtime one are not same one
  • Loading branch information
xieofxie authored Oct 25, 2019
1 parent dc29c80 commit 3ace6a7
Show file tree
Hide file tree
Showing 18 changed files with 12 additions and 31 deletions.
1 change: 0 additions & 1 deletion skills/csharp/calendarskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/emailskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/experimental/automotiveskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/experimental/bingsearchskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
2 changes: 0 additions & 2 deletions skills/csharp/experimental/eventskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down
2 changes: 0 additions & 2 deletions skills/csharp/experimental/hospitalityskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down
2 changes: 0 additions & 2 deletions skills/csharp/experimental/itsmskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down
2 changes: 0 additions & 2 deletions skills/csharp/experimental/musicskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/experimental/newsskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/experimental/weatherskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/pointofinterestskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
1 change: 0 additions & 1 deletion skills/csharp/todoskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Expand Down
2 changes: 0 additions & 2 deletions templates/Skill-Template/csharp/Sample/SkillSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down
2 changes: 0 additions & 2 deletions templates/Skill-Template/csharp/Template/Skill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace VirtualAssistantSample.Dialogs
{
public class MainDialog : RouterDialog
{
private const string Location = "location";
private const string TimeZone = "timezone";
private BotServices _services;
private BotSettings _settings;
private TemplateEngine _templateEngine;
Expand Down Expand Up @@ -236,10 +238,10 @@ protected override async Task OnEventActivityAsync(DialogContext innerDc, Cancel
case Events.Location:
{
var locationObj = new JObject();
locationObj.Add(Events.Location, JToken.FromObject(value));
locationObj.Add(Location, JToken.FromObject(value));

var skillContext = await _skillContext.GetAsync(innerDc.Context, () => new SkillContext());
skillContext[Events.Location] = locationObj;
skillContext[Location] = locationObj;
await _skillContext.SetAsync(innerDc.Context, skillContext);

break;
Expand All @@ -251,10 +253,10 @@ protected override async Task OnEventActivityAsync(DialogContext innerDc, Cancel
{
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(value);
var timeZoneObj = new JObject();
timeZoneObj.Add(Events.TimeZone, JToken.FromObject(timeZoneInfo));
timeZoneObj.Add(TimeZone, JToken.FromObject(timeZoneInfo));

var skillContext = await _skillContext.GetAsync(innerDc.Context, () => new SkillContext());
skillContext[Events.TimeZone] = timeZoneObj;
skillContext[TimeZone] = timeZoneObj;
await _skillContext.SetAsync(innerDc.Context, skillContext);
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<OnboardingDialog>();

// Register skill dialogs
var provider = services.BuildServiceProvider();
foreach (var skill in settings.Skills)
{
var userState = provider.GetService<UserState>();
var telemetryClient = provider.GetService<IBotTelemetryClient>();
var authDialog = BuildAuthDialog(skill, settings, appCredentials);
var credentials = new MicrosoftAppCredentialsEx(settings.MicrosoftAppId, settings.MicrosoftAppPassword, skill.MSAappId);
services.AddTransient(sp => new SkillDialog(skill, credentials, telemetryClient, userState, authDialog));
services.AddTransient(sp =>
{
var userState = sp.GetService<UserState>();
var telemetryClient = sp.GetService<IBotTelemetryClient>();
return new SkillDialog(skill, credentials, telemetryClient, userState, authDialog);
});
}

// Configure adapters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

var provider = services.BuildServiceProvider();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);
Expand Down

0 comments on commit 3ace6a7

Please sign in to comment.