continuity/Server/Program.cs
2023-08-09 16:23:41 +02:00

27 lines
No EOL
1.2 KiB
C#

using System.Net;
using System.Reflection;
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Server;
Console.WriteLine(BitConverter.IsLittleEndian);
var builder = Host.CreateApplicationBuilder();
builder.Services.AddLogging();
builder.Services.AddSingleton<PacketDistributorService>();
builder.Services.AddHostedService<PacketDistributorService>(provider =>
provider.GetService<PacketDistributorService>() ?? throw new InvalidOperationException());
builder.Services.AddMassTransit(x =>
{
x.UsingInMemory((context, configurator) => { configurator.ConfigureEndpoints(context); });
x.AddMediator(cfg => { cfg.AddConsumers(Assembly.GetExecutingAssembly()); });
});
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()));
using IHost host = builder.Build();
await host.RunAsync();