Junaid Aslam
Junaid Aslam
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
It looked good to me but just need a second opinion from you.
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
Would you please take a look at their suggestion about refactoring the services to GeminiService?
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
I agree.
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
and the first answer says "GeminiAuthHandler can be omitted as you can use HttpClient.DefaultRequestHeaders either from the instance or from the factory."
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
ok.. what's ovetler ?
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
Where should this be done? Inside AddHttpClient(....) ??
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
So if the HttpClientHandler is not in DI and I am sending it to the ext method as Func<HttpClientHandler>, how's is that a bad thing?
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
Ok.. but to add anything to DI its instance is made, no?
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
like Func<HttpClientHandler>? proxyHandler=null param breaks DI?
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
bro this is the bit that can you explain more or direct me to some doc where I can read about it
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
they will just call AddGemini or call AddGemini(()=> {... handler});
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
The consumer is not adding HttpClient, it's the extension method, that's doing so
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
I did not understand bro
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
i think I am missing something.. you told me about using Builder and that I should check how its done in httpclient
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
actually someone wants to contribute to my repo and they sent me this.. the only use case they fixed here is httpClientHandler being injected and being optional
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
yeah..
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
What do you think about it?
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
@TeBeCo a small improvement: public static IServiceCollection AddGemini(this IServiceCollection services,Func<HttpClientHandler>? proxyHandler=null) { return RegisterCoreServices<GeminiClient>(services, proxyHandler); } public static IServiceCollection AddGemini<TGeminiClient>(this IServiceCollection services,Func<HttpClientHandler>? proxyHandler=null) where TGeminiClient : class, IGeminiClient { return RegisterCoreServices<TGeminiClient>(services, proxyHandler); } private static IServiceCollection RegisterCoreServices<TGeminiClient>(IServiceCollection services, Func<HttpClientHandler>? proxyHandler) where TGeminiClient : class, IGeminiClient { services.AddTransient<GeminiAuthHandler<GeminiHttpClientOptions>>(); var httpClientBuilder = services.AddHttpClient<IGeminiClient, TGeminiClient>((IServiceProvider serviceProvider, HttpClient client) => { var options = serviceProvider.GetRequiredService<IOptions<GeminiHttpClientOptions>>().Value; client.BaseAddress = options.Url; }); if (proxyHandler is not null) { httpClientBuilder.ConfigurePrimaryHttpMessageHandler(proxyHandler); } httpClientBuilder.AddHttpMessageHandler<GeminiAuthHandler<GeminiHttpClientOptions>>(); services.AddTransient<ITextService, TextService>(); services.AddTransient<IVisionService, VisionService>(); services.AddTransient<IChatService, ChatService>(); services.AddTransient<IEmbeddingService, EmbeddingService>(); services.AddTransient<IModelInfoService, ModelInfoService>(); return services; }
288 replies
CC#
Created by Junaid Aslam on 1/13/2024 in #help
Unable to configure values in DI using the extension method
thanks for your help so far
288 replies