private static CompositeKernel CreateKernel( string defaultKernelName, FrontendEnvironment frontendEnvironment, StartupOptions startupOptions, HttpProbingSettings httpProbingSettings) { var compositeKernel = new CompositeKernel(); compositeKernel.FrontendEnvironment = frontendEnvironment; compositeKernel.Add( new CSharpKernel() .UseDefaultFormatting() .UseNugetDirective() .UseKernelHelpers() .UseJupyterHelpers() .UseWho() .UseXplot() .UseMathAndLaTeX(), new[] { "c#", "C#" }); compositeKernel.Add( new FSharpKernel() .UseDefaultFormatting() .UseNugetDirective() .UseKernelHelpers() .UseWho() .UseDefaultNamespaces() .UseXplot() .UseMathAndLaTeX(), new[] { "f#", "F#" }); compositeKernel.Add( new PowerShellKernel() .UseJupyterHelpers() .UseXplot() .UseProfiles(), new[] { "pwsh" }); compositeKernel.Add( new JavaScriptKernel(), new[] { "js" }); compositeKernel.Add( new HtmlKernel()); var kernel = compositeKernel .UseDefaultMagicCommands() .UseLog() .UseAbout(); SetUpFormatters(frontendEnvironment, startupOptions); kernel.DefaultKernelName = defaultKernelName; if (startupOptions.EnableHttpApi) { kernel = kernel.UseHttpApi(startupOptions, httpProbingSettings); var enableHttp = new SubmitCode("#!enable-http", compositeKernel.Name); enableHttp.PublishInternalEvents(); kernel.DeferCommand(enableHttp); } return(kernel); }
private static IServiceCollection RegisterKernelInServiceCollection(IServiceCollection services, StartupOptions startupOptions, string defaultKernel, Action <KernelBase> afterKernelCreation = null) { services .AddSingleton(_ => { var frontendEnvironment = new BrowserFrontendEnvironment { ApiUri = new Uri($"http://localhost:{startupOptions.HttpPort.PortNumber}") }; return(frontendEnvironment); }) .AddSingleton(c => { var frontendEnvironment = c.GetRequiredService <BrowserFrontendEnvironment>(); var kernel = CreateKernel(defaultKernel, frontendEnvironment, startupOptions, c.GetRequiredService <HttpProbingSettings>()); afterKernelCreation?.Invoke(kernel); return(kernel); }) .AddSingleton <KernelBase>(c => c.GetRequiredService <CompositeKernel>()) .AddSingleton <IKernel>(c => c.GetRequiredService <KernelBase>()); return(services); }