-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyInjection.cs
More file actions
70 lines (67 loc) · 3.64 KB
/
DependencyInjection.cs
File metadata and controls
70 lines (67 loc) · 3.64 KB
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
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ShoeStore.Application.Interface;
using ShoeStore.Application.Interface.Authentication;
using ShoeStore.Application.Interface.CartItemInterface;
using ShoeStore.Application.Interface.CheckoutInterface;
using ShoeStore.Application.Interface.Common;
using ShoeStore.Application.Interface.MasterDataInterface;
using ShoeStore.Application.Interface.InvoiceInterface;
using ShoeStore.Application.Interface.Notification;
using ShoeStore.Application.Interface.ProductInterface;
using ShoeStore.Application.Interface.Strategies;
using ShoeStore.Application.Interface.UploadImage;
using ShoeStore.Application.Services;
using ShoeStore.Infrastructure.Authentication;
using ShoeStore.Infrastructure.Authentication.Strategies;
using ShoeStore.Infrastructure.Cloudinary;
using ShoeStore.Infrastructure.Data;
using ShoeStore.Infrastructure.Notification;
using ShoeStore.Infrastructure.Repositories;
using ShoeStore.Infrastructure.RestorePassService;
using ShoeStore.Application.Interface.VoucherInterface;
namespace ShoeStore.Infrastructure.DependencyInjection;
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<CloudinarySettings>(configuration.GetSection("Cloudinary"));
var connectionString = configuration.GetConnectionString("DefaultConnection");
// register dependency injection in infrastructure layer
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(connectionString,
opt
=> opt.EnableRetryOnFailure(
5,
TimeSpan.FromSeconds(30),
null)).UseSnakeCaseNamingConvention());
services.AddHealthChecks().AddDbContextCheck<AppDbContext>("/api/health");
services.AddScoped<IPasswordHash, PasswordHasher>();
services.AddScoped<ITokenService, TokenService>();
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IProductRepository, ProductRepository>();
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IEmailService, EmailService>();
services.AddScoped<IRestorePasswordService, RestorePasswordService>();
services.AddScoped<IUserRestorePasswordRepository, UserRestorePasswordRepository>();
services.AddKeyedScoped<ISocialAuthStrategy, GoogleAuthStrategy>("Google");
services.AddKeyedScoped<ISocialAuthStrategy, FacebookAuthStrategy>("Facebook");
services.AddScoped<IImageService, CloudinaryService>();
services.AddScoped<IProductVariantRepository, ProductVariantRepository>();
services.AddScoped<ICartItemRepository, CartItemRepository>();
services.AddHttpContextAccessor();
services.AddScoped<ICurrentUser, CurrentUser>();
services.AddScoped<IInvoiceRepository, InvoiceRepository>();
services.AddScoped<IInvoiceService, InvoiceService>();
services.AddScoped<IPaymentTransactionRepository, PaymentTransactionRepository>();
services.AddScoped<IPaymentRepository, PaymentRepository>();
services.AddScoped<IColorRepository, ColorRepository>();
services.AddScoped<ISizeRepository, SizeRepository>();
services.AddScoped<ICategoryRepository, CategoryRepository>();
services.AddScoped<IVoucherRepository, VoucherRepository>();
services.AddScoped<IVoucherService, VoucherService>();
return services;
}
}