I try add
using SciEn.Repo.Contracts;
using SciEn.Repo.IRepository;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddSingleton<ISubDepartmentRepository, SubDepartmentRepository>();
var app = builder.Build();
I got this error
'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: SciEn.Repo.Contracts.ISubDepartmentRepository Lifetime: Scoped ImplementationType: SciEn.Repo.IRepository.SubDepartmentRepository': Unable to resolve service for type 'SciEn.Models.ScinceContext' while attempting to activate 'SciEn.Repo.IRepository.SubDepartmentRepository'.)'
I try remove
builder.Services.AddScoped<ISubDepartmentRepository, SubDepartmentRepository>();
but get error
InvalidOperationException: Unable to resolve service for type "" while attempting to activate
This error is telling you that when it tried to create the
SubDepartmentRepositoryclass it couldn't find theScinceContextthat needs to be injected into it's constructor.You need to ensure you have registered the
SciEn.Models.ScinceContextclass. Is this an Entity Framework DB Context? Make sure you've registered the DB Context...builder.Services.AddDbContext<SciEn.models.ScinceContext>(...);