-
Notifications
You must be signed in to change notification settings - Fork 61
/
IoCConfiguration.cs
67 lines (63 loc) · 3.87 KB
/
IoCConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ReSharper disable InconsistentNaming
namespace TeamCity.Docker
{
using System;
using System.Collections.Generic;
using System.Threading;
using Generic;
using global::Docker.DotNet;
using IoC;
using JetBrains.TeamCity.ServiceMessages.Write;
using JetBrains.TeamCity.ServiceMessages.Write.Special;
using JetBrains.TeamCity.ServiceMessages.Write.Special.Impl.Updater;
using Model;
using static IoC.Lifetime;
internal class IoCConfiguration: IConfiguration
{
public IEnumerable<IToken> Apply(IMutableContainer container)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
yield return container
.Bind<CancellationTokenSource>().As(Singleton).To<CancellationTokenSource>()
.Bind<IFileSystem>().As(Singleton).To<FileSystem>()
.Bind<IEnvironment>().As(Singleton).To<Environment>()
.Bind<ILogger>().As(Singleton).Tag("Console").To<ConsoleLogger>()
.Bind<ILogger>().As(Singleton).Tag("TeamCity").To<TeamCityLogger>()
.Bind<ILogger>().As(Singleton).To<Logger>(ctx =>
new Logger(
ctx.Container.Inject<IOptions>(),
ctx.Container.Inject<IEnvironment>(),
ctx.Container.Inject<ILogger>("Console"),
ctx.Container.Inject<ILogger>("TeamCity")))
.Bind<IDockerClientFactory>().As(Singleton).To<DockerClientFactory>()
.Bind<IDockerClient>().To(ctx => ctx.Container.Inject<IDockerClientFactory>().Create().Result)
.Bind<IStreamService>().As(Singleton).To<StreamService>()
.Bind<IMessageLogger>().As(Singleton).To<MessageLogger>()
.Bind<IDockerConverter>().As(Singleton).To<DockerConverter>()
.Bind<IPathService>().As(Singleton).To<PathService>()
.Bind<IConfigurationExplorer>().As(Singleton).To<ConfigurationExplorer>()
.Bind<IContentParser>().As(Singleton).To<ContentParser>()
.Bind<IFactory<IEnumerable<IGraph<IArtifact, Dependency>>, IGraph<IArtifact, Dependency>>>().As(Singleton).To<BuildGraphsFactory>()
.Bind<IScriptGenerator>().As(Singleton).To<ScriptGenerator>()
.Bind<IGenerator>().Tag("Readme files").As(Singleton).To<ReadmeFilesGenerator>()
// -- Generation of Kotlin DSL via C# had been replaced with reusable build configurations.
// .Bind<IGenerator>().Tag("Kotlin DSL").As(Singleton).To<TeamCityKotlinSettingsGenerator>()
.Bind<IGenerator>().Tag("Scripts").As(Singleton).To<ScriptsGenerator>()
.Bind<IFactory<IGraph<IArtifact, Dependency>, IEnumerable<Template>>>().As(Singleton).To<DockerGraphFactory>()
.Bind<IContextFactory>().As(Singleton).To<ContextFactory>()
.Bind<IBuildPathProvider>().As(Singleton).To<BuildPathProvider>()
.Bind<IFactory<NodesDescription, IEnumerable<INode<IArtifact>>>>().As(Singleton).To<NodesNameFactory>()
// TeamCity messages
.Bind<IServiceMessageFormatter>().As(Singleton).To<ServiceMessageFormatter>()
.Bind<IFlowIdGenerator>().As(Singleton).To<FlowIdGenerator>()
.Bind<IServiceMessageUpdater>().As(Singleton).To(ctx => new TimestampUpdater(() => DateTime.Now) )
.Bind<ITeamCityServiceMessages>().As(Singleton).To<TeamCityServiceMessages>()
.Bind<ITeamCityWriter, ITeamCityMessageWriter>().As(Singleton).To(ctx => ctx.Container.Inject<ITeamCityServiceMessages>().CreateWriter())
.Bind<ICommand<IGenerateOptions>>().As(Singleton).To<GenerateCommand>()
.Bind<ICommand<IBuildOptions>>().As(Singleton).To<BuildCommand>();
}
}
}