예제 #1
0
        public AppData(ILogger <AppData>?logger, AppDataConfig config)
        {
            _config  = config ?? throw new ArgumentException(nameof(config));
            BasePath = config.BasePath ?? GetDefaultBasePath();
            _logger  = logger;

            Directory.CreateDirectory(TempPath);
            Directory.CreateDirectory(ConfigPath);
            Directory.CreateDirectory(DataPath);

            // Logger may be null when loading configuration
            _logger?.LogInformation($"Using '{BasePath}' as Application BasePath (Version : {CurrentVersion})");

            // Cleanup temp directory from eventual remaining files
            _logger?.LogInformation($"Cleaning '{TempPath}' for application startup");
            EmptyTemp();
        }
예제 #2
0
 public static IHostBuilder AddAppData(this IHostBuilder hostBuilder, string sectionName)
 {
     hostBuilder.ConfigureAppConfiguration((x, y) =>
     {
         var appDataConfig = new AppDataConfig();
         x.Configuration.GetSection(sectionName).Bind(appDataConfig);
         var appData = new AppData(null, appDataConfig);
         hostBuilder.Properties.Add(AppDataConfig, appDataConfig);
         foreach (var configFileName in appData.GetConfigFileNames())
         {
             // Support other types of config ?
             y.AddJsonFile(configFileName);
         }
     });
     hostBuilder.ConfigureServices((x, y) =>
     {
         y.AddAppData((AppDataConfig)x.Properties[AppDataConfig]);
     });
     return(hostBuilder);
 }
예제 #3
0
 public static IServiceCollection AddAppData(this IServiceCollection services, AppDataConfig config)
 {
     services.AddSingleton(config);
     services.AddSingleton <IAppDataMigrator, AppDataMigrator>();
     services.AddSingleton <IAppDataMigrationProvider, DefaultAppDataMigrationProvider>();
     services.AddSingleton <AppData>();
     return(services);
 }