continuity/Server/Program.cs

31 lines
1.5 KiB
C#
Raw Normal View History

2023-08-09 14:23:41 +00:00
using System.Net;
using System.Reflection;
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;
using Server;
2022-12-26 09:34:31 +00:00
2023-08-09 14:23:41 +00:00
Console.WriteLine(BitConverter.IsLittleEndian);
2022-12-31 13:31:42 +00:00
2023-08-09 14:23:41 +00:00
var builder = Host.CreateApplicationBuilder();
2023-08-09 20:23:14 +00:00
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Trace);
builder.Logging.AddFile("Logs/Server-{Date}.json.log", isJson: true, minimumLevel: LogLevel.Trace);
2023-08-09 14:23:41 +00:00
builder.Services.AddLogging();
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
{
2023-08-09 14:23:41 +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(),
provider.GetService<IServiceProvider>() ?? throw new InvalidOperationException(),
provider.GetService<ILoggerFactory>() ?? throw new InvalidOperationException()));
2022-12-31 13:31:42 +00:00
2023-08-09 14:23:41 +00:00
using IHost host = builder.Build();
await host.RunAsync();