From 0800f6f1dfb899c028c804b6b8e0833e4b1f552d Mon Sep 17 00:00:00 2001 From: Robin Todd <54082711+rotodd@users.noreply.github.com> Date: Mon, 8 Jun 2020 10:10:09 -0700 Subject: [PATCH] Updates SchemaInitializer to enable SqlServerFhirModel initialization changes. (#44) --- .../Features/Schema/SchemaInitializer.cs | 17 +++++++++++------ .../SqlServerBaseRegistrationExtensions.cs | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Health.SqlServer/Features/Schema/SchemaInitializer.cs b/src/Microsoft.Health.SqlServer/Features/Schema/SchemaInitializer.cs index 5e176b81..fee0742d 100644 --- a/src/Microsoft.Health.SqlServer/Features/Schema/SchemaInitializer.cs +++ b/src/Microsoft.Health.SqlServer/Features/Schema/SchemaInitializer.cs @@ -22,6 +22,7 @@ public class SchemaInitializer : IStartable private readonly SchemaUpgradeRunner _schemaUpgradeRunner; private readonly SchemaInformation _schemaInformation; private readonly ILogger _logger; + private bool _started; public SchemaInitializer(SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, SchemaUpgradeRunner schemaUpgradeRunner, SchemaInformation schemaInformation, ILogger logger) { @@ -190,13 +191,17 @@ private bool CanInitialize() public void Start() { - if (!string.IsNullOrWhiteSpace(_sqlServerDataStoreConfiguration.ConnectionString)) + if (!_started) { - Initialize(); - } - else - { - _logger.LogCritical("There was no connection string supplied. Schema initialization can not be completed."); + if (!string.IsNullOrWhiteSpace(_sqlServerDataStoreConfiguration.ConnectionString)) + { + Initialize(); + _started = true; + } + else + { + _logger.LogCritical("There was no connection string supplied. Schema initialization can not be completed."); + } } } } diff --git a/src/Microsoft.Health.SqlServer/Registration/SqlServerBaseRegistrationExtensions.cs b/src/Microsoft.Health.SqlServer/Registration/SqlServerBaseRegistrationExtensions.cs index f8742de9..5b376f7a 100644 --- a/src/Microsoft.Health.SqlServer/Registration/SqlServerBaseRegistrationExtensions.cs +++ b/src/Microsoft.Health.SqlServer/Registration/SqlServerBaseRegistrationExtensions.cs @@ -47,6 +47,7 @@ public static IServiceCollection AddSqlServerBase( services.Add() .Singleton() + .AsSelf() .AsService(); services.Add>()