未处理的异常呈现组件:
不能为类型
Inventory_Management.Client.Pages.Authentication.Login
的属性_accountService
提供值。无Inventory_Management.Shared.Services.AccountService
类型的注册服务。
AccountService.cs
public interface IAccountService
{
Task<IResult> Login(Identity model);
}
public class AccountService : IAccountService
{
public async Task<IResult> Login(Identity model){}
}
login.razor
@inject IAccountService _accountService;
<div></div>
@code{
private async Task Submit()
{
var result = await _accountService.Login(userlogin); // Unhandled exception
}
}
遵循Github示例,它在启动类中没有任何作用域。https://github.com/iammukeshm/CleanArchitecture.WebApi。
引用
Client-> Pages-> Authentication-> Login.razor.cs
Infrastructure-> Identity-> Authentication->IAuthenticationManager
Server-> Extensions -> ServiceCollectionExtension.cs
startup.cs -> services.AddServerLocalization();
你需要在Startup类的ConfigureServices方法中注册你的具体类。
public void ConfigureServices(IServiceCollection services){
services.AddScoped<IAccountService, AccountService>();
}
您需要注册IAccountService
(在您试图遵循的示例中-参见ServiceExtensions.AddIdentityInfrastructure
并在Startup
类中调用它),例如;
services.AddScoped<IAccountService, AccountService>(); // also you should register all AccountService's dependencies
然后解析接口,而不是实现:
@inject IAccountService _accountService;
<div></div>
@code{
private async Task Submit()
{
var result = await _accountService.Login(userlogin); // Unhandled exception
}
}