某些服务无法使用Blazor Server构建
我有 class CustomersService:icustomersService
带有contractor:
public CustomersService(HttpClient http)
{
this._http = http;
}
in program.cs file :
builder.Services.AddScoped<ICustomersService, CustomersService>();
我应该如何重新启动/重置构造函数?
Builder.Services.AddScoped&lt; icustomersService,customersService&gt;(); 错误是:
invalidoperationException:无法解析type'system.net.http.httpclient'
i have class CustomersService : ICustomersService
with constractor:
public CustomersService(HttpClient http)
{
this._http = http;
}
and in program.cs file:
builder.Services.AddScoped<ICustomersService, CustomersService>();
How should I reboot/reset the constructor?
builder.Services.AddScoped<ICustomersService, CustomersService>();
the error is:
InvalidOperationException: Unable to resolve service for type 'System.Net.Http.HttpClient'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜想您在Blazor Server中,因为
httpclient
在Web Assembly中默认注册。这是我在服务器中进行操作的方式:
I'm guessing you're in Blazor Server as the
HttpClient
is registered by default in Web Assembly.Here's how I do it in Server: