Startup.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.HttpsPolicy;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using Microsoft.Extensions.Logging;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Serialization;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Threading.Tasks;
  16. using XYY.Authentication.Standard;
  17. using XYY.Core.Standard.ApiClient;
  18. using XYY.Core.Standard.Data.Infrastructure;
  19. using XYY.Data.Standard.Tasks;
  20. using XYY.Service.Standard.RegionService;
  21. using XYY.TaskTrack.Standard;
  22. namespace XYY.Api.Order
  23. {
  24. public class Startup
  25. {
  26. public Startup(IConfiguration configuration)
  27. {
  28. Configuration = configuration;
  29. }
  30. public IConfiguration Configuration { get; }
  31. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  32. // This method gets called by the runtime. Use this method to add services to the container.
  33. public void ConfigureServices(IServiceCollection services)
  34. {
  35. services.AddXYYService(new ServiceOption
  36. {
  37. USEDBTransferAsMVC = true,
  38. CacheType = DistributedCacheType.Memory,
  39. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  40. UseRabbit = true,
  41. //UseFiddler=true,
  42. }, Configuration);
  43. services.ConfigAspectCore("BoxService");
  44. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  45. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  46. services.AddControllers().AddNewtonsoftJson(options =>
  47. {
  48. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  49. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  50. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  51. });
  52. services.AddAuthentication(BasicAuthenticationScheme.DefaultScheme)
  53. .AddScheme<BasicAuthenticationOption, BasicAuthenticationHandler>(BasicAuthenticationScheme.DefaultScheme, null
  54. );
  55. services.AddXYYService(new ServiceOption
  56. {
  57. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  58. UseFinanceChargesRedis = true,
  59. FinanceChargesRedisConnection = "r-wz9o30bx758o8jhbrapd.redis.rds.aliyuncs.com",
  60. USEDBTransferAsMVC = false,
  61. UseRabbit = true
  62. }, Configuration);
  63. services.AddSingleton<Service.Standard.Finance.Charging.Attached.ITAttachedZipSet>();
  64. //ºöÂÔÖ¤Êé´íÎó
  65. ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
  66. {
  67. // local dev, just approve all certs
  68. return true;
  69. };
  70. }
  71. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  72. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  73. {
  74. if (env.IsDevelopment())
  75. {
  76. app.UseDeveloperExceptionPage();
  77. }
  78. app.UseStatusCodePages();
  79. app.UseRouting();
  80. app.UseCors(MyAllowSpecificOrigins);
  81. app.UseBasicAuthentication();
  82. app.UseAuthentication();
  83. app.UseAuthorization();
  84. app.UseWebSockets();
  85. app.UseEndpoints(endpoints =>
  86. {
  87. endpoints.MapControllers();
  88. });
  89. }
  90. }
  91. }