Advertisement
Gesh4o

Startup

Dec 21st, 2017
5,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. namespace P2PChat.Web
  2. {
  3.     using Microsoft.AspNetCore.Builder;
  4.     using Microsoft.AspNetCore.Identity;
  5.     using Microsoft.EntityFrameworkCore;
  6.     using Microsoft.AspNetCore.Hosting;
  7.     using Microsoft.Extensions.Configuration;
  8.     using Microsoft.Extensions.DependencyInjection;
  9.  
  10.     using P2PChat.Web.Data;
  11.     using P2PChat.Web.Models;
  12.     using P2PChat.Web.Services;
  13.     using P2PChat.Web.Contracts;
  14.     using P2PChat.Web.Hubs;
  15.  
  16.     public class Startup
  17.     {
  18.         public Startup(IConfiguration configuration)
  19.         {
  20.             Configuration = configuration;
  21.         }
  22.  
  23.         public IConfiguration Configuration { get; }
  24.  
  25.         // This method gets called by the runtime. Use this method to add services to the container.
  26.         public void ConfigureServices(IServiceCollection services)
  27.         {
  28.             services.AddDbContext<ApplicationDbContext>(options =>
  29.                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  30.  
  31.             services.AddIdentity<ApplicationUser, IdentityRole>()
  32.                 .AddEntityFrameworkStores<ApplicationDbContext>()
  33.                 .AddDefaultTokenProviders();
  34.  
  35.             // Add application services.
  36.             services.AddTransient<IEmailSender, EmailSender>();
  37.             services.AddSingleton<IChatConnectionService, ChatConnectionService>();
  38.             services.AddMvc();
  39.             services.AddSignalR();
  40.  
  41.             services.AddAuthentication().AddCookie();
  42.         }
  43.  
  44.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  45.         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  46.         {
  47.             if (env.IsDevelopment())
  48.             {
  49.                 app.UseDeveloperExceptionPage();
  50.                 app.UseBrowserLink();
  51.                 app.UseDatabaseErrorPage();
  52.             }
  53.             else
  54.             {
  55.                 app.UseExceptionHandler("/Home/Error");
  56.             }
  57.  
  58.             app.UseStaticFiles();
  59.             app.UseAuthentication();
  60.  
  61.             app.UseSignalR(routes =>
  62.             {
  63.                 routes.MapHub<ChatHub>("chat");
  64.             });
  65.  
  66.             app.UseMvc(routes =>
  67.             {
  68.                 routes.MapRoute(
  69.                     name: "default",
  70.                     template: "{controller=Home}/{action=Index}/{id?}");
  71.             });
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement