I have a gRPC and API controller projects in one solution.
When I want to register a service in both projects got this error:
'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: SmsPanel.SendServiceCore.Interfaces.ICreditService Lifetime: Scoped ImplementationType: SmsPanel.SendServiceCore.Services.CreditService': Unable to resolve service for type 'SmsPanel.SendServiceCore.Interfaces.ICoreService' while attempting to activate 'SmsPanel.SendServiceCore.Services.CreditService'.)'
This is my API program.cs:
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<ISmsPanelContext, SmsPanelContext>();
builder.Services.AddScoped<IUserRepository, EFUserRepository>();
builder.Services.AddScoped<ISmsInOutBoxService, SmsInOutBoxService>();
builder.Services.AddScoped<ISettingRepository, EFSettingRepository>();
builder.Services.AddScoped<ITransactionRepository, EFTransactionRepository>();
builder.Services.AddScoped<ISMSInOutBoxDetailRepository, EFSMSInOutBoxDetailRepository>();
builder.Services.AddScoped<ISmsInOutBoxRepository, EFSMSInOutBoxRepository>();
builder.Services.AddScoped<ICorrespondingSendRepository, EFCorrespondingSendRepository>();
builder.Services.AddScoped<IUserLineRepository, EFUserLineRepository>();
builder.Services.AddScoped<ISMSLineRepository, EFSMSLineRepository>();
builder.Services.AddScoped<ITemplateRepository, EFTemplateRepository>();
builder.Services.AddScoped<ISMSRouteRepository, EFSMSRouteRepository>();
builder.Services.AddScoped<ITariffPriceRepository, EFTariffPriceRepository>();
builder.Services.AddScoped<ICoreService, CoreService>();
builder.Services.AddScoped<ICreditService, CreditService>();
builder.Services.AddScoped<IDeliveryService, DeliveryService>();
builder.Services.AddScoped<IMessageService, MessageService>();
builder.Services.AddScoped<INumbersService, NumbersService>();
builder.Services.AddScoped<ISendSmsService, SendSmsService>();
builder.Services.AddScoped<ISMSInvalidWordRepository, EFSMSInvalidWordRepository>();
builder.Services.AddScoped<ISpecialListRepository, EFSpecialListRepository>();
builder.Services.AddScoped<IIntelligentSendRepository, EFIntelligentSendRepository>();
This is my gRPC program.cs:
builder.Services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
options.Interceptors.Add<ExceptionInterceptor>();
});
builder.Services.AddGrpcReflection(); // Grpc.AspNetCore.Server.Reflection
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<ICreditService, CreditService>();
I got it, I should register other services in gRPC too.