public static void ConfigureBpHealthChecksServices(this IServiceCollection services, IConfiguration configuration) { IHealthChecksBuilder healthChecks = services.AddHealthChecks(); string sqlConfig = configuration["Data:SqlServer:ConnectionString"]; if (sqlConfig != null) { healthChecks.AddSqlServer(sqlConfig, name: "sql-server-health", tags: new[] { HealthCheckTag.DATA }); } string mongoConfig = configuration["Data:MongoDB:ConnectionString"]; if (mongoConfig != null) { healthChecks.AddMongoDb(mongoConfig, name: "mongodb-health", tags: new[] { HealthCheckTag.DATA }); } // If server have https, the http endpoint will redirect to the https it and the health check will fail of the redirect if (configuration["Kestrel:EndPoints:Https:Url"] == null && configuration["Kestrel:EndPoints:Http:Url"] != null) { var serviceBaseUrl = Environment.GetEnvironmentVariable("RUNNING_SERVICE_URL") ?? configuration["Kestrel:EndPoints:Http:Url"]; healthChecks.AddUrlGroup( new Uri( $"{serviceBaseUrl.Replace("*", "localhost")}/api/swagger/{configuration["Service:Version"]}/swagger.json"), name: "Get swagger.json", tags: new[] { HealthCheckTag.SANITY }); } }
public static IHealthChecksBuilder AddDependencies( this IHealthChecksBuilder builder, List <Dependency> dependencies) { foreach (var dependencia in dependencies) { string nomeDependencia = dependencia.Name.ToLower(); if (nomeDependencia.StartsWith("sqlserver-")) { builder = builder.AddSqlServer(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("mongodb-")) { builder = builder.AddMongoDb(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("redis-")) { builder = builder.AddRedis(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("postgres-")) { builder = builder.AddNpgSql(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("mysql-")) { builder = builder.AddMySql(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("url-")) { builder = builder.AddUrlGroup(new Uri(dependencia.Url), name: dependencia.Name); } else if (nomeDependencia.StartsWith("rabbitmq-")) { builder = builder.AddRabbitMQ(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("azureservicebusqueue-")) { builder = builder.AddAzureServiceBusQueue(dependencia.ConnectionString, queueName: dependencia.QueueName, name: dependencia.Name); } else if (nomeDependencia.StartsWith("azureblobstorage-")) { builder = builder.AddAzureBlobStorage(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("documentdb-")) { builder = builder.AddDocumentDb( docdb => { docdb.UriEndpoint = dependencia.UriEndpoint; docdb.PrimaryKey = dependencia.PrimaryKey; }); } } return(builder); }
public static IHealthChecksBuilder AddMongoDbHealthCheck( this IHealthChecksBuilder builder, IConfiguration configuration ) { var connectionString = GetConnectionString(configuration); builder.AddMongoDb( connectionString, timeout: TimeSpan.FromSeconds(5) ); return(builder); }
/// <summary> /// Add and use a Mongo database /// </summary> /// <param name="services">The services collection</param> /// <param name="databaseOptions">The database configuration options</param> /// <param name="healthCheckBuilder">An instance of the health check builder</param> /// <param name="healthCheckTag">The tag to register the MongoDb health check against</param> public static void AddMongoDataAccessLayer(this IServiceCollection services, IDatabaseOptions databaseOptions, IHealthChecksBuilder healthCheckBuilder = null, string healthCheckTag = null) { _ = databaseOptions ?? throw new ArgumentNullException(nameof(databaseOptions)); services.AddScoped(typeof(IDatabaseIntegrator <>), typeof(MongoCollectionIntegrator <>)); if (healthCheckBuilder != null) { healthCheckBuilder.AddMongoDb(databaseOptions.ConnectionString, databaseOptions.DatabaseName, null, new[] { healthCheckTag }); } services.AddDataAccessLayer(); }
public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection services, IConfiguration configuration, IHealthChecksBuilder healthChecksBuilder) { services.Configure <MongoDbOptions>(configuration.GetSection(nameof(MongoDbOptions))); var mongoDbOptions = new MongoDbOptions(); configuration.Bind(nameof(MongoDbOptions), mongoDbOptions); healthChecksBuilder.AddMongoDb(mongoDbOptions.ConnectionString, mongoDbOptions.Database, null, null, null, TimeSpan.FromSeconds(2)); services.AddSingleton <DbContextFactory>(); services.AddScoped <IUnitOfWork, MongoDbUnitOfWork>(); services.AddSingleton <IReader, MongoDbReader>(); services.AddSingleton <IIndexCreator, IndexCreator>(); return(services); }
private static void DoAdd(IServiceCollection services, MongoDbServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, IHealthChecksBuilder healthChecksBuilder) { 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)); if (healthChecksBuilder == null) { services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new MongoDbHealthContributor(clientFactory, ctx.GetService <ILogger <MongoDbHealthContributor> >()), ServiceLifetime.Singleton)); } else { healthChecksBuilder.AddMongoDb(clientFactory.CreateConnectionString()); } Type mongoInfo = ConnectorHelpers.FindType(MongoDbTypeLocator.Assemblies, MongoDbTypeLocator.MongoConnectionInfo); var urlFactory = new MongoDbConnectorFactory(info, mongoOptions, mongoInfo); services.Add(new ServiceDescriptor(mongoInfo, urlFactory.Create, contextLifetime)); }
public static IHealthChecksBuilder AddNetCleanMongoContextCheck(this IHealthChecksBuilder builder, string connectionString) { builder.AddMongoDb(connectionString); return builder; }