Startup.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. using XYY.Service.Standard.RegionService;
  7. using XYY.Authentication.Standard;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Serialization;
  10. using XYY.Service.Standard.First.DB;
  11. using XYY.Common.Standard;
  12. using Microsoft.Extensions.Caching.Memory;
  13. using Microsoft.CodeAnalysis;
  14. using System.Threading;
  15. namespace XYY.Api.First
  16. {
  17. public class Startup
  18. {
  19. public Startup(IConfiguration configuration)
  20. {
  21. Configuration = configuration;
  22. }
  23. public IConfiguration Configuration { get; }
  24. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  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.AddSingleton<IFirstDB>(x => new ESFirstDB(Configuration[DefaultConfig.ESUrlKey]));
  29. services.AddSingleton<IFirstDB2>(x => new ESFirstDB2(Configuration[DefaultConfig.ESUrlKey]));
  30. services.AddSingleton<ITrackingLogDB>(x => new TrackingLogDB(Configuration[DefaultConfig.ESUrlKey]));
  31. services.AddXYYService(new ServiceOption
  32. {
  33. RedisConnection = "r-wz9o30bx758o8jhbrapd.redis.rds.aliyuncs.com",
  34. PBESConnection = Configuration[DefaultConfig.ESUrlKey],
  35. USEDBTransferAsMVC = true,
  36. CacheType = DistributedCacheType.Memory,
  37. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  38. UseRabbit = true,
  39. UseTrackingPUSHRedis = true,
  40. }, Configuration);
  41. services.AddSingleton<IWebHook>(x => new QYWXWebHook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5eb4675a-773a-40a0-9bad-745501122580"));
  42. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  43. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  44. services.AddControllers().AddNewtonsoftJson(options =>
  45. {
  46. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  47. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  48. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  49. options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
  50. });
  51. services.AddAuthentication(BasicAuthenticationScheme.DefaultScheme)
  52. .AddScheme<BasicAuthenticationOption, BasicAuthenticationHandler>(BasicAuthenticationScheme.DefaultScheme, null
  53. );
  54. }
  55. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  56. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  57. {
  58. if (env.IsDevelopment())
  59. {
  60. app.UseDeveloperExceptionPage();
  61. }
  62. app.UseStatusCodePages();
  63. app.UseRouting();
  64. app.UseCors(MyAllowSpecificOrigins);
  65. app.UseBasicAuthentication();
  66. app.UseAuthentication();
  67. app.UseAuthorization();
  68. app.UseEndpoints(endpoints =>
  69. {
  70. endpoints.MapControllers();
  71. });
  72. }
  73. }
  74. }