// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, PedramDbContext dbContext, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); dbContext.Database.Migrate(); //this will generate the db if it does not exist } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); var listener = new TCPListener(9990, serviceProvider.GetService <PedramDbContext>()); listener.AcceptSocket(); var nths = new Thread(CheckMessages); nths.Start(serviceProvider); }