-
ABP Framework version: Commercial 9.04
-
UI Type: N/A
-
Database System: EF Core & MongoDB
-
Tiered (for MVC) or Auth Server Separated (for Angular): yes
-
Exception message and full stack trace: N/A
-
Steps to reproduce the issue:
We created a new Microservice solution using Abp Studio and selected EF Core as the database. So all of the Abp generated microservices (Administration, AuditLogging, Identity, etc.) are using MS Sql databases
Most of our microservices use EF Core but we have a couple that use MongoDB.
I added a new microservice module using Studio and selected MongoDB as the database provider. I then created an entity using Abp Suite and generated all of the code.
In the appsettings file the connection strings for the Abp microservices are correctly pointing to the SQL Server databases. I updated the connection string for the new Microservice with the connection string to the MongoDB project.
When I ran the new microservice it correctly created the collections for the new Microservice but it also added collections for the Abp microservices (AbpFeatureGroups, AbpFeatureValues, AbpPermissions, etc) in the mongo database.
Looking at the code I see these in the application module.
using Volo.Abp.SettingManagement.MongoDB;
using Volo.Abp.PermissionManagement.MongoDB;
using Volo.Abp.LanguageManagement.MongoDB;
using Volo.Abp.FeatureManagement.MongoDB;
using Volo.Abp.AuditLogging.MongoDB;
using Volo.Saas.MongoDB;
using Volo.Abp.BlobStoring.Database.MongoDB;
I updated the csproj file and the module to use EF Core packages but am getting errors configuring the database for the microservice entity.
I then reviewed the answer to this support question https://abp.io/support/questions/1269/using-MongoDB-in-microservice-service-inside-microservice-solution-which-uses-efcore but it appears written for v8 and it seems there are significant changes to the microservice template in V9.
Is there a document or can you provide detailed steps to update the microservice to use EntityFrameworkCore for the Abp services and MongoDb for our microservice?
Thank you in advance.
5 Answer(s)
-
0
Hi, can you please check our Change Microservice project to use MongoDB Provider documentation and follow the described steps, and see if it works for you? If you stuck at any point, please let me know.
Best regards.
-
0
It looks like you'd didn't read the full question.
We're on Abp V9 and I generated the solution and microservice using Abp Studio version 09.23. This is the solution configuration.
-
Template: microservice
-
Created ABP Studio Version: 0.9.23
-
Current ABP Studio Version: 0.9.23
-
Multi-Tenancy: Yes
-
UI Framework: mvc
-
Theme: leptonx
-
Theme Style: system
-
Run Install Libs: Yes
-
Database Provider: ef
-
Database Management System: sqlserver
-
Mobile Framework: none
-
Public Website: No
-
Include Tests: Yes
-
Dynamic Localization: Yes
-
Kubernetes Configuration: Yes
-
Grafana Dashboard: Yes
-
Use Local References: No
-
Optional Modules:
-
GDPR
-
TextTemplateManagement
-
AuditLogging
-
OpenIddictAdmin
-
The document link you sent looks like it's based on a previous version of the Microservice template and assumes you want to change everything to MongoDb. In our case we want the Abp microservices as well as most of our microservices to use SQL Server and a couple of other microservices to use MongoDB.
In the new Microservice (MemberConfig) I created withAbp Studio I selected MongoDb for the database provider. The solution that was generated is all MongDb including DistributedEvents, FeatureManagement, LanguageManagement, PermissionManagement and SettingManagement.
Below I've copied the DbContext and CloverleafCMSMemberConfigModule deleting what I thought was irrelevant code.
Please tell me what I need to update/add/delete so that the DistributedEvents, FeatureManagement, LanguageManagement, PermissionManagement and SettingManagement packages use SQL Server and the rest of the MemberConfig microservice use MongDb?
It would be very helpful to know that someone on the Abp team has gone through similar steps using a current version of everything (ABP Studio, Abp Suite and Microservice template).
This is the MemberConfigDbContext class
...other usings using Volo.Abp.LanguageManagement; using Volo.Abp.PermissionManagement; using Volo.Abp.SettingManagement; using Volo.Abp.Studio.Client.AspNetCore; using Volo.Abp.Swashbuckle; using Volo.Abp.Security.Claims; using Volo.Abp.SettingManagement.MongoDB; using Volo.Abp.PermissionManagement.MongoDB; using Volo.Abp.LanguageManagement.MongoDB; using Volo.Abp.FeatureManagement.MongoDB; using Volo.Abp.AuditLogging.MongoDB; using Volo.Saas.MongoDB; using Volo.Abp.BlobStoring.Database.MongoDB; using Volo.Abp.MongoDB.DistributedEvents; namespace CloverleafCMS.MemberConfig; [DependsOn( typeof(BlobStoringDatabaseMongoDbModule), typeof(AbpSettingManagementMongoDbModule), typeof(LanguageManagementMongoDbModule), typeof(AbpPermissionManagementMongoDbModule), typeof(AbpFeatureManagementMongoDbModule), typeof(AbpAuditLoggingMongoDbModule), typeof(SaasMongoDbModule), ... other DependsOn, typeof(AbpHttpClientModule) )]
And this is the CloverleafCMSMemberConfigModule class
public class CloverleafCMSMemberConfigModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); var env = context.Services.GetHostingEnvironment();
var redis = CreateRedisConnection(configuration); ... other configures ConfigureDatabase(context); ... other configures context.Services.TransformAbpClaims(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); var configuration = context.GetConfiguration(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } ... other code } private void ConfigureDatabase(ServiceConfigurationContext context) { Configure<AbpDbConnectionOptions>(options => { options.Databases.Configure("Administration", database => { database.MappedConnections.Add(AbpPermissionManagementDbProperties.ConnectionStringName); database.MappedConnections.Add(AbpFeatureManagementDbProperties.ConnectionStringName); database.MappedConnections.Add(AbpSettingManagementDbProperties.ConnectionStringName); }); options.Databases.Configure("AuditLoggingService", database => { database.MappedConnections.Add(AbpAuditLoggingDbProperties.ConnectionStringName); }); options.Databases.Configure("SaasService", database => { database.MappedConnections.Add(SaasDbProperties.ConnectionStringName); }); options.Databases.Configure("LanguageService", database => { database.MappedConnections.Add(LanguageManagementDbProperties.ConnectionStringName); }); }); context.Services.AddMongoDbContext<MemberConfigDbContext>(options => { options.AddDefaultRepositories(); }); context.Services.AddAlwaysDisableUnitOfWorkTransaction(); Configure<AbpUnitOfWorkDefaultOptions>(options => { options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; }); } private void ConfigureDistributedEventBus() { Configure<AbpDistributedEventBusOptions>(options => { options.Inboxes.Configure(config => { config.UseMongoDbContext<MemberConfigDbContext>(); }); options.Outboxes.Configure(config => { config.UseMongoDbContext<MemberConfigDbContext>(); }); }); } private void ConfigureIntegrationServices() { Configure<AbpAspNetCoreMvcOptions>(options => { options.ExposeIntegrationServices = true; }); } private void ConfigureObjectMapper(ServiceConfigurationContext context { context.Services.AddAutoMapperObjectMapper<CloverleafCMSMemberConfigModule>(); Configure<AbpAutoMapperOptions>(options => { options.AddMaps<CloverleafCMSMemberConfigModule>(validate: true); }); }
-
-
0
Hi, sorry for the misunderstanding and thanks for your detailed question.
I understand that you want to configure your MemberConfig microservice to use MongoDB, while ensuring that the DistributedEvents, FeatureManagement, LanguageManagement, PermissionManagement, and SettingManagement modules continue to use SQL Server.
Steps to achieve this:
1.-) Modify the DbContext Dependencies
Your MemberConfigDbContext is currently configured with MongoDB for FeatureManagement, LanguageManagement, PermissionManagement, SettingManagement, and AuditLogging. Since you want these modules to use SQL Server, you should:
Remove the following MongoDB module dependencies from CloverleafCMSMemberConfigModule:
typeof(AbpSettingManagementMongoDbModule), typeof(LanguageManagementMongoDbModule), typeof(AbpPermissionManagementMongoDbModule), typeof(AbpFeatureManagementMongoDbModule), typeof(AbpAuditLoggingMongoDbModule), typeof(SaasMongoDbModule),
Instead, replace them with their Entity Framework Core (SQL Server) counterparts:
typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(LanguageManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpAuditLoggingEntityFrameworkCoreModule), typeof(SaasEntityFrameworkCoreModule),
2-) Update the Database Configuration in ConfigureDatabase method
You need to explicitly set SQL Server as the database provider for these modules while keeping MongoDB for MemberConfig:
Configure<AbpDbConnectionOptions>(options => { options.Databases.Configure("Administration", database => { database.MappedConnections.Add(AbpPermissionManagementDbProperties.ConnectionStringName); database.MappedConnections.Add(AbpFeatureManagementDbProperties.ConnectionStringName); database.MappedConnections.Add(AbpSettingManagementDbProperties.ConnectionStringName); }); options.Databases.Configure("AuditLoggingService", database => { database.MappedConnections.Add(AbpAuditLoggingDbProperties.ConnectionStringName); }); options.Databases.Configure("SaasService", database => { database.MappedConnections.Add(SaasDbProperties.ConnectionStringName); }); options.Databases.Configure("LanguageService", database => { database.MappedConnections.Add(LanguageManagementDbProperties.ConnectionStringName); }); });
Actually, this should already be done by ABP Studio. Additionally, ensure that your SQL Server connection strings are properly defined in appsettings.json.
3-) Configure MongoDB for MemberConfigDbContext Only
Currently, you're adding default repositories to MemberConfigDbContext using MongoDB. This is fine, but it should not affect the other services that need SQL Server. Make sure your MongoDB context is isolated:
context.Services.AddMongoDbContext<MemberConfigDbContext>(options => { options.AddDefaultRepositories(); });
This keeps MemberConfigDbContext using MongoDB, while the modules mentioned above will use SQL Server.
4-) Ensure That Distributed Events Use SQL Server
Since you want DistributedEvents to use SQL Server, update
ConfigureDistributedEventBus()
to use SQL Server’s DbContext instead of MongoDB:Configure<AbpDistributedEventBusOptions>(options => { options.Inboxes.Configure(config => { config.UseEfCoreDbContext<MySqlServerDbContext>(); }); options.Outboxes.Configure(config => { config.UseEfCoreDbContext<MySqlServerDbContext>(); }); });
This ensures that your event bus persists events in SQL Server rather than MongoDB.
Best regards.
-
0
Ok. I updated the module. However it's probably fine to have the AbpDistributedEventBus use MongoDB in the same database.
However I had to add code to configure the SQL dbcontexts
Configure<AbpDbContextOptions>(options => { options.Configure<PermissionManagementDbContext>(dbContextOptions => { dbContextOptions.UseSqlServer(); }); ... remaining Sql db contexts
Here's the revised MemberConfigDbContext
using CloverleafCMS.MemberConfig.Members; using MongoDB.Driver; using Volo.Abp.Data; using Volo.Abp.MongoDB; using Volo.Abp.MongoDB.DistributedEvents; namespace CloverleafCMS.MemberConfig.Data; [ConnectionStringName(DatabaseName)] public class MemberConfigDbContext : AbpMongoDbContext, IHasEventInbox, IHasEventOutbox { public IMongoCollection Members => Collection(); public const string DatabaseName = "MemberConfig"; public IMongoCollection IncomingEvents => Collection(); public IMongoCollection OutgoingEvents => Collection(); protected override void CreateModel(IMongoModelBuilder modelBuilder) { base.CreateModel(modelBuilder); modelBuilder.ConfigureEventInbox(); modelBuilder.ConfigureEventOutbox(); } }
I was able to build and run the application. However when I execute the post route of the API I get this error:
Error] ---------- RemoteServiceErrorInfo ----------
{
"code": null,
"message": "An internal error occurred during your request!",
"details": null,
"data": null,
"validationErrors": null
}3/5/2025 9:15:38 PM [Error] Autofac.Core.DependencyResolutionException: An exception was thrown while activating Castle.Proxies.MembersAppServiceProxy -> CloverleafCMS.MemberConfig.Members.MongoMemberRepository.
---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'CloverleafCMS.MemberConfig.Members.MongoMemberRepository' can be invoked with the available services and parameters:
Cannot resolve parameter 'Volo.Abp.MongoDB.IMongoDbContextProvider1[CloverleafCMS.MemberConfig.Data.MemberConfigDbContext] dbContextProvider' of constructor 'Void .ctor(Volo.Abp.MongoDB.IMongoDbContextProvider
1[CloverleafCMS.MemberConfig.Data.MemberConfigDbContext])'.See https://autofac.rtfd.io/help/no-constructors-bindable for more info.
-
0
Hi, please apply the following steps:
-
Ensure MongoDB Context is Registered Correctly
In your CloverleafCMSMemberConfigModule, check if MemberConfigDbContext is being registered properly as a MongoDB context. The following should be present in the
ConfigureServices
method:context.Services.AddMongoDbContext<MemberConfigDbContext>(options => { options.AddDefaultRepositories(); options.AddRepository<Member, MongoMemberRepository>(); });
Make sure AddDefaultRepositories() and custom repository configuration is included.
-
Verify Dependency on AbpMongoDbModule
Ensure that CloverleafCMSMemberConfigModule depends on AbpMongoDbModule:
[DependsOn(typeof(AbpMongoDbModule))] public class CloverleafCMSMemberConfigModule : AbpModule { // ... }
This ensures that ABP properly initializes MongoDB-related services.
-
Check the Repository Class Constructor
If the MongoMemberRepository constructor expects IMongoDbContextProvider<MemberConfigDbContext>, confirm that it looks something like this:
public class MongoMemberRepository : MongoDbRepository<MemberConfigDbContext, Member, Guid>, IMemberRepository { public MongoMemberRepository(IMongoDbContextProvider<MemberConfigDbContext> dbContextProvider) : base(dbContextProvider) { } }
If you have a custom implementation, make sure the correct context type is being injected.
Try these fixes one by one and restart your application. Let me know if you need further debugging!
-