Exemplo n.º 1
0
        protected override void OnHostBuilt(IHost host)
        {
            if (Debugger.IsAttached)
            {
                var configuration = new ConfigurationBuilder()
                                    .AddEnvironmentVariables()
                                    .Build();

                var connectionString = new ProductsConfigurationProvider(configuration).GetDatabaseConnectionString();

                var dbContext = new SampleDbContext(connectionString);

                dbContext.MigrateDatabase(connectionString);

                dbContext.Dispose();
            }
        }
Exemplo n.º 2
0
        protected override void ConfigureHealthChecks(IHealthChecksBuilder healthChecksBuilder)
        {
            healthChecksBuilder.AddAsyncCheck("SqlServer", async() =>
            {
                var connectionString = new ProductsConfigurationProvider(Configuration).GetDatabaseConnectionString();

                using (var connection = new SqlConnection(connectionString))
                {
                    try
                    {
                        await connection.OpenAsync();

                        return(HealthCheckResult.Healthy());
                    }
                    catch (SqlException)
                    {
                        return(HealthCheckResult.Unhealthy());
                    }
                }
            });
        }