private static void DoAdd(IServiceCollection services, SqlServerServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
        {
            var sqlServerConfig = new SqlServerProviderConnectorOptions(config);
            var factory         = new SqlServerProviderConnectorFactory(info, sqlServerConfig, SqlServerTypeLocator.SqlConnection);

            services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalHealthContributor> >()), contextLifetime));
        }
        private static void DoAdd(IServiceCollection services, SqlServerServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks)
        {
            Type sqlServerConnection = SqlServerTypeLocator.SqlConnection;
            var  sqlServerConfig     = new SqlServerProviderConnectorOptions(config);
            var  factory             = new SqlServerProviderConnectorFactory(info, sqlServerConfig, sqlServerConnection);

            services.Add(new ServiceDescriptor(typeof(IDbConnection), factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(sqlServerConnection, factory.Create, contextLifetime));
            if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalHealthContributor> >()), ServiceLifetime.Singleton));
            }
        }
Esempio n. 3
0
        private static void DoAdd(IServiceCollection services, SqlServerServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, IHealthChecksBuilder healthChecksBuilder)
        {
            Type sqlServerConnection = SqlServerTypeLocator.SqlConnection;
            var  sqlServerConfig     = new SqlServerProviderConnectorOptions(config);
            var  factory             = new SqlServerProviderConnectorFactory(info, sqlServerConfig, sqlServerConnection);

            services.Add(new ServiceDescriptor(typeof(IDbConnection), factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(sqlServerConnection, factory.Create, contextLifetime));
            if (healthChecksBuilder == null)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalHealthContributor> >()), ServiceLifetime.Singleton));
            }
            else
            {
                healthChecksBuilder.AddSqlServer(factory.CreateConnectionString());
            }
        }