continuity/Server/Program.cs

39 lines
1.5 KiB
C#
Raw Normal View History

#pragma warning disable AV1500
using System.Net;
2023-08-09 14:23:41 +00:00
using System.Reflection;
using MassTransit;
2023-08-14 11:49:27 +00:00
using Microsoft.EntityFrameworkCore;
2023-08-09 14:23:41 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
2022-12-31 13:31:42 +00:00
using Microsoft.Extensions.Logging;
2023-08-10 08:47:35 +00:00
using Server.DB;
using Server.Services;
2022-12-31 13:31:42 +00:00
2023-08-09 14:23:41 +00:00
var builder = Host.CreateApplicationBuilder();
2023-08-10 08:47:35 +00:00
builder.Services.AddLogging();
2023-08-14 19:30:32 +00:00
builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Trace);
builder.Logging.AddFile("Logs/Server-{Date}.json.log", LogLevel.Trace, isJson: true);
2023-08-14 11:49:27 +00:00
builder.Services.AddEntityFrameworkNpgsql();
builder.Services.AddDbContext<WonderkingContext>();
2023-08-09 14:23:41 +00:00
builder.Services.AddSingleton<PacketDistributorService>();
2023-08-14 19:30:32 +00:00
builder.Services.AddHostedService(provider =>
2023-08-09 14:23:41 +00:00
provider.GetService<PacketDistributorService>() ?? throw new InvalidOperationException());
builder.Services.AddMassTransit(x =>
2022-12-31 13:31:42 +00:00
{
x.UsingInMemory((context, configurator) => configurator.ConfigureEndpoints(context));
x.AddMediator(cfg => cfg.AddConsumers(Assembly.GetExecutingAssembly()));
2022-12-31 13:31:42 +00:00
});
2023-08-14 19:30:32 +00:00
builder.Services.AddHostedService(provider => new WonderkingAuthServer(IPAddress.Any, 10001,
2023-08-09 14:23:41 +00:00
provider.GetService<ILogger<WonderkingAuthServer>>() ?? throw new InvalidOperationException(),
2023-08-10 08:47:35 +00:00
provider.GetService<IServiceProvider>() ?? throw new InvalidOperationException()));
2022-12-31 13:31:42 +00:00
2023-08-11 09:31:30 +00:00
using var host = builder.Build();
2023-08-14 11:49:27 +00:00
await using (var scope = host.Services.CreateAsyncScope())
{
var db = scope.ServiceProvider.GetRequiredService<WonderkingContext>();
await db.Database.MigrateAsync();
}
2023-08-11 09:31:30 +00:00
await host.RunAsync();
#pragma warning restore AV1500