@@ -129,7 +129,8 @@ public async Task<IReadOnlyList<long>> VotedOfVideos(List<long> videoIds)
129129 /// <summary> Scan voted videos, which means paging through all voted videos. </summary>
130130 public async Task < ( long ? , IReadOnlyList < long > ) > VotedVideos ( long page , int size )
131131 {
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 ) ;
133134 if ( ! string . IsNullOrEmpty ( Token ) && AuthenticationHeaderValue . TryParse ( Token , out var auth ) )
134135 {
135136 req . Headers . Authorization = auth ;
@@ -212,8 +213,8 @@ public static string GetConnString(this IServiceProvider sp, string name)
212213 => sp . GetRequiredService < IConfiguration > ( ) . ConnString ( name ) ;
213214
214215 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 ;
217218
218219 public static IServiceCollection AddSearchClient ( this IServiceCollection services ) => services
219220 . 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
225226 client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
226227 } ) . Services ;
227228
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 ;
231232
232233 public static IApplicationBuilder UseToken ( this IApplicationBuilder app ) =>
233234 app . Use ( async ( context , next ) =>
0 commit comments