0

so I am having some DI issues which I do not understand. I saw a few posts similar and I tried what they recommended but I have not had any luck. Here is the error I am getting

"Unable to resolve service for type 'IRetrieveService' while attempting to activate 'UpdateService'

Here is how I have my update service setup

private readonly IAsyncPolicy<SaveDocumentsResult> _processDocumentUpdatesPolicy;
private readonly IRetrieveService _retrieveService;
private readonly ISaveService _saveService;

public UpdateService(
    IAsyncPolicy<SaveDocumentsResult> processDocumentUpdatesPolicy,
    IRetrieveService retrieveService,
    ISaveService saveService)
{
    _processDocumentUpdatesPolicy = processDocumentUpdatesPolicy ?? throw new ArgumentNullException(nameof(processDocumentUpdatesPolicy));
    _retrieveService = retrieveService ?? throw new ArgumentNullException(nameof(retrieveService));
    _saveService = saveService ?? throw new ArgumentNullException(nameof(saveService));
}

Finally, I have this where I have added my services

Services.AddScoped<IRetrieveService, RetrieveService>();
Services.AddScoped<ISaveService, SaveService>();
Kit
  • 20,354
  • 4
  • 60
  • 103
  • Can you show how you have registered `UpdateService` in DI? Can you show the definition of `RetrieveService` (at least the constructor), _and any dependencies it has_? Can you post the full stack-trace? – RB. Jul 26 '21 at 15:54
  • This registration looks ok. It's the RegistrationService class that possibly is missing some of its dependencies – Wiktor Zychla Jul 26 '21 at 15:57
  • Try adding the services as singletons (temporarily) to see if that helps. Maybe that will lead you to a better solution. – Kit Jul 26 '21 at 16:08
  • 4
    Also, and I know this seems obvious, but are the `AddScoped` calls actually being made? – Kit Jul 26 '21 at 16:11
  • Can you post the relates code about IRetrieveService and the RetrieveService? Besides, about the UpdateService Constructor method, have you ever registered the UpdateService class? – Zhi Lv Jul 27 '21 at 05:33
  • Put a breakpoint on the line `Services.AddScoped()` and see if it's actually being hit. If so, double check whether the the registration is made on a `Services` instance that is *later on* used to build the `IServiceProvider`. – Steven Jul 27 '21 at 11:43

1 Answers1

0

Nothing in your code suggest any issues regarding the IRetreiverService and implementation. I believe there must be at problem with your service setup.

Try have a look at the following link. It describes the different usages.

AddTransient, AddScoped and AddSingleton Services Differences