I am getting this error can anyone help me ?
Inner Exception 1:
InvalidOperationException: Error while validating the service descriptor 'ServiceType: LServices.Interfaces.IUpdater Lifetime: Scoped ImplementationType: LServices.IUpdater ': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'LServices.Repositories.Base.Repository`1[LServices.Entities.Students]'.
Inner Exception 2:
InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'LServices.Repositories.Base.Repository`1[LServices.Entities.Students]]'.
I have my files as below :
Startup.cs
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddDbContext(item =>
- item.UseSqlServer(Configuration.GetConnectionString("DBConnection")));
- services.AddTransient();
- services.AddTransient(typeof(IRepository<>), typeof(Repository<>));
- services.AddTransient(typeof(IGenericRepository<,>), typeof(GeneralRepository<,>));
- }
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
-
- var appl2 = app.ApplicationServices.GetService();
- appl2.GetFloorsDataInDb();
- app.UseRouting();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapGet("/", async context =>
- {
- await context.Response.WriteAsync("Hello World!");
- });
- });
- }
Context class :
- public class LServiceContext : DbContext
- {
- public LServiceContext (DbContextOptions options) : base(options)
- {
- }
- public DbSet<Student> Student{ get; set; }
- }
The class which I want to class in startup.cs
- namespace LServiceJob
- {
- public classUpdater : IUpdater
- {
- private IRepository studentsRepository;
- public FloorsInfoUpdater(IRepository studentRepository)
- {
- this.studentRepository= studentRepository;
- }
- public List GetFloorsDataInDb()
- {
- List groupedFloors = this.studentRepository.GetAll().ToList();
- return groupedstuents;
- }
- }
- }