1+ using System ;
12using GitVersion . BuildServers ;
23using Microsoft . Extensions . DependencyInjection ;
34using GitVersion . Common ;
5+ using GitVersion . Configuration ;
46using GitVersion . Logging ;
7+ using Microsoft . Extensions . Options ;
8+ using Environment = GitVersion . Common . Environment ;
59
610namespace GitVersion
711{
@@ -15,6 +19,29 @@ public void RegisterTypes(IServiceCollection services)
1519
1620 services . AddSingleton < IExecuteCore , ExecuteCore > ( ) ;
1721
22+ services . AddSingleton < IBuildServerResolver , BuildServerResolver > ( ) ;
23+ services . AddSingleton ( GetConfigFileLocator ) ;
24+
25+ RegisterBuildServers ( services ) ;
26+ }
27+
28+ private static IConfigFileLocator GetConfigFileLocator ( IServiceProvider sp )
29+ {
30+ var fileSystem = sp . GetService < IFileSystem > ( ) ;
31+ var log = sp . GetService < ILog > ( ) ;
32+ var arguments = sp . GetService < IOptions < Arguments > > ( ) ;
33+
34+ var configFile = arguments . Value . ConfigFile ;
35+
36+ var configFileLocator = string . IsNullOrWhiteSpace ( configFile )
37+ ? new DefaultConfigFileLocator ( fileSystem , log ) as IConfigFileLocator
38+ : new NamedConfigFileLocator ( configFile , fileSystem , log ) ;
39+
40+ return configFileLocator ;
41+ }
42+
43+ private static void RegisterBuildServers ( IServiceCollection services )
44+ {
1845 services . AddSingleton < IBuildServer , ContinuaCi > ( ) ;
1946 services . AddSingleton < IBuildServer , TeamCity > ( ) ;
2047 services . AddSingleton < IBuildServer , AppVeyor > ( ) ;
@@ -26,8 +53,6 @@ public void RegisterTypes(IServiceCollection services)
2653 services . AddSingleton < IBuildServer , EnvRun > ( ) ;
2754 services . AddSingleton < IBuildServer , Drone > ( ) ;
2855 services . AddSingleton < IBuildServer , CodeBuild > ( ) ;
29-
30- services . AddSingleton < IBuildServerResolver , BuildServerResolver > ( ) ;
3156 }
3257 }
3358}
0 commit comments