using Microsoft.Extensions.DependencyInjection; using Microsoft.JSInterop; using RobotNet10.ScriptEditor.Clients; using RobotNet10.ScriptEditor.Services; using RobotNet10.ScriptEngine.Shared; using System.Reflection; namespace RobotNet10.ScriptEditor; public static class Extensions { public static void AddScriptEditor(this IServiceCollection services) where TScriptEngineResource : class, IScriptEngineResource { try { _ = typeof(Microsoft.CodeAnalysis.Host.HostServices).Assembly.CreateInstance("Microsoft.CodeAnalysis.Host.DefaultPersistentStorageConfiguration"); } catch (TargetInvocationException) { GC.Collect(); } services.AddSingleton(); // Register HubClients as Scoped services services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(sp => { var httpClient = sp.GetRequiredService(); var jsRuntime = sp.GetService(); return new ScriptResourceResolver(httpClient, jsRuntime); }); } }