'Error while validating the service descriptor 'ServiceType'
I interject in the method but it showing exception here:
The code is extension of the services.
public static IServiceCollection AddServices(this IServiceCollection services, string ConnectionString)
{
services.AddRepository(ConnectionString);
services.AddTransient<INotificationService, NotificationService>();
services.AddTransient<ITherapistServices, TherapistServices>();
return services;
}
public class TherapistServices : ITherapistServices
{
private readonly IUnitOfWorkRepository _unitWork;
private readonly INotificationService _notificationService;
public TherapistServices(IUnitOfWorkRepository unitWork, NotificationService notificationService)
{
_unitWork = unitWork;
_notificationService = notificationService;
}
Here I wrote a method where the both of the injected items are called.
public async Task<ApproveTherapist> CreateAcceptRejectTherapist(ApproveTherapistCreateDto approveTherapist)
{
ApproveTherapist therapistApproveReject = _mapper.Map<ApproveTherapist>(approveTherapist);
therapistApproveReject.ApprovedAt = DateTime.UtcNow;
therapistApproveReject.AdminId = Convert.ToInt64(approveTherapist.AdminId);
await _unitWork.ApproveTherapistRepositoryUnit.Add(therapistApproveReject);
_unitWork.Complete();
//Push Notification coding
var approveEntity = _unitWork.UserRepositoryUnit.GetTherapistById(approveTherapist.TherapistId);
if(approveEntity !=null)
{
NotificationModel notificationModel = new NotificationModel();
notificationModel.DeviceId = approveEntity.DeviceIdToken;
if (approveTherapist.IsApproved == true)
{
notificationModel.Title = "Approve by Admin";
notificationModel.Body = "Hi Therapist your application is approved by admin";
}
else
{
notificationModel.Title = "Reject by Admin";
notificationModel.Body = "Hi Therapist your application is reject by admin";
}
await _notificationService.SendNotification(notificationModel);
}
//End Push notification coding
return therapistApproveReject;
}
}
}
In the code there is exception showing on the startup. I called the extension method on the startup page. I wrote the services on the above code and the interface called up in that file.
services.AddServices(Configuration.GetConnectionString("SMBHDBConnection"));
The exception is given below:
InnerException = {"Error while validating the service descriptor 'ServiceType: SMBH_SERVICES.RepositoryServices.Abstract.ITherapistServices Lifetime: Transient ImplementationType: SMBH_SERVICES.RepositoryServices.Concrete.TherapistServices': Unable to resolve service for ty...
Exception image:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|