mirror of
https://github.com/Varorbc/PaySharp.git
synced 2026-10-19 14:21:46 +08:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
#if NETCOREAPP
|
|
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
|