Startup.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.Extensions.Options;
  11. namespace NoName_CarplateRecognizeCamera_Lab
  12. {
  13. public class Startup
  14. {
  15. static NLog.Logger mainLogger = NLog.LogManager.LoadConfiguration("nlog.xml").GetLogger("Main");
  16. public Startup(IConfiguration configuration)
  17. {
  18. //Configuration = configuration;
  19. //using (var context = new ServiceDbContext())
  20. //{
  21. // context.Database.Migrate();
  22. //}
  23. }
  24. public IConfiguration Configuration { get; }
  25. // This method gets called by the runtime. Use this method to add services to the container.
  26. public void ConfigureServices(IServiceCollection services)
  27. {
  28. services.AddCors();
  29. services.AddMvc();
  30. //var ttt = Configuration.GetSection("ConnectionStrings");
  31. // When used with ASP.net core, add these lines to Startup.cs
  32. //var connectionString = Configuration.GetValue<string>("ConnectionStrings");//.GetConnectionString("ServiceDbContext");
  33. //services.AddEntityFrameworkNpgsql().AddDbContext<ServiceDbContext>(options => options.UseNpgsql(connectionString));
  34. //// and add this to appSettings.json
  35. //// "ConnectionStrings": { "BlogContext": "Server=localhost;Database=blog" }
  36. //services.AddScoped<DbContext, ServiceDbContext>();
  37. services.AddMvcCore().AddApiExplorer();
  38. // Register the Swagger generator, defining 1 or more Swagger documents
  39. services.AddSwaggerGen(c =>
  40. {
  41. //c.SwaggerDoc("v1", new SwaggerDoc { Title = "My API", Version = "v1" });
  42. });
  43. }
  44. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  45. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  46. {
  47. app.UseCors(builder => builder
  48. .AllowAnyOrigin()
  49. .AllowAnyMethod()
  50. .AllowAnyHeader()
  51. .AllowCredentials());
  52. //if (env.IsDevelopment())
  53. {
  54. app.UseDeveloperExceptionPage();
  55. }
  56. // Enable middleware to serve generated Swagger as a JSON endpoint.
  57. app.UseSwagger();
  58. // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
  59. // specifying the Swagger JSON endpoint.
  60. app.UseSwaggerUI(c =>
  61. {
  62. c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
  63. c.RoutePrefix = string.Empty;
  64. });
  65. app.UseMvc();
  66. }
  67. }
  68. }