Reputation: 16851
I am getting the following exception. Why is it and how can I solve this?
In SMSService.cs
when I comment on the constructor it starts to work, but I will require to access ISMSSender
from it.
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Authentication.API.Repository.Interface.ISMSService Lifetime: Singleton ImplementationType: Authentication.API.Repository.SMSService': Unable to resolve service for type 'SMSSender.API.Repository.Interface.ISMSSender' while attempting to activate 'Authentication.API.Repository.SMSService'.)'
Authentication.API.Repository.SMSService
public class SMSService : ISMSService
{
private readonly ISMSSender _smsSender;
public SMSService(ISMSSender smsSender)
{
_smsSender = smsSender;
}
}
Startup ...
services.AddTransient<ISMSService, SMSService>();
...
SMSSender.API.Repository.Interface.ISMSSender
public interface ISMSSender
{
Task<SMSUser> SendSMS(SMSUser prospectiveUser);
}
SMSSender.API.Repository.Interface.SMSSender
public class SMSSender : ISMSSender
{
public async Task<SMSUser> SendSMS(SMSUser sMSUser)
{ }
}
Upvotes: 0
Views: 698
Reputation: 5109
Looks like you didn't register the SMSSender (you did the service):
services.AddTransient<ISMSService, SMSService>();
services.AddTransient<ISMSSender, SMSSender>();
Upvotes: 4