[FA-misc] Mass transit overhaul, needs testing and review
This commit is contained in:
76
FictionArchive.Service.ReportingService/Program.cs
Normal file
76
FictionArchive.Service.ReportingService/Program.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using FictionArchive.Common.Extensions;
|
||||
using FictionArchive.Service.ReportingService.GraphQL;
|
||||
using FictionArchive.Service.ReportingService.Services;
|
||||
using FictionArchive.Service.ReportingService.Services.Consumers;
|
||||
using FictionArchive.Service.Shared;
|
||||
using FictionArchive.Service.Shared.Extensions;
|
||||
using FictionArchive.Service.Shared.MassTransit;
|
||||
|
||||
namespace FictionArchive.Service.ReportingService;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
||||
|
||||
builder.AddLocalAppsettings();
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
#region Database
|
||||
|
||||
builder.Services.RegisterDbContext<ReportingServiceDbContext>(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection")!,
|
||||
skipInfrastructure: isSchemaExport);
|
||||
|
||||
#endregion
|
||||
|
||||
#region MassTransit
|
||||
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
builder.Services.AddFictionArchiveMassTransit<ReportingServiceDbContext>(
|
||||
builder.Configuration,
|
||||
x =>
|
||||
{
|
||||
x.AddConsumer<JobStateChangedEventConsumer>();
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GraphQL
|
||||
|
||||
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||
.AddAuthorization();
|
||||
|
||||
#endregion
|
||||
|
||||
// Authentication & Authorization
|
||||
builder.Services.AddOidcAuthentication(builder.Configuration);
|
||||
builder.Services.AddFictionArchiveAuthorization();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<ReportingServiceDbContext>();
|
||||
dbContext.UpdateDatabase();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.RunWithGraphQLCommands(args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user