2022-05-01 16:25:03 +08:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2021-07-27 18:37:11 +08:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
2021-12-28 14:05:39 +08:00
|
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.Api.Sample
|
2021-07-27 18:37:11 +08:00
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddControllers();
|
|
|
|
|
|
2022-05-01 16:25:03 +08:00
|
|
|
|
// 注入配置项(内容见 `appsettings.json` 文件)
|
2021-07-27 18:37:11 +08:00
|
|
|
|
services.AddOptions();
|
|
|
|
|
services.Configure<Options.WechatOptions>(Configuration.GetSection(nameof(Options.WechatOptions)));
|
|
|
|
|
|
2022-05-01 16:25:03 +08:00
|
|
|
|
// 注入分布式锁
|
2021-07-27 18:37:11 +08:00
|
|
|
|
services.AddSingleton<Services.DistributedLock.IDistributedLockFactory, Services.DistributedLock.Implements.DistributedLockFactory>();
|
|
|
|
|
|
2022-05-01 16:25:03 +08:00
|
|
|
|
// 注入仓储类
|
2021-07-27 18:37:11 +08:00
|
|
|
|
services.AddSingleton<Services.Repositories.IWechatAccessTokenEntityRepository, Services.Repositories.Implements.WechatAccessTokenEntityRepository>();
|
|
|
|
|
|
2022-05-01 16:25:03 +08:00
|
|
|
|
// 注入工厂 HTTP 客户端
|
2021-07-27 18:37:11 +08:00
|
|
|
|
services.AddHttpClient();
|
2024-01-29 23:11:56 +08:00
|
|
|
|
services.AddSingleton<Services.HttpClients.IWechatApiClientFactory, Services.HttpClients.Implements.WechatApiClientFactory>();
|
2021-07-27 18:37:11 +08:00
|
|
|
|
|
2022-05-01 16:25:03 +08:00
|
|
|
|
// 注入后台任务
|
2021-07-27 18:37:11 +08:00
|
|
|
|
services.AddHostedService<Services.BackgroundServices.WechatAccessTokenRefreshingBackgroundService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app)
|
|
|
|
|
{
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|