using Immense.RemoteControl.Server.Abstractions; using Microsoft.Extensions.DependencyInjection; namespace Immense.RemoteControl.Server.Extensions; public interface IRemoteControlServerBuilder { /// /// Adds your implementation of to the /// DI container as a singleton. /// /// void AddHubEventHandler() where T : class, IHubEventHandler; /// /// Adds your implementation of to the /// DI container as a singleton. /// /// void AddSessionRecordingSink() where T : class, ISessionRecordingSink; /// /// Adds your implementation of to the /// DI container as a scoped service. /// /// void AddViewerAuthorizer() where T : class, IViewerAuthorizer; /// /// Adds your implementation of to the /// DI container as a singleton. /// /// void AddViewerOptionsProvider() where T : class, IViewerOptionsProvider; /// /// Adds your implementation of to the /// DI container as a scoped service. /// /// void AddViewerPageDataProvider() where T : class, IViewerPageDataProvider; } internal class RemoteControlServerBuilder : IRemoteControlServerBuilder { private readonly IServiceCollection _services; public RemoteControlServerBuilder(IServiceCollection services) { _services = services; } public void AddHubEventHandler() where T : class, IHubEventHandler { _services.AddSingleton(); } public void AddSessionRecordingSink() where T : class, ISessionRecordingSink { _services.AddSingleton(); } public void AddViewerAuthorizer() where T : class, IViewerAuthorizer { _services.AddScoped(); } public void AddViewerOptionsProvider() where T : class, IViewerOptionsProvider { _services.AddSingleton(); } public void AddViewerPageDataProvider() where T : class, IViewerPageDataProvider { _services.AddScoped(); } internal void Validate() { var serviceTypes = new[] { typeof(IHubEventHandler), typeof(IViewerAuthorizer), typeof(IViewerPageDataProvider), typeof(ISessionRecordingSink), typeof(IViewerOptionsProvider) }; foreach (var type in serviceTypes) { if (!_services.Any(x => x.ServiceType == type)) { throw new Exception($"Missing service registration for type {type.Name}."); } } } }