Startup.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.Api.Finance.Controllers;
  11. using XYY.Service.Standard.Finance;
  12. namespace XYY.Api.Finance
  13. {
  14. public class Startup
  15. {
  16. public Startup(IConfiguration configuration)
  17. {
  18. Configuration = configuration;
  19. }
  20. public IConfiguration Configuration { get; }
  21. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  22. // This method gets called by the runtime. Use this method to add services to the container.
  23. public void ConfigureServices(IServiceCollection services)
  24. {
  25. services.AddXYYService(new ServiceOption
  26. {
  27. PBESConnection = Configuration[DefaultConfig.ESUrlKey],
  28. USEDBTransferAsMVC = true,
  29. CacheType = DistributedCacheType.Redis,
  30. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  31. RedisConnection = Configuration[DefaultConfig.RedisConnectionKey],
  32. UseRabbit = true,
  33. }, Configuration);
  34. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  35. policy.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod()));
  36. services.AddControllers().AddNewtonsoftJson(options =>
  37. {
  38. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  39. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  40. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  41. });
  42. services.AddSignalR();
  43. services.AddAuthentication(BasicAuthenticationScheme.DefaultScheme)
  44. .AddScheme<BasicAuthenticationOption, BasicAuthenticationHandler>(BasicAuthenticationScheme.DefaultScheme, null
  45. );
  46. }
  47. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  48. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  49. {
  50. if (env.IsDevelopment())
  51. {
  52. app.UseDeveloperExceptionPage();
  53. }
  54. app.UseStatusCodePages();
  55. app.UseRouting();
  56. app.UseCors(MyAllowSpecificOrigins);
  57. app.UseWebSockets();
  58. app.UseBasicAuthentication();
  59. app.UseAuthentication();
  60. app.UseAuthorization();
  61. app.UseEndpoints(endpoints =>
  62. {
  63. endpoints.MapControllers();
  64. endpoints.MapHub<BatchInputHub>("/BatchInput");
  65. });
  66. }
  67. }
  68. }