Ошибка не может разрешить сервис типа почему и как ее решить ?
An unhandled exception occurred while processing the request. <div class="titleerror">InvalidOperationException: Unable to resolve service for type 'TabDataAccess.Repositories.RepositoryTab`1[TabDataAccess.Dto.Employee]' while attempting to activate 'WebTabCore.Controllers.EmployeeController'.</div> Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired) <div id="stackpage" class="page"> InvalidOperationException: Unable to resolve service for type 'TabDataAccess.Repositories.RepositoryTab`1[TabDataAccess.Dto.Employee]' while attempting to activate 'WebTabCore.Controllers.EmployeeController'. what i do as following An unhandled exception occurred while processing the request. InvalidOperationException: Unable to resolve service for type 'TabDataAccess.Repositories.RepositoryTab`1[TabDataAccess.Dto.Employee]' while attempting to activate 'WebTabCore.Controllers.EmployeeController'. Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired) InvalidOperationException: Unable to resolve service for type 'TabDataAccess.Repositories.RepositoryTab`1[TabDataAccess.Dto.Employee]' while attempting to activate 'WebTabCore.Controllers.EmployeeController'. what i do as following what i do as below What I have tried: <pre>public class Employee { public int EmployeeId { get; set; } public int BranchCode { get; set; } public string EmployeeName { get; set; } public int EmployeeAge { get; set; } } Repository public class RepositoryTab<T> : IrepositoryTab<T> where T : class { protected TabDbContext db { get; set; } private DbSet<T> dbSet; public RepositoryTab(TabDbContext Tabdb) { db = Tabdb; dbSet = db.Set<T>(); } public IEnumerable<T> GetAll() { return dbSet.ToList(); } } public interface IrepositoryTab<T> where T : class { IEnumerable<T> GetAll(); } configureservices services.AddDbContext<TabDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); appsetting.json "ConnectionStrings": { "DefaultConnection": "Server=.\\SQL2014;Database=ErpWeb;uid=sa;pwd=abc123;ConnectRetryCount=0;" why this exceptioh happen
Bryian Tan
Что в конструкторе EmployeeController?
ahmed_sa
публичный класс EmployeeController : контроллер
{
private IrepositoryTab<employee> _repository = null;
public EmployeeController(RepositoryTab<employee> emp)
{
это._repository = Эми;
}
индекс общественного IActionResult ()
{
сотрудники ВАР = _repository.Способность();
обратный просмотр(сотрудники);
}
}