using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Amazon.AspNetCore.DataProtection.SSM; using Amazon; using Amazon.Util; using Microsoft.Extensions.Logging; namespace CloudMosaic.Frontend { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; ConfigureDynamoDB(); } 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) { services.Configure(Configuration.GetSection("AppOptions")); services.AddAWSService(); services.AddAWSService(); services.AddAWSService(); services.AddAWSService(); services.AddAWSService(); services.AddAWSService(); services.AddSingleton(); // This is the usual code we'd see to use Sql Server for our user // authentication. Instead, we've changed the application to use // an Amazon Cognito User Pool. // //services.AddDbContext(options => // options.UseSqlServer( // Configuration.GetConnectionString("DefaultConnection"))); //services.AddDefaultIdentity() // .AddEntityFrameworkStores(); services.AddCognitoIdentity(); services.ConfigureApplicationCookie(options => { options.LoginPath = new PathString("/Identity/Account/Login"); }); services.AddDataProtection().PersistKeysToAWSSystemsManager("/CloudMosaic/DataProtection"); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } private void ConfigureDynamoDB() { string value; if ((value = this.Configuration["AppOptions:TableGallery"]) != null) { AWSConfigsDynamoDB.Context.AddMapping(new TypeMapping(typeof(Models.Gallery), value)); } if ((value = this.Configuration["AppOptions:TableMosaic"]) != null) { AWSConfigsDynamoDB.Context.AddMapping(new TypeMapping(typeof(Models.Mosaic), value)); } } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddAWSProvider(this.Configuration.GetAWSLoggingConfigSection()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(); } } }