1
+ using CheckDrive . Domain . Interfaces ;
1
2
using CheckDrive . Application . Interfaces ;
2
- using CheckDrive . Domain . Interfaces ;
3
3
using CheckDrive . Infrastructure . Configurations ;
4
4
using CheckDrive . Infrastructure . Email ;
5
5
using CheckDrive . Infrastructure . Persistence ;
9
9
using Microsoft . EntityFrameworkCore ;
10
10
using Microsoft . Extensions . Configuration ;
11
11
using Microsoft . Extensions . DependencyInjection ;
12
+ using CheckDrive . Application . Interfaces . Authorization ;
13
+ using CheckDrive . Infrastructure . Helpers ;
12
14
13
15
namespace CheckDrive . Infrastructure . Extensions ;
14
16
@@ -20,6 +22,7 @@ public static IServiceCollection RegisterInfrastructure(this IServiceCollection
20
22
AddConfigurations ( services , configuration ) ;
21
23
AddFluentEmail ( services , configuration ) ;
22
24
AddServices ( services ) ;
25
+ AddIdentity ( services ) ;
23
26
24
27
return services ;
25
28
}
@@ -28,10 +31,6 @@ private static void AddPersistence(IServiceCollection services, IConfiguration c
28
31
{
29
32
services . AddDbContext < ICheckDriveDbContext , CheckDriveDbContext > ( options =>
30
33
options . UseSqlServer ( configuration . GetConnectionString ( "DefaultConnection" ) ) ) ;
31
-
32
- services . AddIdentity < IdentityUser , IdentityRole > ( )
33
- . AddEntityFrameworkStores < CheckDriveDbContext > ( )
34
- . AddDefaultTokenProviders ( ) ;
35
34
}
36
35
37
36
private static void AddConfigurations ( IServiceCollection services , IConfiguration configuration )
@@ -50,6 +49,11 @@ private static void AddConfigurations(IServiceCollection services, IConfiguratio
50
49
. Bind ( configuration . GetSection ( SmsConfigurations . SectionName ) )
51
50
. ValidateDataAnnotations ( )
52
51
. ValidateOnStart ( ) ;
52
+
53
+ services . AddOptions < JwtOptions > ( )
54
+ . Bind ( configuration . GetSection ( JwtOptions . SectionName ) )
55
+ . ValidateDataAnnotations ( )
56
+ . ValidateOnStart ( ) ;
53
57
}
54
58
55
59
private static void AddFluentEmail ( IServiceCollection services , IConfiguration configuration )
@@ -82,5 +86,25 @@ private static void AddServices(IServiceCollection services)
82
86
{
83
87
services . AddScoped < IEmailService , EmailService > ( ) ;
84
88
services . AddScoped < ISmsService , SmsService > ( ) ;
89
+ services . AddSingleton < IJwtTokenGenerator , JwtTokenGenerator > ( ) ;
90
+ }
91
+
92
+ private static void AddIdentity ( IServiceCollection services )
93
+ {
94
+ services . AddIdentity < IdentityUser , IdentityRole > ( options =>
95
+ {
96
+ options . Password . RequiredLength = 7 ;
97
+ options . Password . RequireUppercase = false ;
98
+ options . Password . RequireLowercase = false ;
99
+ options . Password . RequireNonAlphanumeric = false ;
100
+ options . Password . RequireDigit = false ;
101
+ } )
102
+ . AddEntityFrameworkStores < CheckDriveDbContext > ( )
103
+ . AddDefaultTokenProviders ( ) ;
104
+
105
+ services . Configure < DataProtectionTokenProviderOptions > ( options =>
106
+ {
107
+ options . TokenLifespan = TimeSpan . FromHours ( 12 ) ;
108
+ } ) ;
85
109
}
86
110
}
0 commit comments