-1
I’m getting the message below while trying to compile my project. I commented some code and came to the conclusion that I am implementing the data context class in the wrong way because if I comment it the error stops occurring.
Follow below the error.
Unhandled Exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BLL.People.Person.Searches.Abstractions.IPersonQuery Lifetime: Transient ImplementationType: BLL.People.Person.Searches.Services.PersonQuery': Unable to resolve service for type 'DAL.People.Peopledbcontext' while attempting to Activate 'BLL.People.Person.Searches.Services.Personquery'.)
---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: BLL.People.Person.Searches.Abstractions.IPersonQuery Lifetime: Transient ImplementationType: BLL.People.Person.Searches.Services.PersonQuery': Unable to resolve service for type 'DAL.People.Peopledbcontext' while attempting to Activate 'BLL.People.Person.Searches.Services.Personquery'.
---> System.InvalidOperationException: Unable to resolve service for type 'DAL.People.PeopleDbContext' while attempting to activate 'BLL.People.Person.Searches.Services.PersonQuery'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain)
At Microsoft.Extensions.Dependencyinjection.ServiceLookup.Serviceproviderengine.Validateservice(Servicedescriptor Descriptor)
--- End of Inner Exception stack trace ---
At Microsoft.Extensions.Dependencyinjection.ServiceLookup.Serviceproviderengine.Validateservice(Servicedescriptor Descriptor)
At Microsoft.Extensions.Dependencyinjection.ServiceProvider.. ctor(Ienumerable1 serviceDescriptors, ServiceProviderOptions options) --- End of inner exception stack trace --- at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable
1 serviceDescriptors, Serviceprovideroptions options)
At Microsoft.Extensions.Dependencyinjection.ServiceCollectionContainerBuilderExtensions.Buildserviceprovider(Iservicecollection services, Serviceprovideroptions options)
At microsoft.Extensions.Dependencyinjection.DefaultServiceProviderFactory.Createserviceprovider(Iservicecollection containerBuilder)
At Microsoft.Extensions.Hosting.Internal.Servicefactoryadapter`1.Createserviceprovider(Object containerBuilder)
At Microsoft.Extensions.Hosting.HostBuilder.Createserviceprovider()
At Microsoft.Extensions.Hosting.HostBuilder.Build()
At Leiriaapi.Program.Main(String[] args) in D: Projects.netCore Leiriaapi Program.Cs:line 16
Below is the context class:
public class PeopleDbContext : DbContext {
// Constructor
public PeopleDbContext(DbContextOptions options) : base(options) {}
// Person
public DbSet<PersonEntity> Person { get; set; }
protected override void OnModelCreating(ModelBuilder builder) {
// Person
builder.ApplyConfiguration(new PersonConfiguration());
}
}
Below is the class where I register dependencies
public static class People_IoC {
public static IServiceCollection AddMapperPeople(this IServiceCollection conteiner) {
// Person
conteiner.AddTransient<IPersonQuery, PersonQuery>();
return conteiner;
}
}
I’m not finding the problem. Thanks for your time. If you need more information I am available.