source: ChapterX.Infrastructure/DependencyInjection.cs@ a8f4a2d

main
Last change on this file since a8f4a2d was d300631, checked in by kikisrbinoska <srbinoskakristina07@…>, 2 months ago

Added transactions and pooling

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[877c13c]1using ChapterX.Application.Abstractions;
[e294f7d]2using ChapterX.Application.Auth;
[877c13c]3using ChapterX.Domain.Repositories;
4using ChapterX.Infrastructure.Data.DataContext;
5using ChapterX.Infrastructure.Repositories;
[e294f7d]6using ChapterX.Infrastructure.Services;
[877c13c]7using Microsoft.EntityFrameworkCore;
8using Microsoft.Extensions.Configuration;
9using Microsoft.Extensions.DependencyInjection;
10
11namespace ChapterX.Infrastructure
12{
13 public static class DependencyInjection
14 {
15 public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
16 {
[d300631]17 var poolSection = configuration.GetSection("ConnectionPool");
18 var minPoolSize = poolSection.GetValue<int>("MinPoolSize", 1);
19 var maxPoolSize = poolSection.GetValue<int>("MaxPoolSize", 20);
20 var idleLifetime = poolSection.GetValue<int>("ConnectionIdleLifetime", 300);
21 var pruningInterval = poolSection.GetValue<int>("ConnectionPruningInterval", 10);
22 var commandTimeout = poolSection.GetValue<int>("CommandTimeout", 30);
23 var connectionTimeout = poolSection.GetValue<int>("Timeout", 15);
24
25 var baseConnectionString = configuration.GetConnectionString("Database")!;
26 var connectionString =
27 $"{baseConnectionString};Minimum Pool Size={minPoolSize};Maximum Pool Size={maxPoolSize};" +
28 $"Connection Idle Lifetime={idleLifetime};Connection Pruning Interval={pruningInterval};" +
29 $"Command Timeout={commandTimeout};Timeout={connectionTimeout}";
30
31 services.AddDbContextPool<ApplicationDbContext>(options =>
32 options.UseNpgsql(connectionString));
[877c13c]33
34 services.AddScoped<IApplicationDbContext>(sp => sp.GetRequiredService<ApplicationDbContext>());
[e294f7d]35 services.AddScoped<IJwtTokenService, JwtTokenService>();
[877c13c]36
37 services.AddScoped<IUserRepository, UserRepository>();
38 services.AddScoped<IWriterRepository, WriterRepository>();
39 services.AddScoped<IStoryRepository, StoryRepository>();
40 services.AddScoped<IAdminRepository, AdminRepository>();
41 services.AddScoped<IRegularUserRepository, RegularUserRepository>();
42 services.AddScoped<IGenreRepository, GenreRepository>();
43 services.AddScoped<IReadingListRepository, ReadingListRepository>();
44 services.AddScoped<IReadingListItemsRepository, ReadingListItemsRepository>();
45 services.AddScoped<INotificationRepository, NotificationRepository>();
46 services.AddScoped<INotifyRepository, NotifyRepository>();
47 services.AddScoped<INeedApprovalRepository, NeedApprovalRepository>();
48 services.AddScoped<ILikesRepository, LikesRepository>();
49 services.AddScoped<IHasGenreRepository, HasGenreRepository>();
50 services.AddScoped<ICollaborationRepository, CollaborationRepository>();
51 services.AddScoped<IChapterRepository, ChapterRepository>();
52 services.AddScoped<ICommentRepository, CommentRepository>();
53 services.AddScoped<IAISuggestionRepository, AISuggestionRepository>();
54 services.AddScoped<IContentTypeRepository, ContentTypeRepository>();
55 services.AddScoped<IPermissionLevelRepository, PermissionLevelRepository>();
56 services.AddScoped<IRolesRepository, RolesRepository>();
57 services.AddScoped<IStatusRepository, StatusRepository>();
58
59 return services;
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.