Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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<TScriptEngineResource>(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<IScriptEngineResource, TScriptEngineResource>();
|
||||
|
||||
// Register HubClients as Scoped services
|
||||
services.AddScoped<ConsoleHubClient>();
|
||||
services.AddScoped<FileManagerHubClient>();
|
||||
services.AddScoped<ScriptManagerHubClient>();
|
||||
services.AddScoped<InstanceMissionHubClient>();
|
||||
services.AddScoped<ScriptWorkspace>();
|
||||
services.AddScoped<ScriptResourceResolver>(sp =>
|
||||
{
|
||||
var httpClient = sp.GetRequiredService<HttpClient>();
|
||||
var jsRuntime = sp.GetService<IJSRuntime>();
|
||||
return new ScriptResourceResolver(httpClient, jsRuntime);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user