Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Startup.cs 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. using WebApiUtils.Dbo;
  15. namespace WebApiUtils
  16. {
  17. public class Startup
  18. {
  19. public Startup(IHostingEnvironment env)
  20. {
  21. var builder = new ConfigurationBuilder()
  22. .SetBasePath(env.ContentRootPath)
  23. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  24. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  25. if (env.IsEnvironment("Development"))
  26. {
  27. // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
  28. builder.AddApplicationInsightsSettings(developerMode: true);
  29. }
  30. builder.AddEnvironmentVariables();
  31. Configuration = builder.Build();
  32. }
  33. public IConfigurationRoot Configuration { get; }
  34. // This method gets called by the runtime. Use this method to add services to the container
  35. public void ConfigureServices(IServiceCollection services)
  36. {
  37. // Add framework services.
  38. services.AddApplicationInsightsTelemetry(Configuration);
  39. services.AddLuticateUtils(options => options.Version = "dev");
  40. services.AddScoped<PkGuidBusiness>();
  41. services.AddScoped<LuUtilsPkGuidDataAccess>();
  42. services.AddScoped<UploadBusiness>();
  43. services.AddScoped<UploadDataAccess>();
  44. services.Configure<AppConfigDbo>(dbo =>
  45. {
  46. dbo.UploadDir = "/tmp/luticate2";
  47. Directory.CreateDirectory(dbo.UploadDir);
  48. });
  49. services.AddDbContext<LuUtilsDbContext>(options =>
  50. {
  51. options.UseNpgsql(Configuration.GetConnectionString("default"));
  52. options.UseInternalServiceProvider(new ServiceCollection()
  53. .AddEntityFrameworkNpgsqlLuticate()
  54. .AddEntityFrameworkNpgsql()
  55. .BuildServiceProvider());
  56. }, ServiceLifetime.Transient);
  57. services.AddMvc()
  58. .AddLuticateUtils();
  59. }
  60. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
  61. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  62. {
  63. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  64. loggerFactory.AddDebug();
  65. // app.UseApplicationInsightsRequestTelemetry();
  66. //
  67. // app.UseApplicationInsightsExceptionTelemetry();
  68. // app.UseStaticFiles(new StaticFileOptions
  69. // {
  70. // ServeUnknownFileTypes = true,
  71. // FileProvider = new PhysicalFileProvider("/tmp/luticate2"),
  72. // RequestPath = new PathString("/uploadraw")
  73. // });
  74. app.UseLuticateUtils();
  75. app.UseMvc();
  76. }
  77. }
  78. }