Assignment for Location Calculation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.8 KiB

  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.HttpsPolicy;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Configuration;
  7. using Microsoft.Extensions.DependencyInjection;
  8. using Microsoft.Extensions.DependencyInjection.Extensions;
  9. using Microsoft.Extensions.Hosting;
  10. using Microsoft.Extensions.Logging;
  11. using Microsoft.OpenApi.Models;
  12. using POCDistance.DAL;
  13. using POCDistance.Models;
  14. using POCDistance.Service;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Threading.Tasks;
  19. namespace POCDistance
  20. {
  21. public class Startup
  22. {
  23. public Startup(IConfiguration configuration)
  24. {
  25. Configuration = configuration;
  26. }
  27. public IConfiguration Configuration { get; }
  28. // This method gets called by the runtime. Use this method to add services to the container.
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddCors(options =>
  32. {
  33. options.AddPolicy(SecurityPolicy.SiteCorsPolicy, builder =>
  34. {
  35. builder.AllowAnyHeader();
  36. builder.AllowAnyMethod();
  37. builder.AllowAnyOrigin();
  38. });
  39. });
  40. //Added for session state
  41. services.AddDistributedMemoryCache();
  42. services.AddSession(options =>
  43. {
  44. options.IdleTimeout = TimeSpan.FromMinutes(10);
  45. });
  46. services.AddControllers();
  47. services.AddSwaggerGen(c =>
  48. {
  49. c.SwaggerDoc("v1", new OpenApiInfo { Title = "POCDistance", Version = "v1" });
  50. });
  51. //DI Implementation
  52. services.AddHttpContextAccessor();
  53. services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  54. services.TryAddScoped<IDataSourceAdapter, DataSourceAdapter>();
  55. services.TryAddScoped<ILocationService, LocationService>();
  56. }
  57. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  58. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  59. {
  60. if (env.IsDevelopment())
  61. {
  62. app.UseDeveloperExceptionPage();
  63. app.UseSwagger();
  64. app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "POCDistance v1"));
  65. }
  66. app.UseSession();
  67. app.UseHttpsRedirection();
  68. app.UseRouting();
  69. // UseCors with CorsPolicy defined
  70. app.UseCors(SecurityPolicy.SiteCorsPolicy);
  71. app.UseAuthorization();
  72. app.UseEndpoints(endpoints =>
  73. {
  74. endpoints.MapControllers();
  75. });
  76. }
  77. }
  78. }