public SpotifyPlayerBotAccessors(ConversationState conversationState, OAuthService oAuthService, PlayerService playerService, CurrentTrackService currentTrackService, UIService uiService, SearchService searchService, ArtistsService artistsService, TracksService tracksService) { ConversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState)); OAuthService = oAuthService ?? throw new ArgumentNullException(nameof(oAuthService)); PlayerService = playerService ?? throw new ArgumentNullException(nameof(playerService)); CurrentTrackService = currentTrackService ?? throw new ArgumentNullException(nameof(currentTrackService)); UIService = uiService ?? throw new ArgumentNullException(nameof(uiService)); SearchService = searchService ?? throw new ArgumentNullException(nameof(searchService)); ArtistsService = artistsService ?? throw new ArgumentNullException(nameof(artistsService)); TracksService = tracksService ?? throw new ArgumentNullException(nameof(tracksService)); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.Configure <RazorViewEngineOptions>(o => { o.ViewLocationFormats.Clear(); o.ViewLocationFormats.Add("/Callback/Views/{1}/{0}" + RazorViewEngine.ViewExtension); }); var authorizationMapper = new AuthorizationMapper(); services.AddSingleton(typeof(IAuthorizationMapper), authorizationMapper); services.AddBot <SpotifyPlayerBot>(options => { var secretKey = Configuration.GetSection("botFileSecret")?.Value; var botConfig = BotConfiguration.Load(@".\Bots\SpotifyPlayerBot.bot", secretKey); services.AddSingleton(sp => botConfig); var service = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == "development").FirstOrDefault(); if (!(service is EndpointService endpointService)) { throw new InvalidOperationException($"The .bot file does not contain a development endpoint."); } options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword); options.OnTurnError = async(context, exception) => { await context.SendActivityAsync("Sorry, it looks like something went wrong."); }; }); var dataStore = new MemoryStorage(); var conversationState = new ConversationState(dataStore); var oAuthService = new OAuthService(authorizationMapper, Configuration.GetSection("spotifyAppId")?.Value, Configuration.GetSection("spotifyAppSecret")?.Value); var playerService = new PlayerService(); var currentTrackService = new CurrentTrackService(); var uiService = new UIService(oAuthService.GetAuthorizeUrl()); var searchService = new SearchService(); var artistsService = new ArtistsService(); var tracksService = new TracksService(); services.AddSingleton(serviceProvider => { var options = serviceProvider.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; var accessors = new SpotifyPlayerBotAccessors(conversationState, oAuthService, playerService, currentTrackService, uiService, searchService, artistsService, tracksService) { ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"), OAuthServiceState = conversationState.CreateProperty <OAuthService>("OAuthServiceState"), PlayerServiceState = conversationState.CreateProperty <PlayerService>("PlayerServiceState"), CurrentTrackServiceState = conversationState.CreateProperty <CurrentTrackService>("CurrentServiceState"), UIServiceState = conversationState.CreateProperty <UIService>("UIServiceState"), SearchServiceState = conversationState.CreateProperty <SearchService>("SearchServiceState"), ArtistsServiceState = conversationState.CreateProperty <ArtistsService>("ArtistsServiceState"), TracksServiceState = conversationState.CreateProperty <TracksService>("TracksServiceState") }; return(accessors); }); }