如何在类库中使用ihttpclientFactory
我正在尝试将一些代码从Net Core API转换为类库。
我被卡住了如何使用httpclientFactory。 通常,可以在program.cs或启动中配置httpclientfactory,例如
services.AddHttpClient("abc", xxx config).
如何在类库中为httpclientFactory进行配置。
I am trying to convert some code from net core api to class library.
I am stuck how to use HttpClientfactory.
Normally the httpclientfactory can be configured in program.cs or Startup like
services.AddHttpClient("abc", xxx config).
How to do configurations in class library for Httpclientfactory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以按以下尝试尝试:
您可以通过接口获得HTTPClinetFactory的实例
You could try as below:
you could get the instance of httpclinetfactory through the interface
在您的库中,添加了
iservCollection
的扩展方法,以在主项目中“启用”它。在库中:
然后在您的
启动
中只需调用它:更新:如作者所述,他正在基于插件的应用程序。例如,在这种情况下,您需要某种惯例:
registration
使用公共静态方法Invoke(IserviceCollection SC,iconFiguration config)
启动
中,您可以通过所有插件库迭代其registration.invoke(sc,config)
使用反射:In your library add an extension method for
IServiceCollection
to "enable" it in the main project.In the library:
Then in your
Startup
just call it:UPDATE: As the author described, he's working on the plugin based application. In that case you need some kind of convention, for instance:
Registration
with public static methodInvoke(IServiceCollection sc, IConfiguration config)
Startup
you can iterate through all plugin libraries and call theirRegistration.Invoke(sc, config)
using reflection: