continuity/Server/Program.cs

41 lines
1.9 KiB
C#
Raw Normal View History

#pragma warning disable AV1500
using System.Net;
2023-08-09 14:23:41 +00:00
using System.Reflection;
2023-08-10 08:47:35 +00:00
using CouchDB.Driver.DependencyInjection;
2023-08-09 14:23:41 +00:00
using MassTransit;
2023-08-09 20:23:14 +00:00
using Microsoft.Extensions.Configuration;
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-11 09:31:30 +00:00
var configurationRoot = builder.Configuration.AddJsonFile("settings.json", false, true)
2023-08-10 08:47:35 +00:00
.AddEnvironmentVariables().Build();
builder.Services.AddLogging();
2023-08-11 14:01:32 +00:00
builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Debug);
builder.Logging.AddFile("Logs/Server-{Date}.json.log", LogLevel.Debug, isJson: true);
2023-08-10 08:47:35 +00:00
builder.Services.AddCouchContext<WonderkingContext>(cfg =>
{
cfg.UseEndpoint(configurationRoot["DB:Endpoint"] ?? throw new InvalidOperationException())
.UseBasicAuthentication(configurationRoot["DB:User"] ?? throw new InvalidOperationException(),
configurationRoot["DB:Password"] ?? throw new InvalidOperationException())
.EnsureDatabaseExists();
});
2023-08-09 14:23:41 +00:00
builder.Services.AddSingleton<PacketDistributorService>();
builder.Services.AddHostedService<PacketDistributorService>(provider =>
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-09 14:23:41 +00:00
builder.Services.AddHostedService<WonderkingAuthServer>(provider => new WonderkingAuthServer(IPAddress.Any, 10001,
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();
await host.RunAsync();
#pragma warning restore AV1500