Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit b564a04

Browse files
Optimize Composition
1 parent 9977254 commit b564a04

19 files changed

Lines changed: 94 additions & 106 deletions

CSharpInteractive/AddNuGetReferenceCommandRunner.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ internal class AddNuGetReferenceCommandRunner(
88
INuGetReferenceResolver nuGetReferenceResolver,
99
IReferenceRegistry referenceRegistry) : ICommandRunner
1010
{
11-
1211
public CommandResult TryRun(ICommand command)
1312
{
1413
if (command is not AddNuGetReferenceCommand addPackageReferenceCommand)

CSharpInteractive/CISpecific.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ internal class CISpecific<T>(
1111
[Tag("Ansi")] Func<T> ansiFactory)
1212
: ICISpecific<T>
1313
{
14-
1514
public T Instance => settings.CIType switch
1615
{
1716
CIType.TeamCity => teamcityFactory(),

CSharpInteractive/CSharpScriptCommandRunner.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace CSharpInteractive;
44

55
internal class CSharpScriptCommandRunner(ICSharpScriptRunner scriptRunner) : ICommandRunner
66
{
7-
87
public CommandResult TryRun(ICommand command)
98
{
109
switch (command)

CSharpInteractive/Composition.cs

Lines changed: 94 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,11 @@ private void Setup()
2626
DI.Setup(nameof(Composition))
2727
.Hint(Hint.Resolve, "Off")
2828
.Root<Root>("Root")
29-
29+
3030
.DefaultLifetime(Lifetime.Singleton)
31-
#if TOOL
32-
.Bind().To(_ => RunningMode.Tool)
33-
#endif
34-
#if APPLICATION
35-
.Bind().To(_ => RunningMode.Application)
36-
#endif
3731
.Bind().To<Root>()
38-
.Bind().To(_ => typeof(Composition).Assembly)
39-
.Bind().To(_ => new CSharpParseOptions().LanguageVersion)
40-
.Bind("RuntimePath").To(_ => Path.GetDirectoryName(typeof(object).Assembly.Location) ?? string.Empty)
41-
.Bind("TargetFrameworkMoniker").To(ctx =>
42-
{
43-
ctx.Inject<Assembly>(out var assembly);
44-
return assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName ?? string.Empty;
45-
})
46-
.Bind().To(_ => Process.GetCurrentProcess())
47-
.Bind("ModuleFile").To(ctx =>
48-
{
49-
ctx.Inject<Process>(out var process);
50-
return process.MainModule?.FileName ?? string.Empty;
51-
})
5232
.Bind().To(_ => new CancellationTokenSource())
53-
.Bind().As(Lifetime.Transient).To(ctx =>
54-
{
55-
ctx.Inject<CancellationTokenSource>(out var cancellationTokenSource);
56-
return cancellationTokenSource.Token;
57-
})
5833
.Bind(Tag.Type).To<ExitManager>()
59-
.Bind().To<HostEnvironment>()
60-
.Bind().To<ColorTheme>()
61-
.Bind().To<TeamCityLineFormatter>()
6234
.Bind().To<CISpecific<TT>>()
6335
.Bind("Default").To<ConsoleInOut>()
6436
.Bind("TeamCity").To<TeamCityInOut>()
@@ -81,18 +53,11 @@ private void Setup()
8153
ctx.Inject<ICISpecific<ILog<TT>>>(out var log);
8254
return log.Instance;
8355
})
84-
.Bind().To<FileSystem>()
8556
.Bind().To<CISettings>()
8657
.Bind().To<ExitTracker>()
8758
.Bind<IEnvironment, IScriptContext, IErrorContext>().Bind<ITraceSource>(Tag.Type).To<Environment>()
88-
.Bind<IDotNetEnvironment>().Bind<ITraceSource>(Tag.Type).To<DotNetEnvironment>()
89-
.Bind<IDockerEnvironment>().Bind<ITraceSource>(Tag.Type).To<DockerEnvironment>()
90-
.Bind<INuGetEnvironment>().Bind<ITraceSource>(Tag.Type).To<NuGetEnvironment>()
9159
.Bind<IEnvironmentVariables>().Bind<ITraceSource>(Tag.Type).To<EnvironmentVariables>()
9260
.Bind().To<Settings>()
93-
.Bind(typeof(VerbosityLevel)).To<VerbosityLevelSettingDescription>()
94-
.Bind().To<MSBuildArgumentsTool>()
95-
.Bind().To<CommandLineParser>()
9661
.Bind().To<Info>()
9762
.Bind().To<ConsoleSource>()
9863
.Bind(typeof(LoadFileCodeSource)).To(ctx => new Func<string, ICodeSource>(name =>
@@ -109,23 +74,35 @@ private void Setup()
10974
}))
11075
.Bind(InteractionMode.Interactive).To<InteractiveRunner>()
11176
.Bind(InteractionMode.NonInteractive).To<ScriptRunner>()
112-
.Bind().As(Lifetime.Transient).To(ctx =>
113-
{
114-
ctx.Inject<ISettings>(out var settings);
115-
if (settings.InteractionMode == InteractionMode.Interactive)
116-
{
117-
ctx.Inject<IScriptRunner>(InteractionMode.Interactive, out var scriptRunner);
118-
return scriptRunner;
119-
}
120-
else
121-
{
122-
ctx.Inject<IScriptRunner>(InteractionMode.NonInteractive, out var scriptRunner);
123-
return scriptRunner;
124-
}
125-
})
12677
.Bind().To<CommandSource>()
127-
.Bind().To<StringService>()
12878
.Bind().To<Statistics>()
79+
.Bind().To<CommandsRunner>()
80+
.Bind().To<CodeSourceCommandFactory>()
81+
.Bind().To<CSharpScriptRunner>()
82+
.Bind().To<TargetFrameworkMonikerParser>()
83+
.Bind(Tag.Type).To<Debugger>()
84+
.Bind().To<DockerSettings>()
85+
.Bind().To<ProcessOutputWriter>()
86+
.Bind().To<BuildMessageLogWriter>()
87+
.Bind().To<MessageIndicesReader>()
88+
.Bind().To<MessagesReader>()
89+
.Bind().To<PathResolverContext>()
90+
.Bind().To<ProcessInFlowRunner>()
91+
.Bind().To<NuGetReferenceResolver>()
92+
.Bind().To<ScriptContentReplacer>()
93+
94+
.DefaultLifetime(Lifetime.PerBlock)
95+
.Bind().To<HostEnvironment>()
96+
.Bind().To<ColorTheme>()
97+
.Bind().To<TeamCityLineFormatter>()
98+
.Bind().To<FileSystem>()
99+
.Bind<IDotNetEnvironment>().Bind<ITraceSource>(Tag.Type).To<DotNetEnvironment>()
100+
.Bind<IDockerEnvironment>().Bind<ITraceSource>(Tag.Type).To<DockerEnvironment>()
101+
.Bind<INuGetEnvironment>().Bind<ITraceSource>(Tag.Type).To<NuGetEnvironment>()
102+
.Bind(typeof(VerbosityLevel)).To<VerbosityLevelSettingDescription>()
103+
.Bind().To<MSBuildArgumentsTool>()
104+
.Bind().To<CommandLineParser>()
105+
.Bind().To<StringService>()
129106
.Bind().To<TracePresenter>()
130107
.Bind().To<StatisticsPresenter>()
131108
.Bind().To<DiagnosticsPresenter>()
@@ -136,85 +113,114 @@ private void Setup()
136113
.Bind().To<UniqueNameGenerator>()
137114
.Bind().To<NuGetAssetsReader>()
138115
.Bind().To<Cleaner>()
139-
.Bind().To<CommandsRunner>()
140-
.Bind().To<CodeSourceCommandFactory>()
141-
.Bind().As(Lifetime.Transient).To<ScriptCommandFactory>()
142-
.Bind().To<CSharpScriptRunner>()
143-
.Bind().To<TargetFrameworkMonikerParser>()
144-
.Bind(Tag.Type).To<Debugger>()
145-
.Bind().To<DockerSettings>()
146-
.Bind("base").As(Lifetime.Transient).To<BuildContext>()
147-
.Bind().As(Lifetime.Transient).To<ReliableBuildContext>()
148116
.Bind().To<TextToColorStrings>()
149117
.Bind().To<FileExplorer>()
150-
.Bind().To<ProcessOutputWriter>()
151-
.Bind().To<BuildMessageLogWriter>()
152-
.Bind().To(_ => MemoryPool<TT>.Shared)
153-
.Bind().To<MessageIndicesReader>()
154-
.Bind().To<MessagesReader>()
155-
.Bind().To<PathResolverContext>()
156118
.Bind().To<Utf8Encoding>()
157-
.Bind().As(Lifetime.Transient).To<ProcessMonitor>()
158119
.Bind().To<BuildOutputProcessor>()
159120
.Bind("default").To<DefaultBuildMessagesProcessor>()
160121
.Bind("custom").To<CustomMessagesProcessor>()
122+
.Bind().To<TeamCityContext>()
161123
.Bind().To<SummaryPresenter>()
162124
.Bind().To<ExitCodeParser>()
163125
.Bind("base").To<ProcessRunner>()
164-
.Bind().To<ProcessInFlowRunner>()
165-
.Bind().To<TeamCityContext>()
166126
.Bind().To<ProcessResultHandler>()
127+
.Bind().To<TextReplacer>()
167128
.Bind().To<RuntimeExplorer>()
168-
.Bind().To<NuGetReferenceResolver>()
169-
.Bind().As(Lifetime.Transient).To<SourceResolver>()
170-
.Bind().As(Lifetime.Transient).To<MetadataResolver>()
171-
.Bind().To<ScriptContentReplacer>()
172-
.Bind().To<TextReplacer>();
129+
130+
.DefaultLifetime(Lifetime.Transient)
131+
#if TOOL
132+
.Bind().To(_ => RunningMode.Tool)
133+
#endif
134+
#if APPLICATION
135+
.Bind().To(_ => RunningMode.Application)
136+
#endif
137+
.Bind().To(_ => typeof(Composition).Assembly)
138+
.Bind().To(_ => new CSharpParseOptions().LanguageVersion)
139+
.Bind("RuntimePath").To(_ => Path.GetDirectoryName(typeof(object).Assembly.Location) ?? string.Empty)
140+
.Bind().To(ctx =>
141+
{
142+
ctx.Inject<CancellationTokenSource>(out var cancellationTokenSource);
143+
return cancellationTokenSource.Token;
144+
})
145+
.Bind("TargetFrameworkMoniker").To(ctx =>
146+
{
147+
ctx.Inject<Assembly>(out var assembly);
148+
return assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName ?? string.Empty;
149+
})
150+
.Bind().To(_ => Process.GetCurrentProcess())
151+
.Bind("ModuleFile").To(ctx =>
152+
{
153+
ctx.Inject<Process>(out var process);
154+
return process.MainModule?.FileName ?? string.Empty;
155+
})
156+
.Bind().To(ctx =>
157+
{
158+
ctx.Inject<ISettings>(out var settings);
159+
if (settings.InteractionMode == InteractionMode.Interactive)
160+
{
161+
ctx.Inject<IScriptRunner>(InteractionMode.Interactive, out var scriptRunner);
162+
return scriptRunner;
163+
}
164+
else
165+
{
166+
ctx.Inject<IScriptRunner>(InteractionMode.NonInteractive, out var scriptRunner);
167+
return scriptRunner;
168+
}
169+
})
170+
.Bind().To<ScriptCommandFactory>()
171+
.Bind().To<ReliableBuildContext>()
172+
.Bind().To<ProcessMonitor>()
173+
.Bind().To<ProcessManager>()
174+
.Bind("base").To<BuildContext>()
175+
.Bind().To(_ => MemoryPool<TT>.Shared)
176+
.Bind().To<SourceResolver>()
177+
.Bind().To<MetadataResolver>();
173178

174179
DI.Setup(nameof(Composition))
180+
.DefaultLifetime(Lifetime.Transient)
181+
.Bind().To<AssembliesProvider>()
182+
.Bind(Tag.Type).To<ConfigurableScriptOptionsFactory>()
183+
.Bind().To<ScriptSubmissionAnalyzer>()
184+
.Bind(Tag.Unique).To<HelpCommandFactory>()
185+
.Bind(Tag.Unique).To<HelpCommandRunner>()
186+
.Bind().To<FilePathResolver>()
187+
.Bind().To<StartInfoFactory>()
188+
175189
.DefaultLifetime(Lifetime.Singleton)
176190
// Script options factory
177191
.Bind().To(_ => new Setting<LanguageVersion>(LanguageVersion.Default))
178192
.Bind().To(_ => new Setting<OptimizationLevel>(OptimizationLevel.Release))
179193
.Bind().To(_ => new Setting<WarningLevel>((WarningLevel)ScriptOptions.Default.WarningLevel))
180194
.Bind().To(_ => new Setting<CheckOverflow>(ScriptOptions.Default.CheckOverflow ? CheckOverflow.On : CheckOverflow.Off))
181195
.Bind().To(_ => new Setting<AllowUnsafe>(ScriptOptions.Default.AllowUnsafe ? AllowUnsafe.On : AllowUnsafe.Off))
182-
.Bind().To<AssembliesProvider>()
183196
.Bind(Tag.Type).To<AssembliesScriptOptionsProvider>()
184-
.Bind(Tag.Type).To<ConfigurableScriptOptionsFactory>()
185197
.Bind(Tag.Type).Bind<IReferenceRegistry>().To<ReferencesScriptOptionsFactory>()
186198
.Bind(Tag.Type).To<SourceFileScriptOptionsFactory>()
187199
.Bind(Tag.Type).To<MetadataResolverOptionsFactory>()
188200
.Bind(Tag.Type).To<ImportsOptionsFactory>()
189201
.Bind(Tag.Unique).To<SettingCommandFactory<LanguageVersion>>()
190202
.Bind(Tag.Unique).To<SettingCommandRunner<LanguageVersion>>()
191-
.Bind(typeof(LanguageVersion)).To<LanguageVersionSettingDescription>()
203+
.Bind(typeof(LanguageVersion)).As(Lifetime.PerBlock).To<LanguageVersionSettingDescription>()
192204
.Bind(Tag.Unique).To<SettingCommandFactory<OptimizationLevel>>()
193205
.Bind(Tag.Unique).To<SettingCommandRunner<OptimizationLevel>>()
194-
.Bind(typeof(OptimizationLevel)).To<OptimizationLevelSettingDescription>()
206+
.Bind(typeof(OptimizationLevel)).As(Lifetime.PerBlock).To<OptimizationLevelSettingDescription>()
195207
.Bind(Tag.Unique).To<SettingCommandFactory<WarningLevel>>()
196208
.Bind(Tag.Unique).To<SettingCommandRunner<WarningLevel>>()
197-
.Bind(typeof(WarningLevel)).To<WarningLevelSettingDescription>()
209+
.Bind(typeof(WarningLevel)).As(Lifetime.PerBlock).To<WarningLevelSettingDescription>()
198210
.Bind(Tag.Unique).To<SettingCommandFactory<CheckOverflow>>()
199211
.Bind(Tag.Unique).To<SettingCommandRunner<CheckOverflow>>()
200-
.Bind(typeof(CheckOverflow)).To<CheckOverflowSettingDescription>()
212+
.Bind(typeof(CheckOverflow)).As(Lifetime.PerBlock).To<CheckOverflowSettingDescription>()
201213
.Bind(Tag.Unique).To<SettingCommandFactory<AllowUnsafe>>()
202214
.Bind(Tag.Unique).To<SettingCommandRunner<AllowUnsafe>>()
203-
.Bind(typeof(AllowUnsafe)).To<AllowUnsafeSettingDescription>()
215+
.Bind(typeof(AllowUnsafe)).As(Lifetime.PerBlock).To<AllowUnsafeSettingDescription>()
204216
.Bind(Tag.Unique).To<SettingCommandFactory<NuGetRestoreSetting>>()
205217
.Bind(Tag.Unique).To<SettingCommandRunner<NuGetRestoreSetting>>()
206-
.Bind(typeof(NuGetRestoreSetting)).To<NuGetRestoreSettingDescription>()
207-
.Bind().To<ScriptSubmissionAnalyzer>()
218+
.Bind(typeof(NuGetRestoreSetting)).As(Lifetime.PerBlock).To<NuGetRestoreSettingDescription>()
208219
.Bind(Tag.Unique).To<CSharpScriptCommandRunner>()
209-
.Bind(Tag.Unique).To<HelpCommandFactory>()
210-
.Bind(Tag.Unique).To<HelpCommandRunner>()
211220
.Bind(Tag.Unique).To<SettingCommandFactory<VerbosityLevel>>()
212221
.Bind(Tag.Unique).To<SettingCommandRunner<VerbosityLevel>>()
213222
.Bind(Tag.Unique).To<AddNuGetReferenceCommandFactory>()
214-
.Bind().To<FilePathResolver>()
215223
.Bind(Tag.Unique).To<AddNuGetReferenceCommandRunner>()
216-
.Bind().To<StartInfoFactory>()
217-
.Bind().As(Lifetime.Transient).To<ProcessManager>()
218224
.Bind("Default", "Ansi").To<Properties>()
219225
.Bind("TeamCity").To<TeamCityProperties>()
220226

CSharpInteractive/ConfigurableScriptOptionsFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal class ConfigurableScriptOptionsFactory(
1414
ISettingGetter<AllowUnsafe> allowUnsafe)
1515
: IScriptOptionsFactory
1616
{
17-
1817
public ScriptOptions Create(ScriptOptions baseOptions) =>
1918
baseOptions
2019
.WithLanguageVersion(languageVersion.GetSetting())

CSharpInteractive/ConsoleInOut.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ internal class ConsoleInOut(
77
ITextToColorStrings textToColorStrings,
88
IColorTheme colorTheme) : IStdOut, IStdErr
99
{
10-
1110
void IStdErr.WriteLine(params Text[] line) => WriteStdErr(line + Text.NewLine);
1211

1312
public void Write(params Text[] text) => console.WriteToOut(text.SelectMany(i => textToColorStrings.Convert(i.Value, colorTheme.GetConsoleColor(i.Color))).ToArray());

CSharpInteractive/DockerEnvironment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ internal class DockerEnvironment(
88
IEnvironment environment,
99
IFileExplorer fileExplorer) : ITraceSource, IDockerEnvironment
1010
{
11-
1211
public string Path
1312
{
1413
get

CSharpInteractive/DotnetEnvironment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ internal class DotNetEnvironment(
1212
IFileExplorer fileExplorer)
1313
: IDotNetEnvironment, ITraceSource
1414
{
15-
1615
public string Path
1716
{
1817
get

CSharpInteractive/ExitManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ internal class ExitManager(
77
// ReSharper disable once SuggestBaseTypeForParameterInConstructor
88
CancellationTokenSource cancellationTokenSource) : IActive
99
{
10-
1110
public IDisposable Activate()
1211
{
1312
if (settings.InteractionMode != InteractionMode.Interactive)

CSharpInteractive/FilePathResolver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ internal class FilePathResolver(
66
IEnvironment environment,
77
IFileSystem fileSystem) : IFilePathResolver
88
{
9-
109
public bool TryResolve(string? fileOrDirectoryPath, out string fullScriptPath)
1110
{
1211
var state = State.Unknown;

0 commit comments

Comments
 (0)