Skip to content

Commit

Permalink
di-29
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Aug 1, 2024
1 parent 39453b6 commit 763d714
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 54 deletions.
2 changes: 1 addition & 1 deletion CSharpInteractive.Tests/CSharpInteractive.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
<PackageReference Include="Moq" Version="4.20.70"/>
<PackageReference Include="Pure.DI" Version="2.1.27">
<PackageReference Include="Pure.DI" Version="2.1.29">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion CSharpInteractive/CSharpInteractive.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PackageReference Include="NuGet.Build.Tasks" Version="6.4.0"/>
<PackageReference Include="Microsoft.Build.Framework" Version="16.8.0" IncludeAssets="all"/>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" IncludeAssets="all"/>
<PackageReference Include="Pure.DI" Version="2.1.27">
<PackageReference Include="Pure.DI" Version="2.1.29">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion CSharpInteractive/CSharpInteractive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="NuGet.Build.Tasks" Version="6.4.0"/>
<PackageReference Include="Microsoft.Build.Framework" Version="16.8.0" IncludeAssets="all"/>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" IncludeAssets="all"/>
<PackageReference Include="Pure.DI" Version="2.1.27">
<PackageReference Include="Pure.DI" Version="2.1.29">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
63 changes: 12 additions & 51 deletions CSharpInteractive/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,25 @@ private void Setup()
.Bind("TeamCity").To<TeamCityInOut>()
.Bind("Ansi").To<AnsiInOut>()
.Bind().To<Console>()
.Bind().To(ctx =>
{
ctx.Inject<ICISpecific<IStdOut>>(out var stdOut);
return stdOut.Instance;
})
.Bind().To(ctx =>
{
ctx.Inject<ICISpecific<IStdErr>>(out var stdErr);
return stdErr.Instance;
})
.Bind().To((ICISpecific<IStdOut> stdOut) => stdOut.Instance)
.Bind().To((ICISpecific<IStdErr> stdErr) => stdErr.Instance)
.Bind("Default", "Ansi").To<Log<TT>>()
.Bind("TeamCity").To<TeamCityLog<TT>>()
.Bind().To(ctx =>
{
ctx.Inject<ICISpecific<ILog<TT>>>(out var log);
return log.Instance;
})
.Bind().To((ICISpecific<ILog<TT>> log) => log.Instance)
.Bind().To<CISettings>()
.Bind().To<ExitTracker>()
.Bind().Bind<ITraceSource>(Tag.Type).To<Environment>()
.Bind<IEnvironmentVariables>().Bind<ITraceSource>(Tag.Type).To<EnvironmentVariables>()
.Bind().To<Settings>()
.Bind().To<Info>()
.Bind().To<ConsoleSource>()
.Bind(typeof(LoadFileCodeSource)).To(ctx => new Func<string, ICodeSource>(name =>
.Bind(typeof(LoadFileCodeSource)).To((LoadFileCodeSource loadFileCodeSource) => new Func<string, ICodeSource>(name =>
{
ctx.Inject<LoadFileCodeSource>(out var loadFileCodeSource);
loadFileCodeSource.Name = name;
return loadFileCodeSource;
}))
.Bind(typeof(LineCodeSource)).To(ctx => new Func<string, ICodeSource>(line =>
.Bind(typeof(LineCodeSource)).To((LineCodeSource lineCodeSource) => new Func<string, ICodeSource>(line =>
{
ctx.Inject<LineCodeSource>(out var lineCodeSource);
lineCodeSource.Line = line;
return lineCodeSource;
}))
Expand Down Expand Up @@ -159,23 +145,10 @@ private void Setup()
.Bind().To(_ => typeof(Composition).Assembly)
.Bind().To(_ => new CSharpParseOptions().LanguageVersion)
.Bind("RuntimePath").To(_ => Path.GetDirectoryName(typeof(object).Assembly.Location) ?? string.Empty)
.Bind().To(ctx =>
{
ctx.Inject<CancellationTokenSource>(out var cancellationTokenSource);
return cancellationTokenSource.Token;
})
.Bind("TargetFrameworkMoniker").To(ctx =>
{
ctx.Inject<Assembly>(out var assembly);
return assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName ?? string.Empty;
})
.Bind().To((CancellationTokenSource cancellationTokenSource) => cancellationTokenSource.Token)
.Bind("TargetFrameworkMoniker").To((Assembly assembly) => assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName ?? string.Empty)
.Bind().To(_ => Process.GetCurrentProcess())
.Bind("ModuleFile").To(ctx =>
{
ctx.Inject<Process>(out var process);
return process.MainModule?.FileName ?? string.Empty;
})

.Bind("ModuleFile").To((Process process) => process.MainModule?.FileName ?? string.Empty)
.Bind().To<ScriptCommandFactory>()
.Bind().To<ReliableBuildContext>()
.Bind().To<ProcessMonitor>()
Expand Down Expand Up @@ -235,11 +208,7 @@ private void Setup()

// Public
.Bind().To<HostService>()
.Bind().To(ctx =>
{
ctx.Inject<ICISpecific<IProperties>>(out var properties);
return properties.Instance;
})
.Bind().To((ICISpecific<IProperties> properties) => properties.Instance)
.Bind().To<NuGetService>()
.Bind().To<CommandLineRunner>()
.Bind().To<BuildRunner>()
Expand All @@ -250,17 +219,9 @@ private void Setup()
.Bind().To<FlowIdGenerator>()
.Bind().As(Lifetime.Transient).To(_ => DateTime.Now)
.Bind().To<TimestampUpdater>()
.Bind().To(
ctx =>
{
ctx.Inject<ITeamCityServiceMessages>(out var teamCityServiceMessages);
return teamCityServiceMessages.CreateWriter(
str =>
{
ctx.Inject<IConsole>(out var console);
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 763d714

Please sign in to comment.