Example #1
0
        public static IHealthContributor GetMongoDbHealthContributor(IConfiguration configuration, ILogger <MongoDbHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Type mongoDbImplementationType = MongoDbTypeLocator.MongoClient;
            var  info = configuration.GetSingletonServiceInfo <MongoDbServiceInfo>();

            MongoDbConnectorOptions rabbitMQConfig = new MongoDbConnectorOptions(configuration);
            MongoDbConnectorFactory factory        = new MongoDbConnectorFactory(info, rabbitMQConfig, mongoDbImplementationType);

            return(new MongoDbHealthContributor(factory, logger));
        }
        private static void DoAdd(IServiceCollection services, MongoDbServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
        {
            Type mongoClient   = MongoDbTypeLocator.MongoClient;
            var  mongoOptions  = new MongoDbConnectorOptions(config);
            var  clientFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoClient);

            services.Add(new ServiceDescriptor(MongoDbTypeLocator.IMongoClient, clientFactory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(mongoClient, clientFactory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new MongoDbHealthContributor(clientFactory, ctx.GetService <ILogger <MongoDbHealthContributor> >()), ServiceLifetime.Singleton));

            Type mongoInfo  = ConnectorHelpers.FindType(MongoDbTypeLocator.Assemblies, MongoDbTypeLocator.MongoConnectionInfo);
            var  urlFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoInfo);

            services.Add(new ServiceDescriptor(mongoInfo, urlFactory.Create, contextLifetime));
        }
        private static void DoAdd(IServiceCollection services, MongoDbServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
        {
            Type mongoClient   = MongoDbTypeLocator.MongoClient;
            var  mongoOptions  = new MongoDbConnectorOptions(config);
            var  clientFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoClient);

            services.Add(new ServiceDescriptor(MongoDbTypeLocator.IMongoClient, clientFactory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(mongoClient, clientFactory.Create, contextLifetime));

            Type mongoInfo  = ConnectorHelpers.FindType(MongoDbTypeLocator.Assemblies, MongoDbTypeLocator.MongoConnectionInfo);
            var  urlFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoInfo);

            services.Add(new ServiceDescriptor(mongoInfo, urlFactory.Create, contextLifetime));

            // TODO: add health check
        }
        private static void DoAdd(IServiceCollection services, MongoDbServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks = false)
        {
            var mongoClient   = MongoDbTypeLocator.MongoClient;
            var mongoOptions  = new MongoDbConnectorOptions(config);
            var clientFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoClient);

            services.Add(new ServiceDescriptor(MongoDbTypeLocator.IMongoClient, clientFactory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(mongoClient, clientFactory.Create, contextLifetime));
            if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new MongoDbHealthContributor(clientFactory, ctx.GetService <ILogger <MongoDbHealthContributor> >()), ServiceLifetime.Singleton));
            }

            var mongoInfo  = ReflectionHelpers.FindType(MongoDbTypeLocator.Assemblies, MongoDbTypeLocator.MongoConnectionInfo);
            var urlFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoInfo);

            services.Add(new ServiceDescriptor(mongoInfo, urlFactory.Create, contextLifetime));
        }
Example #5
0
 public MongoDbHealthContributor(MongoDbConnectorFactory factory, ILogger <MongoDbHealthContributor> logger = null)
 {
     _logger      = logger;
     _mongoClient = factory.Create(null);
 }