1
0

Startup.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Essensoft.AspNetCore.Payment.Alipay;
  2. using Essensoft.AspNetCore.Payment.WeChatPay;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. namespace WebApplicationSample
  9. {
  10. public class Startup
  11. {
  12. public Startup(IConfiguration configuration)
  13. {
  14. Configuration = configuration;
  15. }
  16. public IConfiguration Configuration { get; }
  17. // This method gets called by the runtime. Use this method to add services to the container.
  18. public void ConfigureServices(IServiceCollection services)
  19. {
  20. // 引入Payment 依赖注入
  21. services.AddAlipay();
  22. services.AddWeChatPay();
  23. // 在 appsettings.json 中 配置选项
  24. services.Configure<AlipayOptions>(Configuration.GetSection("Alipay"));
  25. services.Configure<WeChatPayOptions>(Configuration.GetSection("WeChatPay"));
  26. services.AddControllersWithViews();
  27. }
  28. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  29. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  30. {
  31. if (env.IsDevelopment())
  32. {
  33. app.UseDeveloperExceptionPage();
  34. }
  35. else
  36. {
  37. app.UseExceptionHandler("/Home/Error");
  38. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  39. app.UseHsts();
  40. }
  41. app.UseHttpsRedirection();
  42. app.UseStaticFiles();
  43. app.UseRouting();
  44. app.UseAuthorization();
  45. app.UseEndpoints(endpoints =>
  46. {
  47. endpoints.MapControllerRoute(
  48. name: "default",
  49. pattern: "{controller=Home}/{action=Index}/{id?}");
  50. });
  51. }
  52. }
  53. }