private static void RegisterStorage(ConsoleAppConfig cfg, IServiceCollection serviceCollection) { BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128)); BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer <decimal>(new DecimalSerializer(BsonType.Decimal128))); var mongoClient = new MongoClient(cfg.MongoConnectionString); var db = mongoClient.GetDatabase(cfg.MongoDbName); serviceCollection.AddSingleton(typeof(IMongoDatabase), (provider) => db); serviceCollection.AddTransient(typeof(IStorage <CardOperation>), typeof(CardOperationStorage)); serviceCollection.AddTransient(typeof(IStorage <CardOperationsImport>), typeof(CardOperationsImportStorage)); serviceCollection.AddTransient(typeof(IDbLogicManager), typeof(DbLogicManager)); }
private static ConsoleAppConfig ReadConfig() { #if DEBUG var cfgFileName = "appsettings.json"; #else var cfgFileName = "appsettings.Release.json"; #endif IConfiguration jsonConfig = new ConfigurationBuilder() .AddJsonFile(cfgFileName, true, true) .Build(); var cfg = new ConsoleAppConfig(); cfg.OperationsReportsDataFolderPath = jsonConfig["OperationsReportsDataFolderPath"]; cfg.MongoConnectionString = jsonConfig["MongoConnectionString"]; cfg.MongoDbName = jsonConfig["MongoDbName"]; return(cfg); }
public static ServiceProvider InitApp(ConsoleAppConfig cfg) { // init app Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Console.OutputEncoding = Encoding.Default; Console.InputEncoding = Encoding.GetEncoding(1251); var serviceCollection = new ServiceCollection(); RegisterStorage(cfg, serviceCollection); serviceCollection.AddTransient(typeof(IReportFileChoseStrategy), typeof(DefaultReportFileChoseStrategy)); serviceCollection.AddTransient(typeof(IModelStringView <CardOperation>), typeof(CardOperationStringView)); serviceCollection.AddTransient(typeof(IModelStringView <OperationSetStatistics>), typeof(CardOperationSetStatisticsStringView)); serviceCollection.AddTransient(typeof(ICardOperationParser), typeof(CsvCardOperationParser)); serviceCollection.AddTransient(typeof(IDateRangeParser), typeof(DateRangeParser)); serviceCollection.AddSingleton(typeof(IConfigurationProvider), new ConfigProvider(cfg)); serviceCollection.AddTransient(typeof(ICardOperationsLoader), typeof(FileSystemOperationsLoader)); serviceCollection.AddTransient(typeof(ImportCardOperationsCommand), typeof(ImportCardOperationsCommand)); serviceCollection.AddTransient(typeof(ShowOperationsCommand), typeof(ShowOperationsCommand)); serviceCollection.AddTransient(typeof(ShowOperationsByPeriodCommand), typeof(ShowOperationsByPeriodCommand)); serviceCollection.AddTransient(typeof(ShowOperationsByCategoryCommand), typeof(ShowOperationsByCategoryCommand)); serviceCollection.AddTransient(typeof(OutcomeByCategoryReportCommand), typeof(OutcomeByCategoryReportCommand)); serviceCollection.AddTransient(typeof(ShowAllCategoriesCommand), typeof(ShowAllCategoriesCommand)); serviceCollection.AddTransient(typeof(ManageOperationsUserInterfaceCommand), typeof(ManageOperationsUserInterfaceCommand)); serviceCollection.AddTransient(typeof(SetCardOperationSetCommand), typeof(SetCardOperationSetCommand)); serviceCollection.AddTransient(typeof(EditCardOperationsCommand), typeof(EditCardOperationsCommand)); serviceCollection.AddTransient(typeof(AddCardOperationToCategoryCommand), typeof(AddCardOperationToCategoryCommand)); serviceCollection.AddTransient(typeof(SearchForOperationsCommand), typeof(SearchForOperationsCommand)); serviceCollection.AddTransient(typeof(ExitCurrentMenuCommand), typeof(ExitCurrentMenuCommand)); var serviceProvider = serviceCollection.BuildServiceProvider(); serviceCollection.AddSingleton(typeof(IServiceProvider), serviceProvider); return(serviceProvider); }
public ConfigProvider(ConsoleAppConfig cfg) { _cfg = cfg; }