© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
16 replies
TheBrambleShark

ServiceProvider not providing registered service [Answered]

For some reason, despite registering this api wrapper as so:
services.TryAddScoped<IInContactRestAPI>
(
    serviceProvider => new InContactRestAPI
    (
        serviceProvider.GetRequiredService<IRestHttpClient>(),
        serviceProvider.GetRequiredService<IOptionsMonitor<JsonSerializerOptions>>().Get(InContact),
        serviceProvider.GetRequiredService<IOptions<InContactConfig>>(),
        serviceProvider.GetRequiredService<ITokenStore>()
    )
);
services.TryAddScoped<IInContactRestAPI>
(
    serviceProvider => new InContactRestAPI
    (
        serviceProvider.GetRequiredService<IRestHttpClient>(),
        serviceProvider.GetRequiredService<IOptionsMonitor<JsonSerializerOptions>>().Get(InContact),
        serviceProvider.GetRequiredService<IOptions<InContactConfig>>(),
        serviceProvider.GetRequiredService<ITokenStore>()
    )
);

Attempting to retrieve it from the service provider results in an InvalidOperationException because the type is not in the service provider. This happens whether I request the interface or the concrete implementation. Rider does in fact confirm that the scoped rest api wrapper is present in the service collection when stepping through.
unknown.png
unknown.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

AboutView not registered?
C#CC# / help
11mo ago
✅ Problems with mocking a ServiceProvider
C#CC# / help
3y ago