Startup.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.AddSingleton<IESBTrackingLogDB>(x => new ESBTrackingLogDB(Configuration[DefaultConfig.ESUrlKey]));
  32. services.AddXYYService(new ServiceOption
  33. {
  34. RedisConnection = "r-wz9o30bx758o8jhbrapd.redis.rds.aliyuncs.com",
  35. PBESConnection = Configuration[DefaultConfig.ESUrlKey],
  36. USEDBTransferAsMVC = true,
  37. CacheType = DistributedCacheType.Memory,
  38. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  39. UseRabbit = true,
  40. UseTrackingPUSHRedis = true,
  41. }, Configuration);
  42. services.AddSingleton<IWebHook>(x => new QYWXWebHook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5eb4675a-773a-40a0-9bad-745501122580"));
  43. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  44. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  45. services.AddControllers().AddNewtonsoftJson(options =>
  46. {
  47. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  48. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  49. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  50. options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
  51. });
  52. services.AddAuthentication(BasicAuthenticationScheme.DefaultScheme)
  53. .AddScheme<BasicAuthenticationOption, BasicAuthenticationHandler>(BasicAuthenticationScheme.DefaultScheme, null
  54. );
  55. }
  56. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  57. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  58. {
  59. if (env.IsDevelopment())
  60. {
  61. app.UseDeveloperExceptionPage();
  62. }
  63. app.UseStatusCodePages();
  64. app.UseRouting();
  65. app.UseCors(MyAllowSpecificOrigins);
  66. app.UseBasicAuthentication();
  67. app.UseAuthentication();
  68. app.UseAuthorization();
  69. app.UseEndpoints(endpoints =>
  70. {
  71. endpoints.MapControllers();
  72. });
  73. }
  74. }
  75. }