From c8c6399419e09b0071d9e8e96d10bc44d346bf78 Mon Sep 17 00:00:00 2001 From: Nikolaj Brask-Nielsen Date: Mon, 13 Nov 2023 07:15:42 +0100 Subject: [PATCH] feat: Extension for umbraco connection string --- ...mbracoEFCoreServiceCollectionExtensions.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs b/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs index 8fb8e536175f..4f37d58f914c 100644 --- a/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs @@ -144,11 +144,11 @@ public static void UseDatabaseProvider(this DbContextOptionsBuilder builder, str } /// - /// Sets the database provider to use based on the Umbraco connection string. + /// Gets the Umbraco connection string and provider name. /// - /// /// - public static void UseUmbracoDatabaseProvider(this DbContextOptionsBuilder builder, IServiceProvider serviceProvider) + /// + public static ConnectionStrings GetUmbracoConnectionString(this IServiceProvider serviceProvider) { ConnectionStrings connectionStrings = serviceProvider.GetRequiredService>().CurrentValue; @@ -162,12 +162,32 @@ public static void UseUmbracoDatabaseProvider(this DbContextOptionsBuilder build if (string.IsNullOrEmpty(connectionStrings.ProviderName)) { Log.Warning("No database provider was set. ProviderName is null"); - return; } if (string.IsNullOrEmpty(connectionStrings.ConnectionString)) { Log.Warning("No database provider was set. Connection string is null"); + } + + return connectionStrings; + } + + /// + /// Sets the database provider to use based on the Umbraco connection string. + /// + /// + /// + public static void UseUmbracoDatabaseProvider(this DbContextOptionsBuilder builder, IServiceProvider serviceProvider) + { + ConnectionStrings connectionStrings = serviceProvider.GetUmbracoConnectionString(); + + if (string.IsNullOrEmpty(connectionStrings.ProviderName)) + { + return; + } + + if (string.IsNullOrEmpty(connectionStrings.ConnectionString)) + { return; }