Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ChatroomDbContext dbContext)
        {
            EnsureDbConnection(dbContext);
            dbContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseCors("DevCORS");
            }
            else
            {
                app.UseCors("ProdCORS");
            }

            app.UseHttpsRedirection();
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub <ChatroomHub>("/slr/chatroom");
            });
        }
Example #2
0
 private void EnsureDbConnection(ChatroomDbContext dbContext, int retries = 0)
 {
     if (!dbContext.Database.CanConnect())
     {
         if (retries == 10)
         {
             Console.WriteLine("Max retries reached.");
             return;
         }
         retries += 1;
         Console.WriteLine("DB unreachable. Attempting connection after {0} ms. Retry count: {1}", 3000, retries);
         Thread.Sleep(3000);
         EnsureDbConnection(dbContext, retries);
     }
 }
Example #3
0
 public Repository(ChatroomDbContext context)
 {
     _context = context;
 }