79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
using FictionArchive.Common.Extensions;
|
|
using FictionArchive.Service.Shared;
|
|
using FictionArchive.Service.Shared.Extensions;
|
|
using FictionArchive.Service.UserNovelDataService.Consumers;
|
|
using FictionArchive.Service.UserNovelDataService.GraphQL;
|
|
using FictionArchive.Service.UserNovelDataService.Services;
|
|
|
|
namespace FictionArchive.Service.UserNovelDataService;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
|
|
|
builder.AddLocalAppsettings();
|
|
|
|
builder.Services.AddMemoryCache();
|
|
builder.Services.AddHealthChecks();
|
|
|
|
#region MassTransit
|
|
|
|
if (!isSchemaExport)
|
|
{
|
|
builder.Services.AddFictionArchiveMassTransit(
|
|
builder.Configuration,
|
|
x =>
|
|
{
|
|
x.AddConsumer<NovelCreatedConsumer>();
|
|
x.AddConsumer<ChapterCreatedConsumer>();
|
|
x.AddConsumer<UserInvitedConsumer>();
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GraphQL
|
|
|
|
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
|
.AddAuthorization();
|
|
|
|
#endregion
|
|
|
|
#region Database
|
|
|
|
builder.Services.RegisterDbContext<UserNovelDataServiceDbContext>(
|
|
builder.Configuration.GetConnectionString("DefaultConnection"),
|
|
skipInfrastructure: isSchemaExport);
|
|
|
|
#endregion
|
|
|
|
// Authentication & Authorization
|
|
builder.Services.AddOidcAuthentication(builder.Configuration);
|
|
builder.Services.AddFictionArchiveAuthorization();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Update database (skip in schema export mode)
|
|
if (!isSchemaExport)
|
|
{
|
|
using var scope = app.Services.CreateScope();
|
|
var dbContext = scope.ServiceProvider.GetRequiredService<UserNovelDataServiceDbContext>();
|
|
dbContext.UpdateDatabase();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapHealthChecks("/healthz");
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapGraphQL();
|
|
|
|
app.RunWithGraphQLCommands(args);
|
|
}
|
|
} |