I upgraded the project to ASP.NET Core 2 today and I received the following error:
Cannot use the restricted IMongoDbContext service from singleton IActiveUsersService
I have the following registration:
services.AddSingleton<IActiveUsersService, ActiveUsersService>(); services.AddScoped<IMongoDbContext, MongoDbContext>(); services.AddSingleton(option => { var client = new MongoClient(MongoConnectionString.Settings); return client.GetDatabase(MongoConnectionString.Database); }) public class MongoDbContext : IMongoDbContext { private readonly IMongoDatabase _database; public MongoDbContext(IMongoDatabase database) { _database = database; } public IMongoCollection<T> GetCollection<T>() where T : Entity, new() { return _database.GetCollection<T>(new T().CollectionName); } } public class IActiveUsersService: ActiveUsersService { public IActiveUsersService(IMongoDbContext mongoDbContext) { ... } }
Why can't DI use this service? Everything works fine for ASP.NET Core 1.1.
c # asp.net-core
user348173
source share