using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.Extensibility; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.ApplicationInsights; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; using Microsoft.EntityFrameworkCore; using ProjectGrid.Data; namespace ProjectGrid { public class Startup { ILogger _logger; public Startup() { Configuration = new ConfigurationBuilder() .AddJsonFile("appSettings.json") // Get Connectionstring from appsetting.json .Build(); } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("DefaultConnection"); // Cant log here.. //_logger.LogInformation($"Try to connect to Database with {connectionString}"); services.AddDbContext(options => options.UseSqlServer(connectionString)); //_logger.LogInformation($"DataAccessContext registered with {connectionString}"); // TODO: for Testing //services.AddDatabaseDeveloperPageExceptionFilter(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ProjectGrid", Version = "v1" }); }); // Manager services.AddSingleton(new TicTacTocManager()); services.AddScoped(); // DataAccess services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger logger) { _logger = logger; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ProjectGrid v1")); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }