Startup.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. using XYY.Service.Strandard.EMailService;
  18. namespace XYY.Api.WarningNotice
  19. {
  20. public class Startup
  21. {
  22. public IConfiguration Configuration { get; }
  23. public Startup(IConfiguration configuration)
  24. {
  25. Configuration = configuration;
  26. }
  27. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  28. // This method gets called by the runtime. Use this method to add services to the container.
  29. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  30. public void ConfigureServices(IServiceCollection services)
  31. {
  32. services.AddXYYService(new ServiceOption
  33. {
  34. USEDBTransferAsMVC = true,
  35. CacheType = DistributedCacheType.Redis,
  36. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  37. RedisConnection = Configuration[DefaultConfig.RedisConnectionKey],
  38. UseRabbit = true
  39. }, Configuration);
  40. services.AddDistributedMemoryCache();
  41. services.AddSingleton<IWebHook>(x => new QYWXWebHook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5eb4675a-773a-40a0-9bad-745501122580"));
  42. services.AddSingleton<IEmailService, EmailService>();
  43. //services.AddTransient<IDingDingService, DingDingService>();
  44. services.AddTransient<IUserInfoRepository, UserInfoRepository>();
  45. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  46. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  47. services.AddMvcCore();
  48. //ºöÂÔÖ¤Êé´íÎó
  49. ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
  50. {
  51. // local dev, just approve all certs
  52. return true;
  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.UseEndpoints(endpoints =>
  66. {
  67. endpoints.MapControllers();
  68. });
  69. }
  70. }
  71. }