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