-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoot.cs
50 lines (46 loc) · 1.78 KB
/
Root.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace CSharpInteractive;
using Core;
using HostApi;
using HostApi.Internal;
using JetBrains.TeamCity.ServiceMessages.Read;
using JetBrains.TeamCity.ServiceMessages.Write.Special;
using Microsoft.Extensions.DependencyInjection;
[ExcludeFromCodeCoverage]
internal record Root(
#if TOOL
Program Program,
#endif
IHost Host,
ITestEnvironment TestEnvironment,
IStatisticsRegistry StatisticsRegistry,
ILog<Root> Log,
IInfo Info,
IExitTracker ExitTracker,
Lazy<HostComponents> HostComponents,
Lazy<ICommandLineRunner> CommandLineRunner,
Lazy<IBuildRunner> BuildRunner,
Lazy<IEnvironment> Environment,
Lazy<IDotNetEnvironment> DotNetEnvironment,
Lazy<INuGet> NuGet,
Lazy<IServiceMessageParser> ServiceMessageParser,
Lazy<ITeamCityWriter> TeamCityWriter,
IConsoleHandler ConsoleHandler) : IServiceProvider
{
private readonly Lazy<IServiceProvider> _serviceProvider = new(() =>
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<IServiceCollection>(_ => serviceCollection);
serviceCollection.AddTransient(_ => Host);
serviceCollection.AddTransient(_ => HostComponents.Value);
serviceCollection.AddTransient(_ => NuGet.Value);
serviceCollection.AddTransient(_ => CommandLineRunner.Value);
serviceCollection.AddTransient(_ => BuildRunner.Value);
serviceCollection.AddTransient(_ => ServiceMessageParser.Value);
serviceCollection.AddTransient(_ => TeamCityWriter.Value);
return serviceCollection.BuildServiceProvider();
});
public object? GetService(Type serviceType) =>
_serviceProvider.Value.GetService(serviceType);
}