Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public MongoDbContext(MongoOption option)
        {
            var client = new MongoClient(option.ConnectionString);

            _db = client.GetDatabase(option.DatabaseName);
        }