82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using FictionArchive.Service.NovelService.GraphQL;
|
|
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
|
using FictionArchive.Service.NovelService.Services;
|
|
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
|
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
|
using FictionArchive.Service.NovelService.Services.SourceAdapters.Novelpia;
|
|
using FictionArchive.Service.Shared.Extensions;
|
|
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
|
using FictionArchive.Service.Shared.Services.GraphQL;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FictionArchive.Service.NovelService;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddMemoryCache();
|
|
|
|
#region Event Bus
|
|
|
|
builder.Services.AddRabbitMQ(opt =>
|
|
{
|
|
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
|
})
|
|
.Subscribe<TranslationRequestCompletedEvent, TranslationRequestCompletedEventHandler>()
|
|
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
|
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>();
|
|
|
|
#endregion
|
|
|
|
#region GraphQL
|
|
|
|
builder.Services.AddDefaultGraphQl<Query, Mutation>();
|
|
|
|
#endregion
|
|
|
|
#region Database
|
|
|
|
builder.Services.RegisterDbContext<NovelServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
|
|
|
|
#endregion
|
|
|
|
#region Source Adapters
|
|
|
|
builder.Services.Configure<NovelpiaConfiguration>(builder.Configuration.GetSection("Novelpia"));
|
|
builder.Services.AddHttpClient<NovelpiaAuthMessageHandler>(client =>
|
|
{
|
|
client.BaseAddress = new Uri("https://novelpia.com");
|
|
});
|
|
builder.Services.AddHttpClient<ISourceAdapter, NovelpiaAdapter>(client =>
|
|
{
|
|
client.BaseAddress = new Uri("https://novelpia.com");
|
|
})
|
|
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
|
|
|
builder.Services.AddTransient<NovelUpdateService>();
|
|
|
|
#endregion
|
|
|
|
builder.Services.AddHealthChecks();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Update database
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var dbContext = scope.ServiceProvider.GetRequiredService<NovelServiceDbContext>();
|
|
dbContext.UpdateDatabase();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapHealthChecks("/healthz");
|
|
|
|
app.MapGraphQL();
|
|
|
|
app.RunWithGraphQLCommands(args);
|
|
}
|
|
} |