TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naruto Reddy
NA
123
39.3k
Error: "Some services are not able to be constructed"
Jun 15 2020 3:03 AM
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 appl = app.ApplicationServices.GetServices();
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;
}
}
}
Reply
Answers (
2
)
Calculate Nearest Site Latitude and Longitude
Need best simple way to save pdf to database from win form