-
Notifications
You must be signed in to change notification settings - Fork 1
/
Startup.cs
119 lines (100 loc) · 4.34 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using QuizNSwap.Areas.Gameplay.SignalRHubs;
using QuizNSwap.Data;
using QuizNSwap.Data.Models;
namespace QuizNSwap
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddSignalR();
/* MSDN:
*
* Entity Framework contexts
Entity Framework contexts are usually added to the service container using the scoped lifetime
because web app database operations are normally scoped to the client request.
The default lifetime is scoped if a lifetime isn't specified by an AddDbContext<TContext> overload
when registering the database context. Services of a given lifetime shouldn't use a database context
with a shorter lifetime than the service.
*/
services
.AddDbContext<QuizNSwapContext>(options =>
options
.UseSqlite(Configuration
.GetConnectionString("DefaultConnection")));
services
.AddIdentity<User, IdentityRole>(opts =>
{
opts.User.RequireUniqueEmail = true;
opts.Password.RequiredLength = 6;
opts.Password.RequireNonAlphanumeric = false;
opts.Password.RequireLowercase = false;
opts.Password.RequireUppercase = false;
opts.Password.RequireDigit = false;
})
.AddEntityFrameworkStores<QuizNSwapContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options => options.LoginPath = "/");
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app
.UseEndpoints(endpoints =>
{
endpoints
.MapControllerRoute(name: "defaultDashboardAreaView",
pattern: "{area:exists}/{controller=Home}/{action=Index}");
//this one will try to get you to index if you specify area and controller
endpoints
.MapControllerRoute(name: "defaultActionSpecifiedAreaNController",
pattern: "{area:exists}/{controller}/{action=Index}");
//this one is for the action methods of the start-no-area place
endpoints
.MapControllerRoute(name: "ThreeParamsSpecified",
pattern: "{area:exists}/{controller}/{action}");
//this one is for appending index to a controller you specify in the start-no-area place
endpoints
.MapControllerRoute(name: "startDefaultAction",
pattern: "{controller}/{action=Index}");
//the start page
endpoints
.MapControllerRoute(name: "start",
pattern: "{controller=User}/{action=Index}");
//TODO: I don't want action methods and Index appended to the address bar.
endpoints.MapHub<ChatHub>("/chatHub"); //name of hub class
});
}
}
}