/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">IServiceCollection instance.</param> public void ConfigureServices(IServiceCollection services) { // Add all options set from configuration values. services.AddOptions <AuthenticationOptions>() .Configure <IConfiguration>((authenticationOptions, configuration) => { Startup.FillAuthenticationOptionsProperties(authenticationOptions, configuration); }); services.AddOptions <BotOptions>() .Configure <IConfiguration>((botOptions, configuration) => { botOptions.MicrosoftAppId = configuration.GetValue <string>("MicrosoftAppId"); botOptions.MicrosoftAppPassword = configuration.GetValue <string>("MicrosoftAppPassword"); }); services.AddOptions <BotFilterMiddlewareOptions>() .Configure <IConfiguration>((botFilterMiddlewareOptions, configuration) => { botFilterMiddlewareOptions.DisableTenantFilter = configuration.GetValue <bool>("DisableTenantFilter", false); botFilterMiddlewareOptions.AllowedTenants = configuration.GetValue <string>("AllowedTenants"); }); services.AddOptions <RepositoryOptions>() .Configure <IConfiguration>((repositoryOptions, configuration) => { repositoryOptions.StorageAccountConnectionString = configuration.GetValue <string>("StorageAccountConnectionString"); // Setting this to true because the main application should ensure that all // tables exist. repositoryOptions.EnsureTableExists = true; }); services.AddOptions <MessageQueueOptions>() .Configure <IConfiguration>((messageQueueOptions, configuration) => { messageQueueOptions.ServiceBusConnection = configuration.GetValue <string>("ServiceBusConnection"); }); services.AddOptions <DataQueueMessageOptions>() .Configure <IConfiguration>((dataQueueMessageOptions, configuration) => { dataQueueMessageOptions.ForceCompleteMessageDelayInSeconds = configuration.GetValue <double>("ForceCompleteMessageDelayInSeconds", 86400); }); services.AddOptions <UserAppOptions>() .Configure <IConfiguration>((options, configuration) => { options.ProactivelyInstallUserApp = configuration.GetValue <bool>("ProactivelyInstallUserApp", true); options.UserAppExternalId = configuration.GetValue <string>("UserAppExternalId", "148a66bb-e83d-425a-927d-09f4299a9274"); }); services.AddOptions(); // Add localization services. services.AddLocalizationSettings(this.Configuration); // Add authentication services. AuthenticationOptions authenticationOptionsParameter = new AuthenticationOptions(); Startup.FillAuthenticationOptionsProperties(authenticationOptionsParameter, this.Configuration); services.AddAuthentication(this.Configuration, authenticationOptionsParameter); services.AddControllersWithViews(); // Setup SPA static files. // In production, the React files will be served from this directory. services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); // Add blob client. services.AddSingleton(sp => new BlobContainerClient( sp.GetService <IConfiguration>().GetValue <string>("StorageAccountConnectionString"), Common.Constants.BlobContainerName)); // The bot needs an HttpClient to download and upload files. services.AddHttpClient(); // Add bot services. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); services.AddTransient <CompanyCommunicatorBotFilterMiddleware>(); services.AddSingleton <CompanyCommunicatorBotAdapter>(); services.AddTransient <TeamsDataCapture>(); services.AddTransient <TeamsFileUpload>(); services.AddTransient <IBot, CompanyCommunicatorBot>(); // Add repositories. services.AddSingleton <TeamDataRepository>(); services.AddSingleton <UserDataRepository>(); services.AddSingleton <SentNotificationDataRepository>(); services.AddSingleton <NotificationDataRepository>(); services.AddSingleton <ExportDataRepository>(); services.AddSingleton <AppConfigRepository>(); // Add service bus message queues. services.AddSingleton <PrepareToSendQueue>(); services.AddSingleton <DataQueue>(); services.AddSingleton <ExportQueue>(); // Add draft notification preview services. services.AddTransient <DraftNotificationPreviewService>(); // Add microsoft graph services. services.AddScoped <IAuthenticationProvider, GraphTokenProvider>(); services.AddScoped <IGraphServiceClient, GraphServiceClient>(); services.AddScoped <Beta.IGraphServiceClient, Beta.GraphServiceClient>(); services.AddScoped <IGraphServiceFactory, GraphServiceFactory>(); services.AddScoped <IGroupsService>(sp => sp.GetRequiredService <IGraphServiceFactory>().GetGroupsService()); services.AddScoped <IAppCatalogService>(sp => sp.GetRequiredService <IGraphServiceFactory>().GetAppCatalogService()); // Add Application Insights telemetry. services.AddApplicationInsightsTelemetry(); // Add miscellaneous dependencies. services.AddTransient <TableRowKeyGenerator>(); services.AddTransient <AdaptiveCardCreator>(); services.AddSingleton <IAppSettingsService, AppSettingsService>(); }