Skip to content

Commit 38636d9

Browse files
Refactoring
1 parent 3e1fbd8 commit 38636d9

File tree

15 files changed

+36
-35
lines changed

15 files changed

+36
-35
lines changed

CSharpInteractive.Tests/Integration/Core/DotNetScript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static CommandLine Create(params string[] lines) =>
1212

1313
public static CommandLine Create() =>
1414
new(
15-
Composition.Shared.Root.DotNetEnvironment.Path,
15+
Composition.Shared.Root.DotNetEnvironment.Value.Path,
1616
Path.Combine(Path.GetDirectoryName(typeof(DotNetScript).Assembly.Location)!, "dotnet-csi.dll"));
1717

1818
public static CommandLine CreateForScript(string scriptName, string? workingDirectory, IEnumerable<string> args, params string[] lines)
@@ -27,7 +27,7 @@ public static string GetWorkingDirectory()
2727
{
2828
var uniqueNameGenerator = new UniqueNameGenerator();
2929
var environment = Composition.Shared.Root.Environment;
30-
var tempDirectory = environment.GetPath(SpecialFolder.Temp);
30+
var tempDirectory = environment.Value.GetPath(SpecialFolder.Temp);
3131
return Path.Combine(tempDirectory, uniqueNameGenerator.Generate());
3232
}
3333
}

CSharpInteractive.Tests/Integration/NuGetTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void ShouldSupportRestore()
1818

1919
// When
2020
var nuget = Composition.Shared.Root.NuGet;
21-
var result = nuget.Restore(new NuGetRestoreSettings("IoC.Container").WithVersionRange(VersionRange.Parse("1.3.6")).WithTargetFrameworkMoniker("net5.0").WithPackagesPath(tempPath)).ToList();
21+
var result = nuget.Value.Restore(new NuGetRestoreSettings("IoC.Container").WithVersionRange(VersionRange.Parse("1.3.6")).WithTargetFrameworkMoniker("net5.0").WithPackagesPath(tempPath)).ToList();
2222

2323
// Then
2424
result.Count.ShouldBe(1);
@@ -32,7 +32,7 @@ public void ShouldSupportRestoreForDefaults()
3232

3333
// When
3434
var nuget = Composition.Shared.Root.NuGet;
35-
var result = nuget.Restore(new NuGetRestoreSettings("IoC.Container")).ToList();
35+
var result = nuget.Value.Restore(new NuGetRestoreSettings("IoC.Container")).ToList();
3636

3737
// Then
3838
result.Count.ShouldBeGreaterThan(0);

