private RandomWordsService InitializeService() { PancakeConfiguration pancakeConfiguration = new PancakeConfiguration { DBConnectionString = "Host=localhost;Database=Words;Username=postgres;Password=marshmallow" }; RandomWordsService randomWordsService = new RandomWordsService(); randomWordsService.Init(pancakeConfiguration); return(randomWordsService); }
private PancakeContext _db; //todo: подключение должно быть одно на все сервисы? public void Init(PancakeConfiguration configuration) { try { _db = new PancakeContext(configuration); IsInitialized = true; } catch (Exception e) { Console.WriteLine($"Error connecting to database: {e}"); throw; } }
public void Init(PancakeConfiguration configuration) { if (!IsInitialized) { try { _db = new PancakeContext(configuration); IsInitialized = true; } catch (Exception e) { Console.WriteLine($"Error connecting to database: {e}"); throw; } } else { Console.WriteLine($"RandomWordsService already initialized!"); } }
public PancakeContext(PancakeConfiguration pancakeConfiguration) { _connectionString = pancakeConfiguration.DBConnectionString; }