Hi,
We are developing an application in Asp.net mvc Core and EF Core.
We made multiple layers. Now Issue is that we need the dbcontext in MVC project so we added. but when we are creating a repository library and trying to use it. then it is throwing this exception:
An unhandled exception occurred while processing the request.
<div class="titleerror">InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'On.Store.Repository.Companies.CompanyRepository'.</div>---------------------------------- Repository Library ---------------------------------------
We are trying like this :
public class CompanyRepository : GenericRepository<Company>, /*IGenericRepository<Company>*/ ICompanyRepository { public CompanyRepository(DbContext dbContext) : base(dbContext) { } public async Task<IEnumerable<Company>> GetAllAsync() { return await base.GetAllAsync<Company>(); } } =================================== MVC Project Start Up .cs =========================================== services.AddDbContext<DBContext>(); services.AddScoped<ICompanyRepository, CompanyRepository>(); ===================== DBCOntext.cs in MVC Project ====================================================== public class DBContext : DbContext { private IConfigurationRoot _config; public DBContext(IConfigurationRoot config, DbContextOptions options):base(options) { _config = config; }