1- using Microsoft . Extensions . Configuration ;
2- using System ;
3- using System . Collections . Generic ;
1+ using System ;
42using Microsoft . Extensions . DependencyInjection ;
53using Microsoft . Extensions . Logging ;
64using System . Threading . Tasks ;
75using SmartCode . Configuration ;
86using System . IO ;
97using SmartCode . Configuration . ConfigBuilders ;
108using System . Reflection ;
11- using System . Linq ;
129
1310namespace SmartCode . App
1411{
1512 public class SmartCodeApp
1613 {
17- const string APP_SETTINGS_PATH = "appsettings.json" ;
18- const string SMARTCODE_KEY = "SmartCode" ;
19- public IConfigurationRoot Configuration { get ; private set ; }
20- public SmartCodeOptions SmartCodeOptions { get ; private set ; }
14+ public SmartCodeOptions SmartCodeOptions { get ; }
2115 public String AppDirectory { get { return AppDomain . CurrentDomain . BaseDirectory ; } }
2216 public IConfigBuilder ConfigBuilder { get ; private set ; }
23- public IServiceCollection Services { get ; private set ; }
17+ public IServiceCollection Services { get { return SmartCodeOptions . Services ; } }
2418 public IServiceProvider ServiceProvider { get ; private set ; }
2519 public Project Project { get ; private set ; }
26- public string ConfigPath { get ; }
20+ public string ConfigPath { get { return SmartCodeOptions . ConfigPath ; } }
2721 public ILogger < SmartCodeApp > Logger { get ; private set ; }
28- public SmartCodeApp ( String configPath )
22+ public SmartCodeApp ( SmartCodeOptions smartCodeOptions )
2923 {
30- ConfigPath = configPath ;
24+ SmartCodeOptions = smartCodeOptions ;
3125 BuildProject ( ) ;
32- InitConfig ( ) ;
3326 RegisterServices ( ) ;
3427 }
3528
@@ -55,25 +48,11 @@ private void BuildProject()
5548 }
5649 Project = ConfigBuilder . Build ( ) ;
5750 }
58- private void InitConfig ( )
59- {
60- var appSettingsbuilder = new ConfigurationBuilder ( )
61- . SetBasePath ( AppDirectory )
62- . AddJsonFile ( APP_SETTINGS_PATH , false , true ) ;
63- Configuration = appSettingsbuilder . Build ( ) ;
64- SmartCodeOptions = Configuration . GetSection ( SMARTCODE_KEY ) . Get < SmartCodeOptions > ( ) ;
65- }
6651
6752 private void RegisterServices ( )
6853 {
69- Services = new ServiceCollection ( ) ;
7054 Services . AddSingleton < SmartCodeOptions > ( SmartCodeOptions ) ;
7155 Services . AddSingleton < Project > ( Project ) ;
72- Services . AddLogging ( ( loggerBuilder ) =>
73- {
74- var loggingConfig = Configuration . GetSection ( "Logging" ) ;
75- loggerBuilder . AddConfiguration ( loggingConfig ) . AddConsole ( ) ;
76- } ) ;
7756 RegisterPlugins ( ) ;
7857 Services . AddSingleton < IPluginManager , PluginManager > ( ) ;
7958 Services . AddSingleton < IProjectBuilder , ProjectBuilder > ( ) ;
0 commit comments