Implemented factory pattern for server abstraction creation. Implemented raw fs and docker provisioner. Implemented docker event service with observer pattern

This commit is contained in:
2025-07-26 19:14:02 +02:00
parent 0bef60dbc8
commit 84b3d1caf6
13 changed files with 956 additions and 51 deletions

View File

@@ -0,0 +1,39 @@
using MoonlightServers.Daemon.Helpers;
using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.Daemon.ServerSys.Abstractions;
using MoonlightServers.Daemon.ServerSys.Implementations;
namespace MoonlightServers.Daemon.ServerSys;
public class ServerFactory
{
private readonly IServiceProvider ServiceProvider;
public ServerFactory(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
public Server CreateServer(ServerConfiguration configuration)
{
var serverMeta = new ServerMeta();
serverMeta.Configuration = configuration;
// Build service collection
serverMeta.ServiceCollection = new ServiceCollection();
// Configure service pipeline for the server components
serverMeta.ServiceCollection.AddSingleton<IConsole, DockerConsole>();
serverMeta.ServiceCollection.AddSingleton<IFileSystem, RawFileSystem>();
// TODO: Handle implementation configurations (e.g. virtual disk) here
// Combine both app service provider and our server instance specific one
serverMeta.ServiceProvider = new CompositeServiceProvider([
serverMeta.ServiceCollection.BuildServiceProvider(),
ServiceProvider
]);
return serverMeta.ServiceProvider.GetRequiredService<Server>();
}
}