You can’t use a service with a smaller lifetime. Scoped services only exist per-request, while singleton services are created once and the instance is shared.
Now only one instance of IActiveUsersService exists in the app. But it wants to depend on MongoDbContext, which is Scoped, and is created per-request.
You will have to either:
- Make
MongoDbContexta Singleton, or - Make
IActiveUsersServiceScoped, or - Pass
MongoDbContextinto the user service as a function argument