using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using LANCommander.Steam.Abstractions; using LANCommander.Steam.Implementations; using LANCommander.Steam.Options; using LANCommander.Steam.Services; namespace LANCommander.Steam.Extensions; /// /// Extension methods for registering SteamCMD services (optional, for DI-based hosts). /// Steam types can also be constructed directly without DI. /// public static class ServiceCollectionExtensions { /// /// Add SteamCMD service with default in-memory profile store /// public static IServiceCollection AddSteamCmd(this IServiceCollection services, Action? configure = null) { if (configure != null) { services.Configure(configure); } else { services.Configure(_ => { }); } services.AddSingleton(); services.AddScoped(sp => new SteamCmdService( sp.GetService>()?.Value, sp.GetService(), sp.GetService>())); services.AddSingleton(); return services; } /// /// Add SteamCMD service with custom profile store implementation /// public static IServiceCollection AddSteamCmd( this IServiceCollection services, Action? configure = null) where TProfileStore : class, ISteamCmdProfileStore { if (configure != null) { services.Configure(configure); } else { services.Configure(_ => { }); } services.AddSingleton(); services.AddScoped(sp => new SteamCmdService( sp.GetService>()?.Value, sp.GetService(), sp.GetService>())); services.AddSingleton(); return services; } /// /// Add SteamCMD service with existing profile store instance /// public static IServiceCollection AddSteamCmd( this IServiceCollection services, ISteamCmdProfileStore profileStore, Action? configure = null) { if (configure != null) { services.Configure(configure); } else { services.Configure(_ => { }); } services.AddSingleton(profileStore); services.AddScoped(sp => new SteamCmdService( sp.GetService>()?.Value, sp.GetService(), sp.GetService>())); services.AddSingleton(); return services; } }