Program.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.Extensions.DependencyInjection.Extensions;
  4. using Microsoft.OpenApi.Models;
  5. using System.Security.Cryptography.Xml;
  6. var builder = WebApplication.CreateBuilder(args);
  7. builder.Services.Init();
  8. builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  9. builder.Services.AddControllers(option =>
  10. {
  11. option.Filters.Add(typeof(ResponseExceptionFilterAttribute));
  12. option.Filters.Add(typeof(MyAuthorizationFactory.MyActionFilter));
  13. });
  14. builder.Services.AddHostedService<TaskWorker>();
  15. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  16. builder.Services.AddEndpointsApiExplorer();
  17. builder.Services.AddSwaggerGen(option =>
  18. {
  19. option.AddSecurityDefinition("Authorization", new OpenApiSecurityScheme()
  20. {
  21. Description = "ÇëÊäÈë token",
  22. Name = "Authorization",
  23. In = ParameterLocation.Header,
  24. Type = SecuritySchemeType.ApiKey
  25. });
  26. option.AddSecurityRequirement(new OpenApiSecurityRequirement
  27. {
  28. {
  29. new OpenApiSecurityScheme
  30. {
  31. Reference = new OpenApiReference()
  32. {
  33. Type = ReferenceType.SecurityScheme,
  34. Id = "Bearer"
  35. }
  36. }, Array.Empty<string>()
  37. }
  38. });
  39. });
  40. builder.Services.AddCors(options =>
  41. {
  42. options.AddPolicy("AllowAll",
  43. builder =>
  44. {
  45. builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
  46. });
  47. });
  48. var app = builder.Build();
  49. // Configure the HTTP request pipeline.
  50. if (app.Environment.IsDevelopment())
  51. {
  52. app.UseSwagger();
  53. app.UseSwaggerUI();
  54. }
  55. //app.UseSwagger();
  56. //app.UseSwaggerUI();
  57. app.UseHttpsRedirection();
  58. app.UseAuthorization();
  59. app.MapControllers();
  60. app.UseCors("AllowAll"); // ÆôÓà CORS Öмä¼þ
  61. app.Run();