Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Aug 22, 2024
1 parent 2b8c1f3 commit 163956c
Showing 1 changed file with 65 additions and 76 deletions.
141 changes: 65 additions & 76 deletions CSharpInteractive/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal partial class Composition

private void Setup()
{
DI.Setup(nameof(Composition))
DI.Setup()
.Hint(Hint.Resolve, "Off")
.Root<Root>("Root")

Expand Down Expand Up @@ -57,7 +57,68 @@ private void Setup()
#if APPLICATION
.Bind().As(Lifetime.Transient).To(_ => RunningMode.Application)
#endif
.DefaultLifetime(Lifetime.Transient)
.Bind().To(_ => DateTime.Now)
.Bind().To(_ => typeof(Composition).Assembly)
.Bind().To(_ => new CSharpParseOptions().LanguageVersion)
.Bind("RuntimePath").To(_ => Path.GetDirectoryName(typeof(object).Assembly.Location) ?? string.Empty)
.Bind().To((CancellationTokenSource cancellationTokenSource) => cancellationTokenSource.Token)
.Bind("TargetFrameworkMoniker").To((Assembly assembly) => assembly.GetCustomAttribute<System.Runtime.Versioning.TargetFrameworkAttribute>()?.FrameworkName ?? string.Empty)
.Bind().To(_ => Process.GetCurrentProcess())
.Bind("ModuleFile").To((Process process) => process.MainModule?.FileName ?? string.Empty)
.Bind().To<ScriptCommandFactory>()
.Bind().To<ReliableBuildContext>()
.Bind().To<ProcessMonitor>()
.Bind().To<ProcessManager>()
.Bind("base").To<BuildContext>()
.Bind().To(_ => MemoryPool<TT>.Shared)
.Bind().To<SourceResolver>()
.Bind().To<MetadataResolver>()
.Bind().To<AssembliesProvider>()
.Bind(Tag.Type).To<ConfigurableScriptOptionsFactory>()
.Bind().To<ScriptSubmissionAnalyzer>()
.Bind(Tag.Unique).To<HelpCommandFactory>()
.Bind(Tag.Unique).To<HelpCommandRunner>()
.Bind().To<FilePathResolver>()
.Bind().To<StartInfoFactory>()

.DefaultLifetime(Lifetime.PerBlock)
.Bind().To<StartInfoDescription>()
.Bind().To<HostEnvironment>()
.Bind().To<ColorTheme>()
.Bind().To<TeamCityLineFormatter>()
.Bind().To<FileSystem>()
.Bind<IDotNetEnvironment>().Bind<ITraceSource>(Tag.Type).To<DotNetEnvironment>()
.Bind<IDockerEnvironment>().Bind<ITraceSource>(Tag.Type).To<DockerEnvironment>()
.Bind<INuGetEnvironment>().Bind<ITraceSource>(Tag.Type).To<NuGetEnvironment>()
.Bind(typeof(VerbosityLevel)).To<VerbosityLevelSettingDescription>()
.Bind().To<MSBuildArgumentsTool>()
.Bind().To<CommandLineParser>()
.Bind().To<StringService>()
.Bind().To<TracePresenter>()
.Bind().To<StatisticsPresenter>()
.Bind().To<DiagnosticsPresenter>()
.Bind().To<ScriptStatePresenter>()
.Bind().To<BuildEngine>()
.Bind().To<NuGetRestoreService>()
.Bind().To<NuGetLogger>()
.Bind().To<UniqueNameGenerator>()
.Bind().To<NuGetAssetsReader>()
.Bind().To<Cleaner>()
.Bind().To<TextToColorStrings>()
.Bind().To<FileExplorer>()
.Bind().To<Utf8Encoding>()
.Bind().To<BuildOutputProcessor>()
.Bind("default").To<DefaultBuildMessagesProcessor>()
.Bind("custom").To<CustomMessagesProcessor>()
.Bind().To<TeamCityContext>()
.Bind().To<SummaryPresenter>()
.Bind().To<ExitCodeParser>()
.Bind("base").To<ProcessRunner>()
.Bind().To<ProcessResultHandler>()
.Bind().To<TextReplacer>()
.Bind().To<RuntimeExplorer>()

.DefaultLifetime(Lifetime.Singleton)
.Bind().To<Root>()
.Bind().To(_ => new CancellationTokenSource())
Expand Down Expand Up @@ -104,73 +165,6 @@ private void Setup()
.Bind().To<ProcessInFlowRunner>()
.Bind().To<NuGetReferenceResolver>()
.Bind().To<ScriptContentReplacer>()

.DefaultLifetime(Lifetime.PerBlock)
.Bind().To<StartInfoDescription>()
.Bind().To<HostEnvironment>()
.Bind().To<ColorTheme>()
.Bind().To<TeamCityLineFormatter>()
.Bind().To<FileSystem>()
.Bind<IDotNetEnvironment>().Bind<ITraceSource>(Tag.Type).To<DotNetEnvironment>()
.Bind<IDockerEnvironment>().Bind<ITraceSource>(Tag.Type).To<DockerEnvironment>()
.Bind<INuGetEnvironment>().Bind<ITraceSource>(Tag.Type).To<NuGetEnvironment>()
.Bind(typeof(VerbosityLevel)).To<VerbosityLevelSettingDescription>()
.Bind().To<MSBuildArgumentsTool>()
.Bind().To<CommandLineParser>()
.Bind().To<StringService>()
.Bind().To<TracePresenter>()
.Bind().To<StatisticsPresenter>()
.Bind().To<DiagnosticsPresenter>()
.Bind().To<ScriptStatePresenter>()
.Bind().To<BuildEngine>()
.Bind().To<NuGetRestoreService>()
.Bind().To<NuGetLogger>()
.Bind().To<UniqueNameGenerator>()
.Bind().To<NuGetAssetsReader>()
.Bind().To<Cleaner>()
.Bind().To<TextToColorStrings>()
.Bind().To<FileExplorer>()
.Bind().To<Utf8Encoding>()
.Bind().To<BuildOutputProcessor>()
.Bind("default").To<DefaultBuildMessagesProcessor>()
.Bind("custom").To<CustomMessagesProcessor>()
.Bind().To<TeamCityContext>()
.Bind().To<SummaryPresenter>()
.Bind().To<ExitCodeParser>()
.Bind("base").To<ProcessRunner>()
.Bind().To<ProcessResultHandler>()
.Bind().To<TextReplacer>()
.Bind().To<RuntimeExplorer>()

.DefaultLifetime(Lifetime.Transient)
.Bind().To(_ => typeof(Composition).Assembly)
.Bind().To(_ => new CSharpParseOptions().LanguageVersion)
.Bind("RuntimePath").To(_ => Path.GetDirectoryName(typeof(object).Assembly.Location) ?? string.Empty)
.Bind().To((CancellationTokenSource cancellationTokenSource) => cancellationTokenSource.Token)
.Bind("TargetFrameworkMoniker").To((Assembly assembly) => assembly.GetCustomAttribute<System.Runtime.Versioning.TargetFrameworkAttribute>()?.FrameworkName ?? string.Empty)
.Bind().To(_ => Process.GetCurrentProcess())
.Bind("ModuleFile").To((Process process) => process.MainModule?.FileName ?? string.Empty)
.Bind().To<ScriptCommandFactory>()
.Bind().To<ReliableBuildContext>()
.Bind().To<ProcessMonitor>()
.Bind().To<ProcessManager>()
.Bind("base").To<BuildContext>()
.Bind().To(_ => MemoryPool<TT>.Shared)
.Bind().To<SourceResolver>()
.Bind().To<MetadataResolver>();

DI.Setup(nameof(Composition))
.DefaultLifetime(Lifetime.Transient)
.Bind().To<AssembliesProvider>()
.Bind(Tag.Type).To<ConfigurableScriptOptionsFactory>()
.Bind().To<ScriptSubmissionAnalyzer>()
.Bind(Tag.Unique).To<HelpCommandFactory>()
.Bind(Tag.Unique).To<HelpCommandRunner>()
.Bind().To<FilePathResolver>()
.Bind().To<StartInfoFactory>()

.DefaultLifetime(Lifetime.Singleton)
// Script options factory
.Bind().To(_ => new Setting<LanguageVersion>(LanguageVersion.Default))
.Bind().To(_ => new Setting<OptimizationLevel>(OptimizationLevel.Release))
.Bind().To(_ => new Setting<WarningLevel>((WarningLevel)ScriptOptions.Default.WarningLevel))
Expand Down Expand Up @@ -206,23 +200,18 @@ private void Setup()
.Bind(Tag.Unique).To<AddNuGetReferenceCommandRunner>()
.Bind("Default", "Ansi").To<Properties>()
.Bind("TeamCity").To<TeamCityProperties>()
.Bind().To((ICISpecific<IProperties> properties) => properties.Instance)

// Public
// Public services
.Bind().To<HostService>()
.Bind().To((ICISpecific<IProperties> properties) => properties.Instance)
.Bind().To<NuGetService>()
.Bind().To<CommandLineRunner>()
.Bind().To<BuildRunner>()

// TeamCity Service messages
.Bind().To<TeamCityServiceMessages>()
.Bind().To<ServiceMessageFormatter>()
.Bind().To<FlowIdGenerator>()
.Bind().As(Lifetime.Transient).To(_ => DateTime.Now)
.Bind().To<TimestampUpdater>()
.Bind().To((ITeamCityServiceMessages teamCityServiceMessages, IConsole console) =>
teamCityServiceMessages.CreateWriter(str =>
console.WriteToOut((default, str + "\n"))))
.Bind().To((ITeamCityServiceMessages teamCityServiceMessages, IConsole console) => teamCityServiceMessages.CreateWriter(str => console.WriteToOut((default, str + "\n"))))
.Bind().To<ServiceMessageParser>();
}
}

0 comments on commit 163956c

Please sign in to comment.