@@ -19,7 +19,7 @@ public class InteractiveService : IDisposable
19
19
private bool disposedValue ;
20
20
private const string DotnetInteractiveToolNotInstallMessage = "Cannot find a tool in the manifest file that has a command named 'dotnet-interactive'." ;
21
21
//private readonly ProcessJobTracker jobTracker = new ProcessJobTracker();
22
- private string installingDirectory ;
22
+ private string ? installingDirectory ;
23
23
24
24
public event EventHandler < DisplayEvent > ? DisplayEvent ;
25
25
@@ -30,16 +30,35 @@ public class InteractiveService : IDisposable
30
30
public event EventHandler < HoverTextProduced > ? HoverTextProduced ;
31
31
32
32
/// <summary>
33
- /// Create an instance of InteractiveService
33
+ /// Install dotnet interactive tool to <paramref name="installingDirectory"/>
34
+ /// and create an instance of <see cref="InteractiveService"/>.
35
+ ///
36
+ /// When using this constructor, you need to call <see cref="StartAsync(string, CancellationToken)"/> to install dotnet interactive tool
37
+ /// and start the kernel.
34
38
/// </summary>
35
39
/// <param name="installingDirectory">dotnet interactive installing directory</param>
36
40
public InteractiveService ( string installingDirectory )
37
41
{
38
42
this . installingDirectory = installingDirectory ;
39
43
}
40
44
45
+ /// <summary>
46
+ /// Create an instance of <see cref="InteractiveService"/> with a running kernel.
47
+ /// When using this constructor, you don't need to call <see cref="StartAsync(string, CancellationToken)"/> to start the kernel.
48
+ /// </summary>
49
+ /// <param name="kernel"></param>
50
+ public InteractiveService ( Kernel kernel )
51
+ {
52
+ this . kernel = kernel ;
53
+ }
54
+
41
55
public async Task < bool > StartAsync ( string workingDirectory , CancellationToken ct = default )
42
56
{
57
+ if ( this . kernel != null )
58
+ {
59
+ return true ;
60
+ }
61
+
43
62
this . kernel = await this . CreateKernelAsync ( workingDirectory , true , ct ) ;
44
63
return true ;
45
64
}
0 commit comments