-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
60 lines (52 loc) · 2.44 KB
/
Program.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
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.AddHostedService<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<ChatService>();
builder.Services.AddSingleton<Persistence>();
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.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.UseHttpsRedirection();
app.MapControllers();
app.Run();