@@ -129,7 +129,8 @@ public async Task<IReadOnlyList<long>> VotedOfVideos(List<long> videoIds)
129
129
/// <summary> Scan voted videos, which means paging through all voted videos. </summary>
130
130
public async Task < ( long ? , IReadOnlyList < long > ) > VotedVideos ( long page , int size )
131
131
{
132
- using var req = new HttpRequestMessage ( HttpMethod . Get , $ "/graph/videos?page={ page } &size={ size } ") ;
132
+ var url = $ "/graph/videos?page={ page } &size={ size } ";
133
+ using var req = new HttpRequestMessage ( HttpMethod . Get , url ) ;
133
134
if ( ! string . IsNullOrEmpty ( Token ) && AuthenticationHeaderValue . TryParse ( Token , out var auth ) )
134
135
{
135
136
req . Headers . Authorization = auth ;
@@ -212,8 +213,8 @@ public static string GetConnString(this IServiceProvider sp, string name)
212
213
=> sp . GetRequiredService < IConfiguration > ( ) . ConnString ( name ) ;
213
214
214
215
public static IServiceCollection AddVoteRepository ( this IServiceCollection services ) => services
215
- . AddHttpClient < IVoteRepository , VoteRepository > ( "Vote" ,
216
- ( sp , client ) => client . BaseAddress = new Uri ( sp . GetConnString ( "Vote" ) ) ) . Services ;
216
+ . AddScoped < IVoteRepository , VoteRepository > ( sp => new VoteRepository ( sp . GetRequiredService < IHttpClientFactory > ( ) . CreateClient ( "Vote" ) ) )
217
+ . AddHttpClient ( "Vote" , ( sp , client ) => client . BaseAddress = new Uri ( sp . GetConnString ( "Vote" ) ) ) . AddAsKeyed ( ServiceLifetime . Scoped ) . Services ;
217
218
218
219
public static IServiceCollection AddSearchClient ( this IServiceCollection services ) => services
219
220
. AddSingleton < IConnectionMultiplexer > ( sp => ConnectionMultiplexer . Connect ( sp . GetRequiredService < IConfiguration > ( ) . GetConnectionString ( "Redis" ) . EnsureNotNull ( "Redis connection string is null" ) ) )
@@ -225,9 +226,9 @@ public static IServiceCollection AddSearchClient(this IServiceCollection service
225
226
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
226
227
} ) . Services ;
227
228
228
- public static IServiceCollection AddUserRepository ( this IServiceCollection services ) =>
229
- services . AddHttpClient < IUserRepository , UserRepository > ( "User" ,
230
- ( sp , client ) => client . BaseAddress = new Uri ( sp . GetConnString ( "User" ) ) ) . Services ;
229
+ public static IServiceCollection AddUserRepository ( this IServiceCollection services ) => services .
230
+ AddScoped < IUserRepository , UserRepository > ( sp => new UserRepository ( sp . GetRequiredService < IHttpClientFactory > ( ) . CreateClient ( "User" ) ) ) .
231
+ AddHttpClient ( "User" , ( sp , client ) => client . BaseAddress = new Uri ( sp . GetConnString ( "User" ) ) ) . Services ;
231
232
232
233
public static IApplicationBuilder UseToken ( this IApplicationBuilder app ) =>
233
234
app . Use ( async ( context , next ) =>
0 commit comments