相关文章推荐
博学的墨镜  ·  Errors prevented ...·  1 年前    · 
活泼的小熊猫  ·  Android studio ...·  1 年前    · 
聪明伶俐的芒果  ·  spring ...·  1 年前    · 
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 It might be that you haven't registered you mapping from IRepositoryTab to RepositoryTab
But most likely what you need is to specify interface instead of concrete parameter as your consturctor parameter
public EmployeeController(IRepositoryTab<employee> emp) this ._repository = emp;
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •