public AzureDevOpsTalkerService(HttpClient httpClient, AzureDevOpsOAuthOptions devOpsOAuthOptions, IHttpContextAccessor httpContextAccessor, ILogger <AzureDevOpsTalkerService> logger) { _httpClient = httpClient; _devOpsOAuthOptions = devOpsOAuthOptions; _httpContextAccessor = httpContextAccessor; _logger = logger; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { AzureDevOpsOAuthOptions AzDevOpsOptions = new AzureDevOpsOAuthOptions(); AzDevOpsOptions.ClientId = Configuration["AzureAppId"]; AzDevOpsOptions.ClientSecret = Configuration["AzureClientSecret"]; AzDevOpsOptions.Scope.Add("vso.work_write"); // The following line enables Application Insights telemetry collection. services.AddApplicationInsightsTelemetry(); services.AddSnapshotCollector((configuration) => Configuration.Bind(nameof(SnapshotCollectorConfiguration), configuration)); services.AddMvc(); services.AddRazorPages(); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = AzureDevOpsAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { options.LoginPath = "/signin"; options.LogoutPath = "/signout"; }) .AddAzureDevOps(options => { // i couldn't figure out how to use only one of the AzDevOpsOptions objects :( options.ClientId = AzDevOpsOptions.ClientId; options.ClientSecret = AzDevOpsOptions.ClientSecret; options.Scope.Add("vso.work_write"); }); services.AddHttpClient <IAzureDevOpsTalkerService, AzureDevOpsTalkerService>(); services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]); services.AddSingleton <ICosmosDbService>(InitializeCosmosClientInstanceAsync(Configuration.GetSection("CosmosDb")).GetAwaiter().GetResult()); services.AddSingleton <IUserService>(_ => new UserService(Configuration["BasicAuth:UserName"], Configuration["BasicAuth:Password"])); IConfigurationSection injectionsSection = Configuration.GetSection("Injections"); List <Injection> injections = injectionsSection.Get <List <Injection> >(); services.AddSingleton <ICommentLinkerConfiguration>(_ => new CommentLinkerConfiguration(injections)); services.AddSingleton <AzureDevOpsOAuthOptions>(AzDevOpsOptions); services.AddHttpContextAccessor(); }