Files
Servers/MoonlightServers.Daemon/ServerSys/ServerFactory.cs

28 lines
800 B
C#

using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.Daemon.ServerSys.Abstractions;
namespace MoonlightServers.Daemon.ServerSys;
public class ServerFactory
{
private readonly IServiceProvider ServiceProvider;
public ServerFactory(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
public Server CreateServer(ServerConfiguration configuration)
{
var scope = ServiceProvider.CreateAsyncScope();
var context = scope.ServiceProvider.GetRequiredService<ServerContext>();
var server = scope.ServiceProvider.GetRequiredService<Server>();
context.Configuration = configuration;
context.ServiceScope = scope;
context.Self = server;
return server;
}
}