From 652d9e5402569670c178006af77bc642043e3c24 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Thu, 22 Aug 2024 12:45:18 +0300 Subject: [PATCH] Minor --- CSharpInteractive/Composition.cs | 143 ++++++++++++++----------------- 1 file changed, 66 insertions(+), 77 deletions(-) diff --git a/CSharpInteractive/Composition.cs b/CSharpInteractive/Composition.cs index 3c3ce6fa..87ffd21d 100644 --- a/CSharpInteractive/Composition.cs +++ b/CSharpInteractive/Composition.cs @@ -23,9 +23,9 @@ internal partial class Composition { public static readonly Composition Shared = new(); - private void Setup() + private static void Setup() { - DI.Setup(nameof(Composition)) + DI.Setup() .Hint(Hint.Resolve, "Off") .Root("Root") @@ -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()?.FrameworkName ?? string.Empty) + .Bind().To(_ => Process.GetCurrentProcess()) + .Bind("ModuleFile").To((Process process) => process.MainModule?.FileName ?? string.Empty) + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind("base").To() + .Bind().To(_ => MemoryPool.Shared) + .Bind().To() + .Bind().To() + .Bind().To() + .Bind(Tag.Type).To() + .Bind().To() + .Bind(Tag.Unique).To() + .Bind(Tag.Unique).To() + .Bind().To() + .Bind().To() + .DefaultLifetime(Lifetime.PerBlock) + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().Bind(Tag.Type).To() + .Bind().Bind(Tag.Type).To() + .Bind().Bind(Tag.Type).To() + .Bind(typeof(VerbosityLevel)).To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind("default").To() + .Bind("custom").To() + .Bind().To() + .Bind().To() + .Bind().To() + .Bind("base").To() + .Bind().To() + .Bind().To() + .Bind().To() + .DefaultLifetime(Lifetime.Singleton) .Bind().To() .Bind().To(_ => new CancellationTokenSource()) @@ -104,73 +165,6 @@ private void Setup() .Bind().To() .Bind().To() .Bind().To() - - .DefaultLifetime(Lifetime.PerBlock) - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().Bind(Tag.Type).To() - .Bind().Bind(Tag.Type).To() - .Bind().Bind(Tag.Type).To() - .Bind(typeof(VerbosityLevel)).To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind("default").To() - .Bind("custom").To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind("base").To() - .Bind().To() - .Bind().To() - .Bind().To() - - .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()?.FrameworkName ?? string.Empty) - .Bind().To(_ => Process.GetCurrentProcess()) - .Bind("ModuleFile").To((Process process) => process.MainModule?.FileName ?? string.Empty) - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind("base").To() - .Bind().To(_ => MemoryPool.Shared) - .Bind().To() - .Bind().To(); - - DI.Setup(nameof(Composition)) - .DefaultLifetime(Lifetime.Transient) - .Bind().To() - .Bind(Tag.Type).To() - .Bind().To() - .Bind(Tag.Unique).To() - .Bind(Tag.Unique).To() - .Bind().To() - .Bind().To() - - .DefaultLifetime(Lifetime.Singleton) - // Script options factory .Bind().To(_ => new Setting(LanguageVersion.Default)) .Bind().To(_ => new Setting(OptimizationLevel.Release)) .Bind().To(_ => new Setting((WarningLevel)ScriptOptions.Default.WarningLevel)) @@ -206,23 +200,18 @@ private void Setup() .Bind(Tag.Unique).To() .Bind("Default", "Ansi").To() .Bind("TeamCity").To() + .Bind().To((ICISpecific properties) => properties.Instance) - // Public + // Public services .Bind().To() - .Bind().To((ICISpecific properties) => properties.Instance) .Bind().To() .Bind().To() .Bind().To() - - // TeamCity Service messages .Bind().To() .Bind().To() .Bind().To() - .Bind().As(Lifetime.Transient).To(_ => DateTime.Now) .Bind().To() - .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(); } } \ No newline at end of file