From f8c9a8aec455a2e9af0286a673d51bcfdcc6c924 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Wed, 9 Aug 2023 11:15:11 +0300 Subject: [PATCH] Convert CmsKit Unified project to MongoDB --- .../CmsKitWebUnifiedModule.cs | 60 +++++-- .../EntityFrameworkCore/UnifiedDbContext.cs | 5 +- .../UnifiedDbContextFactory.cs | 4 +- .../MonbgoDB/UnifiedDbContext.cs | 33 ++++ .../Volo.CmsKit.Web.Unified.csproj | 146 ++++++++++-------- .../Volo.CmsKit.Web.Unified/appsettings.json | 3 +- 6 files changed, 167 insertions(+), 84 deletions(-) create mode 100644 modules/cms-kit/host/Volo.CmsKit.Web.Unified/MonbgoDB/UnifiedDbContext.cs diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs index f4f746a61d..585a47c127 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs @@ -10,34 +10,24 @@ using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Serilog; -using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Autofac; -using Volo.Abp.BlobStoring.Database.EntityFrameworkCore; using Volo.Abp.Data; -using Volo.Abp.EntityFrameworkCore; -using Volo.Abp.EntityFrameworkCore.SqlServer; using Volo.Abp.FeatureManagement; -using Volo.Abp.FeatureManagement.EntityFrameworkCore; using Volo.Abp.Identity; -using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.Web; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement; -using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.PermissionManagement.HttpApi; using Volo.Abp.PermissionManagement.Identity; -using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.Swashbuckle; using Volo.Abp.TenantManagement; -using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.Web; using Volo.Abp.Threading; using Volo.Abp.VirtualFileSystem; using Volo.CmsKit.Admin.Web; using Volo.CmsKit.Comments; -using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.MediaDescriptors; using Volo.CmsKit.MultiTenancy; using Volo.CmsKit.Public.Web; @@ -47,39 +37,73 @@ using Volo.CmsKit.Tags; using Volo.CmsKit.Web; using Volo.CmsKit.Web.Contents; +#if EntityFrameworkCore +using Volo.Abp.SettingManagement.EntityFrameworkCore; +using Volo.Abp.TenantManagement.EntityFrameworkCore; +using Volo.Abp.Identity.EntityFrameworkCore; +using Volo.Abp.PermissionManagement.EntityFrameworkCore; +using Volo.Abp.FeatureManagement.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore.SqlServer; +using Volo.Abp.BlobStoring.Database.EntityFrameworkCore; +using Volo.CmsKit.EntityFrameworkCore; +using Volo.Abp.AuditLogging.EntityFrameworkCore; +#elif MongoDB +using Volo.Abp.SettingManagement.MongoDB; +using Volo.Abp.TenantManagement.MongoDB; +using Volo.Abp.Identity.MongoDB; +using Volo.Abp.PermissionManagement.MongoDB; +using Volo.Abp.FeatureManagement.MongoDB; +using Volo.Abp.MongoDB; +using Volo.Abp.BlobStoring.Database.MongoDB; +using Volo.Abp.AuditLogging.MongoDB; +using Volo.CmsKit.MongoDB; +#endif + namespace Volo.CmsKit; [DependsOn( typeof(CmsKitWebModule), typeof(CmsKitApplicationModule), typeof(CmsKitHttpApiModule), +#if EntityFrameworkCore typeof(CmsKitEntityFrameworkCoreModule), typeof(AbpAuditLoggingEntityFrameworkCoreModule), + typeof(AbpEntityFrameworkCoreSqlServerModule), + typeof(AbpSettingManagementEntityFrameworkCoreModule), + typeof(AbpPermissionManagementEntityFrameworkCoreModule), + typeof(AbpIdentityEntityFrameworkCoreModule), + typeof(AbpFeatureManagementEntityFrameworkCoreModule), + typeof(AbpTenantManagementEntityFrameworkCoreModule), + typeof(BlobStoringDatabaseEntityFrameworkCoreModule), +#elif MongoDB + typeof(CmsKitMongoDbModule), + typeof(AbpAuditLoggingMongoDbModule), + typeof(AbpSettingManagementMongoDbModule), + typeof(AbpPermissionManagementMongoDbModule), + typeof(AbpIdentityMongoDbModule), + typeof(AbpFeatureManagementMongoDbModule), + typeof(AbpTenantManagementMongoDbModule), + typeof(BlobStoringDatabaseMongoDbModule), +#endif typeof(AbpAutofacModule), typeof(AbpAccountWebModule), typeof(AbpAccountApplicationModule), typeof(AbpAccountHttpApiModule), - typeof(AbpEntityFrameworkCoreSqlServerModule), - typeof(AbpSettingManagementEntityFrameworkCoreModule), - typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementApplicationModule), typeof(AbpPermissionManagementHttpApiModule), typeof(AbpIdentityWebModule), typeof(AbpIdentityApplicationModule), typeof(AbpIdentityHttpApiModule), - typeof(AbpIdentityEntityFrameworkCoreModule), typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpFeatureManagementApplicationModule), typeof(AbpFeatureManagementHttpApiModule), - typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementWebModule), typeof(AbpTenantManagementWebModule), typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementHttpApiModule), - typeof(AbpTenantManagementEntityFrameworkCoreModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreSerilogModule), - typeof(BlobStoringDatabaseEntityFrameworkCoreModule), typeof(AbpSwashbuckleModule) )] public class CmsKitWebUnifiedModule : AbpModule @@ -95,10 +119,12 @@ public class CmsKitWebUnifiedModule : AbpModule ConfigureCmsKit(); +#if EntityFrameworkCore Configure(options => { options.UseSqlServer(); }); +#endif if (hostingEnvironment.IsDevelopment()) { diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContext.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContext.cs index 9109a772ed..cef51b6af3 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContext.cs +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +#if EntityFrameworkCore +using Microsoft.EntityFrameworkCore; using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.BlobStoring.Database.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -10,6 +11,7 @@ using Volo.Abp.TenantManagement.EntityFrameworkCore; namespace Volo.CmsKit.EntityFrameworkCore; +[ConnectionStringName("SqlServerDefault")] public class UnifiedDbContext : AbpDbContext { public UnifiedDbContext(DbContextOptions options) @@ -32,3 +34,4 @@ public class UnifiedDbContext : AbpDbContext modelBuilder.ConfigureBlobStoring(); } } +#endif diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContextFactory.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContextFactory.cs index 156a6f8ba9..481351e453 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContextFactory.cs +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/EntityFrameworkCore/UnifiedDbContextFactory.cs @@ -1,4 +1,5 @@ -using System.IO; +#if EntityFrameworkCore +using System.IO; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; @@ -28,3 +29,4 @@ public class UnifiedDbContextFactory : IDesignTimeDbContextFactory + - - net7.0 - Volo.CmsKit - true - Volo.CmsKit-c2d31439-b723-48e2-b061-5ebd7aeb6010 - + + net7.0 + Volo.CmsKit + true + Volo.CmsKit-c2d31439-b723-48e2-b061-5ebd7aeb6010 + $(DefineConstants);MongoDB + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - - - Public.cshtml - - + + + + + + + + + + + + - - - Always - - - Always - - + + + + + + + + + + + + + + + + + + + + + Public.cshtml + + + + + + Always + + + Always + + diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json index d351388ffd..beaba507ac 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json @@ -1,5 +1,6 @@ { "ConnectionStrings": { - "Default": "Server=(localdb)\\MSSQLLocalDB;Database=CmsKit_Unified;Trusted_Connection=True;TrustServerCertificate=True" + "SqlServerDefault": "Server=(localdb)\\MSSQLLocalDB;Database=CmsKit_Unified;Trusted_Connection=True;TrustServerCertificate=True", + "Default": "mongodb://localhost:27017/CmsKit_Unified" } }