-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (68 loc) · 3.5 KB
/
Program.cs
File metadata and controls
76 lines (68 loc) · 3.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Coflnet.Core;
using Coflnet.Discord;
using Coflnet.Sky.Api.Client.Api;
using Coflnet.Sky.McConnect.Api;
using Coflnet.Sky.PlayerName.Client.Api;
using Octokit;
using StackExchange.Redis;
using Coflnet.Sky.ModCommands.Client.Extensions;
using Coflnet.Sky.ModCommands.Client.Client;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<DiscordHandler>();
builder.Services.AddHostedService(di=> di.GetRequiredService<DiscordHandler>());
builder.Services.AddSingleton<IPlayerNameApi, PlayerNameApi>(di => new PlayerNameApi(builder.Configuration["PLAYERNAME_BASE_URL"]));
builder.Services.AddSingleton<IConnectApi, ConnectApi>(di => new ConnectApi(builder.Configuration["MCCONNECT_BASE_URL"]));
builder.Services.AddSingleton<Coflnet.Payments.Client.Api.IUserApi, Coflnet.Payments.Client.Api.UserApi>(di => new Coflnet.Payments.Client.Api.UserApi(builder.Configuration["PAYMENTS_BASE_URL"]));
builder.Services.AddSingleton<Coflnet.Payments.Client.Api.ITransactionApi, Coflnet.Payments.Client.Api.TransactionApi>(di => new Coflnet.Payments.Client.Api.TransactionApi(builder.Configuration["PAYMENTS_BASE_URL"]));
builder.Services.AddSingleton<Coflnet.Payments.Client.Api.ITopUpApi, Coflnet.Payments.Client.Api.TopUpApi>(di => new Coflnet.Payments.Client.Api.TopUpApi(builder.Configuration["PAYMENTS_BASE_URL"]));
builder.Services.AddSingleton<Coflnet.Payments.Client.Api.IProductsApi, Coflnet.Payments.Client.Api.ProductsApi>(di => new Coflnet.Payments.Client.Api.ProductsApi(builder.Configuration["PAYMENTS_BASE_URL"]));
builder.Services.AddSingleton<Coflnet.Sky.Settings.Client.Api.ISettingsApi, Coflnet.Sky.Settings.Client.Api.SettingsApi>(di => new Coflnet.Sky.Settings.Client.Api.SettingsApi(builder.Configuration["SETTINGS_BASE_URL"]));
builder.Services.AddSingleton<ChatService>();
builder.Services.AddSingleton<LokiQuery>();
builder.Services.AddSingleton<Persistence>();
builder.Host.ConfigureApi((context, s, options) =>
{
options.AddApiHttpClients(c =>
{
c.BaseAddress = new Uri(builder.Configuration["MOD_BASE_URL"]);
});
});
builder.Services.AddSingleton<ProfileClient>();
builder.Services.AddSingleton<UserInfoUpdater>();
builder.Services.AddSingleton<GitHubClient>(di =>
{
var github = new GitHubClient(new ProductHeaderValue("CoflnetBot"))
{
Credentials = new Credentials(builder.Configuration["GitHubToken"])
};
return github;
});
builder.Services.AddResponseCaching();
builder.Services.AddSingleton<Octokit.GraphQL.Connection>(di =>
{
var productInformation = new Octokit.GraphQL.ProductHeaderValue("CoflnetBot", "1");
var connection = new Octokit.GraphQL.Connection(productInformation,builder.Configuration["GitHubToken"]);
return connection;
});
builder.Services.AddCoflnetCore();
builder.Services.AddControllers();
builder.Services.AddSingleton<ISearchApi>(di => new SearchApi(builder.Configuration["API_BASE_URL"]));
builder.Services.AddSingleton<IConnectionMultiplexer>(s => ConnectionMultiplexer.Connect(builder.Configuration["CHAT_REDIS_HOST"]));
var app = builder.Build();
app.UseSwagger(a =>
{
a.RouteTemplate = "api/swagger/{documentName}/swagger.json";
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "SkyApi v1");
c.RoutePrefix = "api";
});
app.UseResponseCaching();
app.UseHttpsRedirection();
app.MapControllers();
app.Run();