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)); }