-
Notifications
You must be signed in to change notification settings - Fork 2
/
SettleModule.cs
41 lines (37 loc) · 1.75 KB
/
SettleModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.IO;
using Autofac;
using Newtonsoft.Json;
using Sp.Settle.Constants;
using Sp.Settle.Internal;
using Sp.Settle.Providers.AliPay;
using Sp.Settle.Providers.ApplePay;
using Sp.Settle.Providers.CmbPay;
using Sp.Settle.Providers.JdPay;
using Sp.Settle.Providers.UnionPay;
using Sp.Settle.Providers.WeChat;
namespace Sp.Settle
{
public class SettleModule : Module
{
private readonly SettleOptions _options;
public SettleModule()
{
var basePath = AppDomain.CurrentDomain.BaseDirectory;
if (!basePath.EndsWith("bin", StringComparison.CurrentCultureIgnoreCase)) basePath = $@"{basePath}\bin";
var json = File.ReadAllText($@"{basePath}\SettleOptions.json");
_options = JsonConvert.DeserializeObject<SettleOptions>(json);
}
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => _options).SingleInstance();
builder.RegisterType<SettleService>().As<ISettleService>().InstancePerLifetimeScope();
builder.RegisterType<AlipayChannel>().Keyed<ISettleChannel>(Provider.Alipay).InstancePerLifetimeScope();
builder.RegisterType<WeChatChannel>().Keyed<ISettleChannel>(Provider.WeChat).InstancePerLifetimeScope();
builder.RegisterType<JdPayChannel>().Keyed<ISettleChannel>(Provider.JdPay).InstancePerLifetimeScope();
builder.RegisterType<ApplePayChannel>().Keyed<ISettleChannel>(Provider.ApplePay).InstancePerLifetimeScope();
builder.RegisterType<UnionPayChannel>().Keyed<ISettleChannel>(Provider.UnionPay).InstancePerLifetimeScope();
builder.RegisterType<CmbPayChannel>().Keyed<ISettleChannel>(Provider.CmbPay).InstancePerLifetimeScope();
}
}
}