0

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)
    { }

}

1 Answer 1

4

Looks like you didn't register the SMSSender (you did the service):

services.AddTransient<ISMSService, SMSService>();
services.AddTransient<ISMSSender, SMSSender>();
Sign up to request clarification or add additional context in comments.

3 Comments

Do I have to ? It comes from another project?
Yes, absolutely
You are building your DI container in this stage. You are telling it which services implement each interface. Without this, there is no way to know which service to resolve based on the interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.