public MongoDbContext(DistributedCacheMongoModuleConfiguration configuration) { _configuration = configuration; var url = MongoUrl.Create(configuration.ConnectionString); MongoClient = new MongoClient(url); Db = MongoClient?.GetDatabase(url.DatabaseName); }
/// <summary> /// Add MongoDB Distributed Cache /// </summary> public static IServiceCollection AddMongoDistributedCache(this IServiceCollection services, DistributedCacheMongoModuleConfiguration configuration) { BsonClassMap.RegisterClassMap(new CacheEntryMap()); return(services .AddSingleton(configuration) .AddSingleton <MongoDbContext>() .AddSingleton <IDistributedCache, MongoDbCache>()); }