public static IServiceCollection AddMongoDbContext(this IServiceCollection services, IConfiguration config) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } services.AddOptions(); var option = new MongoOption(config); services.Add(ServiceDescriptor.Singleton(new MongoDbContext(option))); SetConvention(); return(services); }
public MongoDbContext(MongoOption option) { var client = new MongoClient(option.ConnectionString); _db = client.GetDatabase(option.DatabaseName); }