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
MongoDbContext
a Singleton, or - Make
IActiveUsersService
Scoped, or - Pass
MongoDbContext
into the user service as a function argument