123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #if NETCOREAPP3_1
- using System;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Http;
- using PaySharp.Core;
- using PaySharp.Core.Utils;
- namespace Microsoft.Extensions.DependencyInjection
- {
- public static class ServiceCollectionExtensions
- {
- /// <summary>
- /// 添加PaySharp
- /// </summary>
- /// <param name="services"></param>
- /// <param name="setupAction"></param>
- public static void AddPaySharp(this IServiceCollection services, Action<IGateways> setupAction)
- {
- services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
- services.AddScoped<IGateways>(a =>
- {
- var gateways = new Gateways();
- setupAction(gateways);
- return gateways;
- });
- }
- /// <summary>
- /// 使用PaySharp
- /// </summary>
- /// <param name="app"></param>
- /// <returns></returns>
- public static IApplicationBuilder UsePaySharp(this IApplicationBuilder app)
- {
- var httpContextAccessor = app.ApplicationServices.GetRequiredService<IHttpContextAccessor>();
- HttpUtil.Configure(httpContextAccessor);
- return app;
- }
- }
- }
- #endif
|