using System.Text.Json.Serialization; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using RobotNet10.NavigationTune.Data; using RobotNet10.NavigationTune.Execution; using RobotNet10.NavigationTune.Interfaces; using RobotNet10.NavigationTune.Services; using RobotNet10.NavigationTune.Shared.Interfaces; namespace RobotNet10.NavigationTune.Extensions; /// /// Extension methods for service registration /// public static class ServiceCollectionExtensions { /// /// Add Navigation Tuning services /// public static IServiceCollection AddNavigationTuning( this IServiceCollection services, Action dbContextOptions) { services.AddDbContext(dbContextOptions); // Repositories services.AddScoped(); services.AddScoped(); // Services services.AddScoped(); services.AddScoped(); services.AddScoped(); // Execution services.AddScoped(); services.AddScoped(); // Singleton: so Stop/EMC Stop (different HTTP request) can cancel the running test services.AddSingleton(); // Orchestrator services.AddScoped(); // SignalR Hub: allow NaN/Infinity in JSON so telemetry/metrics with non-finite floats do not abort the connection services.AddSignalR() .AddJsonProtocol(options => { options.PayloadSerializerOptions.NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals; }); return services; } /// /// Add Navigation Tuning with real robot dependencies /// public static IServiceCollection AddNavigationTuningWithRobot( this IServiceCollection services, Action dbContextOptions) { // Add base services services.AddNavigationTuning(dbContextOptions); // Note: Adapters for real robot should be registered in the application layer // that has access to RobotApp.Interfaces.ILocalization and IVelocityController // Example: // services.AddScoped(sp => // { // var localization = sp.GetRequiredService(); // return new LocalizationAdapter( // () => localization.X, // () => localization.Y, // () => localization.Theta // ); // }); return services; } /// /// Map SignalR hubs /// Note: This should be called in the application's Program.cs or Startup.cs /// Example: app.MapHub("/tuninghub"); /// }