// In RemoteExec.Client.DependencyInjection (Extension Project) using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace RemoteExec.Client.DependencyInjection; /// /// Extension methods for registering RemoteExecutor with dependency injection. /// public static class RemoteExecutorServiceCollectionExtensions { /// /// Adds a singleton RemoteExecutor to the service collection. /// /// The service collection to add to. /// The URLs of the remote execution servers. /// An optional action to configure the executor options. /// The service collection for chaining. public static IServiceCollection AddRemoteExecutor(this IServiceCollection services, string[] urls, Action? configure = null) { RemoteExecutorOptions options = new RemoteExecutorOptions(); configure?.Invoke(options); _ = services.AddSingleton(options); _ = services.AddSingleton(sp => { RemoteExecutorOptions opt = sp.GetRequiredService(); ILogger logger = sp.GetRequiredService>(); return new RemoteExecutor(urls, opt, logger); }); return services; } }