Files
Servers/MoonlightServers.Daemon/ServerSystem/Implementations/Docker/Extensions.cs

31 lines
1.1 KiB
C#

using Docker.DotNet;
using Microsoft.Extensions.Options;
using MoonlightServers.Daemon.Configuration;
using MoonlightServers.Daemon.ServerSystem.Abstractions;
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Docker;
public static class Extensions
{
public static void AddDockerServices(this IServiceCollection collection)
{
collection.AddOptions<DockerOptions>().BindConfiguration("Moonlight:Docker");
collection.AddSingleton(sp =>
{
var options = sp.GetRequiredService<IOptions<DockerOptions>>();
return new DockerClientBuilder()
.WithEndpoint(new Uri(options.Value.SocketUri))
.Build();
});
collection.AddSingleton<DockerEventService>();
collection.AddHostedService(sp => sp.GetRequiredService<DockerEventService>());
collection.AddSingleton<IRuntimeEnvironmentService, DockerRuntimeEnvService>();
collection.AddSingleton<IInstallEnvironmentService, DockerInstallEnvService>();
collection.AddSingleton<ContainerConfigMapper>();
}
}