C# Dependency Injection - how to to Resolve Scoped Service in Singleton
I'm stuck on something that should probably be simple. I've searched everywhere and can't find a clear answer. I'm working with an scenario with dependency injection in my ASP.NET Core application. I'm trying to inject a scoped service into a singleton service, but I'm getting the following behavior when the application starts: ``` Unable to resolve service for type 'MyApp.Services.IScopedService' while attempting to activate 'MyApp.Services.SingletonService'. ``` My `Startup.cs` configuration looks like this: ```csharp public void ConfigureServices(IServiceCollection services) { services.AddScoped<IScopedService, ScopedService>(); services.AddSingleton<SingletonService>(); } ``` In the `SingletonService`, I'm trying to use the scoped service as follows: ```csharp public class SingletonService { private readonly IScopedService _scopedService; public SingletonService(IScopedService scopedService) { _scopedService = scopedService; } } ``` From what I understand, a singleton service is created once and lasts for the lifetime of the application. However, the scoped service is created per request, which is causing this scenario. I tried restructuring my code by either making both services singleton or creating the scoped service directly within a method of the singleton, but that feels like a workaround rather than a solution. What is the best practice to handle this situation? How can I properly use a scoped service within a singleton service without running into this scenario? Any advice would be greatly appreciated! Thanks in advance! This is part of a larger application I'm building. Any ideas what could be causing this?