// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var token = Configuration["TELEGRAM_TOKEN"]; var secretKey = Configuration["TELEGRAM_SECRETKEY"]; if (string.IsNullOrEmpty(token)) { throw new ArgumentNullException("Telegram token must be not null"); } var connection = Configuration["MONGO"]; var proxyAddress = Configuration["PROXY_ADDRESS"]; var proxyPort = Configuration["PROXY_PORT"]; var proxy = GetProxy(proxyAddress, proxyPort); if (!string.IsNullOrEmpty(connection)) { MongoDBHelper.ConfigureConnection(connection); } TestDB(); Console.WriteLine($"Connection string is {MongoDBHelper.GetConnectionName}"); services.AddMvc(); services.AddSingleton <ITelegramBot>(_ => new FindITBot(token, secretKey, proxy).Start()); }