44using Microsoft . Extensions . Hosting ;
55using Microsoft . Extensions . Logging ;
66using Oxide . CompilerServices . Interfaces ;
7- using Oxide . CompilerServices . Models . Configuration ;
87using Oxide . CompilerServices . Services ;
8+ using Oxide . CompilerServices . Types . Configuration ;
99using Serilog ;
1010
1111namespace Oxide . CompilerServices . Common ;
1212
1313public static class DependencyInjection
1414{
15- public static void AddServices ( this IServiceCollection services , IConfiguration configuration , string [ ] args )
15+ public static void AddServices ( this IServiceCollection services , ConfigurationManager configuration , string [ ] args )
1616 {
1717 services . Configure < HostOptions > ( service =>
1818 {
1919 service . ServicesStartConcurrently = true ;
2020 service . ServicesStopConcurrently = true ;
2121 } ) ;
2222
23- ConfigurationBuilder configurationBuilder = new ( ) ;
2423
25- configurationBuilder . AddCommandLine ( args , Constants . SwitchMappings ) ;
26- configurationBuilder . AddJsonFile ( Path . Combine ( Constants . RootPath , "oxide.compiler.json" ) , true ) ;
27- configurationBuilder . AddEnvironmentVariables ( "Oxide_" ) ;
24+ configuration . AddCommandLine ( args , Constants . SwitchMappings ) ;
25+ configuration . AddJsonFile ( Path . Combine ( Constants . RootPath , "oxide.compiler.json" ) , true ) ;
26+ configuration . AddEnvironmentVariables ( "Oxide_" ) ;
2827
29- IConfigurationRoot configurationRoot = configurationBuilder . Build ( ) ;
30-
31- string mode = configurationRoot . GetValue < string > ( "Mode" , "release" ) ;
28+ string mode = configuration . GetValue < string > ( "Mode" , "release" ) ;
3229 if ( mode == "test" )
3330 {
34- string ? sourcePath = configurationRoot . GetValue < string > ( "Source" ) ;
31+ string ? sourcePath = configuration . GetValue < string > ( "Source" ) ;
3532 //return CompileTestFilesAsync(sourcePath, outputPath, application.ServiceProvider);
3633 }
3734
38- services . Configure < CompilerConfiguration > ( configurationRoot . GetSection ( "Compiler" ) ) ;
39- services . Configure < DirectoryConfiguration > ( configurationRoot . GetSection ( "Path" ) ) ;
40- services . Configure < LoggingConfiguration > ( configurationRoot . GetSection ( "Logging" ) ) ;
35+ services . Configure < CompilerConfiguration > ( configuration . GetSection ( "Compiler" ) ) ;
36+ services . Configure < DirectoryConfiguration > ( configuration . GetSection ( "Path" ) ) ;
37+ services . Configure < LoggingConfiguration > ( configuration . GetSection ( "Logging" ) ) ;
4138
4239
4340 services . AddLogging ( loggingBuilder =>
4441 {
45- IConfigurationSection logSettings = configurationRoot . GetSection ( "Logging" ) ;
42+ IConfigurationSection logSettings = configuration . GetSection ( "Logging" ) ;
4643 string filePath = logSettings . GetValue ( "FileName" , "oxide.compiler.log" ) ;
4744
4845 if ( filePath . Equals ( "oxide.compiler.log" ) )
4946 {
50- IConfigurationSection pathSettings = configurationRoot . GetSection ( "Path" ) ;
47+ IConfigurationSection pathSettings = configuration . GetSection ( "Path" ) ;
5148 string startDirectory = pathSettings . GetValue ( "Logging" , Environment . CurrentDirectory ) ;
5249 filePath = Path . Combine ( startDirectory , filePath ) ;
5350 }
@@ -60,19 +57,18 @@ public static void AddServices(this IServiceCollection services, IConfiguration
6057#if DEBUG
6158 loggingBuilder . AddDebug ( ) ;
6259#endif
63- if ( ! configurationRoot . GetSection ( "Compiler" ) . GetValue ( "EnableMessageStream" , false ) )
60+ if ( ! configuration . GetSection ( "Compiler" ) . GetValue ( "EnableMessageStream" , false ) )
6461 {
6562 loggingBuilder . AddSimpleConsole ( ) ;
6663 }
6764 } ) ;
6865
6966
70- services . AddSingleton ( configurationRoot ) ;
67+ services . AddSingleton < IConfigurationRoot > ( configuration ) ;
7168 services . AddSingleton < AppConfiguration > ( ) ;
7269 services . AddSingleton < ICompilationService , CompilationService > ( ) ;
7370 services . AddTransient < MetadataReferenceResolver , OxideResolver > ( ) ;
7471 services . AddSingleton < MessageBrokerService > ( ) ;
75- services . AddSingleton < ISerializer , Serializer > ( ) ;
7672 services . AddSingleton < IEntryPointService , EntryPointService > ( ) ;
7773 services . AddHostedService < AppHostService > ( ) ;
7874 }
0 commit comments