-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
94 lines (84 loc) · 3.23 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
using ChatApp.Hubs;
using ChatApp.Hubs.FriendRequestHub;
using ChatApp.Models.Context;
using ChatApp.Models.Entities;
using ChatApp.Models.Identity;
using ChatApp.Services;
using ChatApp.Services.AuthService;
using ChatApp.Services.FriendRequestService;
using ChatApp.Services.FriendService;
using ChatApp.Services.GroupChatService;
using ChatApp.Services.ProfileService;
using ChatApp.Services.ViewModelService;
using ChatApp.ViewModels;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace ChatApp
{
public class Startup
{
private IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IUserService, UserService>();
services.AddTransient<IChatService, ChatService>();
services.AddTransient<IFriendService, FriendService>();
services.AddTransient<IViewModelService, MainVM>();
services.AddTransient<IFriendRequestService, FriendRequestService>();
services.AddTransient<IProfileImageService, ProfileImageService>();
services.AddTransient<IGroupChatService, GroupChatService>();
services.AddDbContext<DataContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("ChatAppDb"));
});
services.AddDbContext<ChatContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("ChatAppDb")
));
services.AddIdentity<AppUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 6;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireDigit = false;
})
.AddEntityFrameworkStores<DataContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Auth";
options.SlidingExpiration = true;
});
services.AddSignalR();
services.AddMvc();
services.AddHttpContextAccessor();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStatusCodePages();
app.UseHttpsRedirection();
app.UseCookiePolicy();
app.UseStaticFiles();
app.UseAuthentication();
app.UseSignalR(routes =>
{
routes.MapHub<FriendRequestHub>("/friendRequestHub");
routes.MapHub<ChatHub>("/chatHub");
});
app.UseMvcWithDefaultRoute();
}
}
}