CSharpInteractive.Tests/Integration/TestTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private static readonly (string, string)[] TeamCityVars =
2121
public static IProcessResult Run(in CommandLine commandLine)
2222
{
2323
var events = new List<Output>();
24-
var result = Composition.Shared.Root.CommandLineRunner.Run(commandLine, output =>
24+
var result = Composition.Shared.Root.CommandLineRunner.Value.Run(commandLine, output =>
2525
{
2626
output.Handled = true;
2727
events.Add(output);
@@ -70,7 +70,7 @@ private static IEnumerable<IServiceMessage> ParseMessagesInternal(this IEnumerab
7070
var parser = Composition.Shared.Root.ServiceMessageParser;
7171
foreach (var line in lines)
7272
{
73-
foreach (var message in parser.ParseServiceMessages(line))
73+
foreach (var message in parser.Value.ParseServiceMessages(line))
7474
{
7575
yield return message;
7676
}

CSharpInteractive/Core/BuildEngine.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public void LogMessageEvent(BuildMessageEventArgs e)
3636
switch (e.Importance)
3737
{
3838
case MessageImportance.High:
39-
log.Info([new Text(message)]);
40-
break;
41-
4239
case MessageImportance.Normal:
4340
log.Info([new Text(message)]);
4441
break;

CSharpInteractive/Core/FilePathResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ReSharper disable ClassNeverInstantiated.Global
2-
2+
// ReSharper disable RedundantExplicitParamsArrayCreation
33
namespace CSharpInteractive.Core;
44

55
using HostApi;

CSharpInteractive/Core/HostService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ReSharper disable UnusedMember.Global
22
// ReSharper disable ClassNeverInstantiated.Global
33
// ReSharper disable HeapView.PossibleBoxingAllocation
4-
4+
// ReSharper disable RedundantExplicitParamsArrayCreation
55
namespace CSharpInteractive.Core;
66

77
using HostApi;

CSharpInteractive/Core/Info.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ReSharper disable ClassNeverInstantiated.Global
2-
2+
// ReSharper disable RedundantExplicitParamsArrayCreation
33
namespace CSharpInteractive.Core;
44

55
using System.Reflection;

CSharpInteractive/Core/InteractiveRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ReSharper disable ClassNeverInstantiated.Global
22
// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault
33
// ReSharper disable UnusedType.Global
4-
4+
// ReSharper disable RedundantExplicitParamsArrayCreation
55
namespace CSharpInteractive.Core;
66

77
using HostApi;

CSharpInteractive/Core/ProcessManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ReSharper disable ClassNeverInstantiated.Global
2-
2+
// ReSharper disable RedundantExplicitParamsArrayCreation
33
namespace CSharpInteractive.Core;
44

55
using System.Diagnostics;

CSharpInteractive/Core/StatisticsPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ReSharper disable ClassNeverInstantiated.Global
2-
2+
// ReSharper disable RedundantExplicitParamsArrayCreation
33
namespace CSharpInteractive.Core;
44

55
using HostApi;

CSharpInteractive/Core/SummaryPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ReSharper disable UnusedType.Global
22
// ReSharper disable ClassNeverInstantiated.Global
33
// ReSharper disable MemberCanBePrivate.Global
4-
4+
// ReSharper disable RedundantExplicitParamsArrayCreation
55
namespace CSharpInteractive.Core;
66

77
using HostApi;

CSharpInteractive/Core/TextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace CSharpInteractive.Core;
44

55
using HostApi;
66

7-
internal static partial class TextExtensions
7+
internal static class TextExtensions
88
{
99
private static readonly Text[] SingleTab = [Text.Tab];
1010

CSharpInteractive/Host.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static ICommandLineResult Run(
327327
TimeSpan timeout = default)
328328
{
329329
ArgumentNullException.ThrowIfNull(commandLine);
330-
return Root.CommandLineRunner.Run(commandLine, handler, timeout);
330+
return Root.CommandLineRunner.Value.Run(commandLine, handler, timeout);
331331
}
332332

333333
/// <summary>
@@ -352,7 +352,7 @@ public static Task<ICommandLineResult> RunAsync(
352352
CancellationToken cancellationToken = default)
353353
{
354354
ArgumentNullException.ThrowIfNull(commandLine);
355-
return Root.CommandLineRunner.RunAsync(commandLine, handler, cancellationToken);
355+
return Root.CommandLineRunner.Value.RunAsync(commandLine, handler, cancellationToken);
356356
}
357357

358358
/// <summary>
@@ -375,7 +375,7 @@ public static IBuildResult Build(
375375
TimeSpan timeout = default)
376376
{
377377
ArgumentNullException.ThrowIfNull(commandLine);
378-
return Root.BuildRunner.Build(commandLine, handler, timeout);
378+
return Root.BuildRunner.Value.Build(commandLine, handler, timeout);
379379
}
380380

381381
/// <summary>
@@ -400,7 +400,7 @@ public static Task<IBuildResult> BuildAsync(
400400
CancellationToken cancellationToken = default)
401401
{
402402
ArgumentNullException.ThrowIfNull(commandLine);
403-
return Root.BuildRunner.BuildAsync(commandLine, handler, cancellationToken);
403+
return Root.BuildRunner.Value.BuildAsync(commandLine, handler, cancellationToken);
404404
}
405405

406406
/// <summary>

CSharpInteractive/Root.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ internal record Root(
2121
ILog<Root> Log,
2222
IInfo Info,
2323
IExitTracker ExitTracker,
24-
HostComponents HostComponents,
25-
ICommandLineRunner CommandLineRunner,
26-
IBuildRunner BuildRunner,
27-
IEnvironment Environment,
28-
IDotNetEnvironment DotNetEnvironment,
29-
INuGet NuGet,
30-
IServiceMessageParser ServiceMessageParser,
31-
ITeamCityWriter TeamCityWriter,
24+
Lazy<HostComponents> HostComponents,
25+
Lazy<ICommandLineRunner> CommandLineRunner,
26+
Lazy<IBuildRunner> BuildRunner,
27+
Lazy<IEnvironment> Environment,
28+
Lazy<IDotNetEnvironment> DotNetEnvironment,
29+
Lazy<INuGet> NuGet,
30+
Lazy<IServiceMessageParser> ServiceMessageParser,
31+
Lazy<ITeamCityWriter> TeamCityWriter,
3232
IConsoleHandler ConsoleHandler) : IServiceProvider
3333
{
3434
private readonly Lazy<IServiceProvider> _serviceProvider = new(() =>
3535
{
3636
var serviceCollection = new ServiceCollection();
3737
serviceCollection.AddTransient<IServiceCollection>(_ => serviceCollection);
3838
serviceCollection.AddTransient(_ => Host);
39-
serviceCollection.AddTransient(_ => HostComponents);
40-
serviceCollection.AddTransient(_ => NuGet);
41-
serviceCollection.AddTransient(_ => CommandLineRunner);
42-
serviceCollection.AddTransient(_ => BuildRunner);
43-
serviceCollection.AddTransient(_ => ServiceMessageParser);
44-
serviceCollection.AddTransient(_ => TeamCityWriter);
39+
serviceCollection.AddTransient(_ => HostComponents.Value);
40+
serviceCollection.AddTransient(_ => NuGet.Value);
41+
serviceCollection.AddTransient(_ => CommandLineRunner.Value);
42+
serviceCollection.AddTransient(_ => BuildRunner.Value);
43+
serviceCollection.AddTransient(_ => ServiceMessageParser.Value);
44+
serviceCollection.AddTransient(_ => TeamCityWriter.Value);
4545
return serviceCollection.BuildServiceProvider();
4646
});
4747

Samples/Scripts/Integration.csx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
using HostApi;
2+
13
WriteLine("Hello World!");
24
Trace("My trace");
35
Info("My info");
6+
Summary("My summary message");
7+
Summary("My summary ", "message".WithColor(Color.Header));
48
Warning("My warning");
59
Error("My error");

0 commit comments

Comments
 (0)