-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependencyInjectionConfiguring.cs
160 lines (138 loc) · 4.82 KB
/
DependencyInjectionConfiguring.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using Backend.Auth.Dal;
using Backend.Auth.Dal.Interfaces;
using Backend.Auth.Logic;
using Backend.Auth.Logic.Interfaces;
using Backend.Base.Services;
using Backend.Base.Services.Filters;
using Backend.Base.Services.Interfaces;
using Backend.Base.Services.ModelBinders;
using Backend.Chat.Dal;
using Backend.Chat.Dal.Interfaces;
using Backend.Chat.Logic;
using Backend.CoursePages.Dal;
using Backend.CoursePages.Dal.Interfaces;
using Backend.CoursePages.Logic;
using Backend.Courses.Dal;
using Backend.Courses.Dal.Interfaces;
using Backend.Courses.Logic;
using Backend.Progress.Dal;
using Backend.Progress.Dal.Interfaces;
using Backend.Progress.Logic;
using Microsoft.EntityFrameworkCore;
namespace Backend;
public class DependencyInjectionConfiguring
{
private IServiceCollection _services { get; set; }
public DependencyInjectionConfiguring(IServiceCollection services)
{
_services = services;
}
public void RegisterServices()
{
RegisterAspServices();
RegisterMyServices();
}
private void RegisterAspServices()
{
_services.AddHttpContextAccessor();
_services.AddControllers(options => options.ModelBinderProviders.Insert(0, new CustomDateTimeModelBinderProvider()));
_services.AddEndpointsApiExplorer();
_services.AddSwaggerGen(c =>
{
c.OperationFilter<SwaggerAuthorizationHeaderFilter>();
});
_services.AddDbContext<AppDatabase>(options => options.UseNpgsql());
}
private void RegisterMyServices()
{
RegisterDatabaseRepositories();
RegisterBusinessServices();
}
private void RegisterDatabaseRepositories()
{
RegisterAuthDbRepos();
RegisterCoursesDbRepos();
RegisterCoursePagesDbRepos();
RegisterProgressDbRepos();
RegisterChatDbRepos();
}
private void RegisterAuthDbRepos()
{
_services.AddScoped<IAccountRepo, AccountRepo>();
_services.AddScoped<IUserRepo, UserRepo>();
_services.AddScoped<IStudentRepo, StudentRepo>();
_services.AddScoped<ITeacherRepo, TeacherRepo>();
_services.AddScoped<IPasswordRepo, PasswordRepo>();
}
private void RegisterCoursesDbRepos()
{
_services.AddScoped<IGroupRepo, GroupRepo>();
_services.AddScoped<ICourseChaptersRepo, CourseChaptersRepo>();
_services.AddScoped<ICourseRepo, CourseRepo>();
_services.AddScoped<IGroupCoursesRepo, GroupCoursesRepo>();
_services.AddScoped<IGroupRepo, GroupRepo>();
_services.AddScoped<IStudentGroupsRepo, StudentGroupsRepo>();
}
private void RegisterCoursePagesDbRepos()
{
_services.AddScoped<ICoursePageRepo, CoursePageRepo>();
_services.AddScoped<ITaskPageRepo, TaskPageRepo>();
_services.AddScoped<ITestPageRepo, TestPageRepo>();
_services.AddScoped<IOpenedQuestionRepo, OpenedQuestionRepo>();
_services.AddScoped<IOneOptionQuestionRepo, OneOptionQuestionRepo>();
_services.AddScoped<IManyOptionQuestionRepo, ManyOptionQuestionRepo>();
_services.AddScoped<IQuestionOptionRepo, QuestionOptionRepo>();
_services.AddScoped<ITheoryPageRepo, TheoryPageRepo>();
_services.AddScoped<ITestQuestionRepo, TestQuestionRepo>();
}
private void RegisterProgressDbRepos()
{
_services.AddScoped<ITaskAnswerRepo, TaskAnswerRepo>();
_services.AddScoped<ITaskScoreRepo, TaskScoreRepo>();
}
private void RegisterChatDbRepos()
{
_services.AddScoped<IMessageRepo, MessageRepo>();
_services.AddScoped<IChatRepo, ChatRepo>();
}
private void RegisterBusinessServices()
{
RegisterHelperServices();
RegisterAuthLogic();
RegisterCoursesLogic();
RegisterCoursePagesLogic();
RegisterProgressLogic();
RegisterChatLogic();
}
private void RegisterAuthLogic()
{
_services.AddScoped<UserService>();
_services.AddScoped<AccountService>();
}
private void RegisterCoursesLogic()
{
_services.AddScoped<GroupService>();
_services.AddScoped<CourseService>();
_services.AddScoped<CourseChaptersService>();
}
private void RegisterCoursePagesLogic()
{
_services.AddScoped<CoursePagesService>();
_services.AddScoped<Md5EditorFilesService>();
}
private void RegisterProgressLogic()
{
_services.AddScoped<ProgressService>();
}
private void RegisterChatLogic()
{
_services.AddScoped<ChatService>();
}
private void RegisterHelperServices()
{
_services.AddScoped<IPasswordHelperService, PasswordHelperService>();
_services.AddScoped<IEncryptionService, EncryptionService>();
_services.AddScoped<IFileManager, StaticFilesManager>();
_services.AddScoped<IUserIdGetter, UserIdGetter>();
}
}