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.

Startup.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.IO;
  2. using Luticate2.Utils.Controllers;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.EntityFrameworkCore;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.FileProviders;
  10. using Microsoft.Extensions.Logging;
  11. using TestUtils.DataAccess;
  12. using WebApiUtils.Business;
  13. using WebApiUtils.DataAccess;
  14. namespace WebApiUtils
  15. {
  16. public class Startup
  17. {
  18. public Startup(IHostingEnvironment env)
  19. {
  20. var builder = new ConfigurationBuilder()
  21. .SetBasePath(env.ContentRootPath)
  22. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  23. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  24. if (env.IsEnvironment("Development"))
  25. {
  26. // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
  27. builder.AddApplicationInsightsSettings(developerMode: true);
  28. }
  29. builder.AddEnvironmentVariables();
  30. Configuration = builder.Build();
  31. }
  32. public IConfigurationRoot Configuration { get; }
  33. // This method gets called by the runtime. Use this method to add services to the container
  34. public void ConfigureServices(IServiceCollection services)
  35. {
  36. // Add framework services.
  37. services.AddApplicationInsightsTelemetry(Configuration);
  38. services.AddLuticateUtils(options => options.Version = "dev");
  39. services.AddScoped<PkGuidBusiness>();
  40. services.AddScoped<LuUtilsPkGuidDataAccess>();
  41. services.AddScoped<UploadBusiness>();
  42. services.AddScoped<UploadDataAccess>();
  43. services.AddDbContext<LuUtilsDbContext>(options =>
  44. {
  45. options.UseNpgsql(Configuration.GetConnectionString("default"));
  46. options.UseInternalServiceProvider(new ServiceCollection()
  47. .AddEntityFrameworkNpgsqlLuticate()
  48. .AddEntityFrameworkNpgsql()
  49. .BuildServiceProvider());
  50. }, ServiceLifetime.Transient);
  51. services.AddMvc()
  52. .AddLuticateUtils();
  53. }
  54. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
  55. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  56. {
  57. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  58. loggerFactory.AddDebug();
  59. // app.UseApplicationInsightsRequestTelemetry();
  60. //
  61. // app.UseApplicationInsightsExceptionTelemetry();
  62. app.UseStaticFiles(new StaticFileOptions
  63. {
  64. ServeUnknownFileTypes = true,
  65. FileProvider = new PhysicalFileProvider("/tmp/luticate2"),
  66. RequestPath = new PathString("/upload")
  67. });
  68. app.UseLuticateUtils();
  69. app.UseMvc();
  70. }
  71. }
  72. }