Пример #1
0
        public MongoClientService(MongoSettingsProvider settings)
        {
            _settings = settings;

            try
            {
                BsonSerializer.RegisterSerializer(new GuidSerializer(BsonType.String));

                _client = new MongoClient(_settings.ConnectionString);

                _database = _client.GetDatabase(_settings.DatabaseName);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Exception thrown calling Constructor MongoClientService(): {exception.Message}");
            }
        }
 public static IServiceCollection AddMongoServiceClient(this IServiceCollection services, MongoSettingsProvider settings)
 {
     return(services.AddSingleton(new MongoClientService(settings)));
 }