-1

Eu estou recebendo a mensagem abaixo ao tentar compilar meu projeto. Eu comentei alguns código e cheguei a conlusão que estou implementando a classe de Contexto de dados de maneira erra pois se eu comento ela o erro para de ocorrer.

Segue abaixo o erro.

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(IEnumerable1 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

Segue abaixo a classe de contexto:

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());
    }
}

Segue abaixo a classe onde eu registro as dependencias

public static class People_IoC {
    public static IServiceCollection AddMapperPeople(this IServiceCollection conteiner) {

        // Person
        conteiner.AddTransient<IPersonQuery, PersonQuery>();

        return conteiner;
    }
}

Eu não estou comseguindo achar o problema. Desde já agradeço a disposição de vocês. Se precisanrem de mais alguma informação estou a disposição.

1 Resposta 1

0

acabei de achar o problema. Eu havia esquecido de registrar a minha classe de contexto com o AddDbContext.

Até mais, obrigado.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .