Startup.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using XYY.Api.WarningNotice.WarningNoticeService;
  11. using XYY.Data.Standard;
  12. using XYY.Service.Standard.DingDing;
  13. using XYY.Service.Standard.RegionService;
  14. using Microsoft.Extensions.Configuration;
  15. using XYY.Common.Standard;
  16. using System.Net;
  17. namespace XYY.Api.WarningNotice
  18. {
  19. public class Startup
  20. {
  21. public IConfiguration Configuration { get; }
  22. public Startup(IConfiguration configuration)
  23. {
  24. Configuration = configuration;
  25. }
  26. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  27. // This method gets called by the runtime. Use this method to add services to the container.
  28. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddXYYService(new ServiceOption
  32. {
  33. USEDBTransferAsMVC = true,
  34. CacheType = DistributedCacheType.Redis,
  35. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  36. RedisConnection = Configuration[DefaultConfig.RedisConnectionKey],
  37. UseRabbit = true
  38. }, Configuration);
  39. services.AddDistributedMemoryCache();
  40. services.AddSingleton<IWebHook>(x => new QYWXWebHook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5eb4675a-773a-40a0-9bad-745501122580"));
  41. //services.AddTransient<IDingDingService, DingDingService>();
  42. services.AddTransient<IUserInfoRepository, UserInfoRepository>();
  43. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  44. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  45. services.AddMvcCore();
  46. //ºöÂÔÖ¤Êé´íÎó
  47. ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
  48. {
  49. // local dev, just approve all certs
  50. return true;
  51. };
  52. }
  53. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  54. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  55. {
  56. if (env.IsDevelopment())
  57. {
  58. app.UseDeveloperExceptionPage();
  59. }
  60. app.UseStatusCodePages();
  61. app.UseRouting();
  62. app.UseCors(MyAllowSpecificOrigins);
  63. app.UseEndpoints(endpoints =>
  64. {
  65. endpoints.MapControllers();
  66. });
  67. }
  68. }
  69. }