- ABP Framework version: v4.3.0
- UI type: Blazor Server
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
Hi, I created project with suite microservice template. Everythink worked correct (i started project with tye) Also i have module project. I created them with module template. I added new service to microservice project as document show. After i referenced module to this service. I did as you do in saas service. But when i run any api method that interact with database from swagger its throw error
Autofac.Core.DependencyResolutionException: An exception was thrown while activating Kuys.Module.EmployeeManagement.EntityFrameworkCore.EmployeeManagementDbContext -> ?:Microsoft.EntityFrameworkCore.DbContextOptions`1[[Kuys.Module.EmployeeManagement.EntityFrameworkCore.EmployeeManagementDbContext, Kuys.Module.EmployeeManagement.EntityFrameworkCore, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null]]. ---> Volo.Abp.AbpException: No configuration found for Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore, Version=5.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60! Use services.Configure
When i comment below lines its working
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<EmployeeManagementServiceDbContext>(options =>
{
options.ReplaceDbContext<IEmployeeManagementDbContext>();
/* Remove "includeAllEntities: true" to create
* default repositories only for aggregate roots */
options.AddDefaultRepositories(includeAllEntities: true);
});
....
}
My module api method using custom repository, this repository try to access dbcontext inside it.
Where i missing or is it could be bug? I guess ReplaceDbContext not work correct??
11 Answer(s)
-
0
Can you share
EmployeeManagementServiceDbContext
and connection strings underappsettings.json
of your Api.Host project? -
0
Hi,
dbcontext
[ConnectionStringName(EmployeeManagementServiceDbProperties.ConnectionStringName)] public class EmployeeManagementServiceDbContext : AbpDbContext<EmployeeManagementServiceDbContext>, IEmployeeManagementDbContext//module dbcontext interface { public DbSet<EmployeeVestedYearlyLeaveHistory> EmployeeVestedYearlyLeaveHistories { get; set; } public DbSet<EmployeePhoto> EmployeePhotos { get; set; } public DbSet<EmployeeContract> EmployeeContracts { get; set; } ... public EmployeeManagementServiceDbContext(DbContextOptions<EmployeeManagementServiceDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.ConfigureEmployeeManagement(); } }
appsettings
{ "App": { "SelfUrl": "https://localhost:44371" }, "AuthServer": { "Authority": "https://localhost:44322", "RequireHttpsMetadata": "true" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", "ConnectionStrings": { "EmployeeManagementService": "Server=localhost,1434;Database=Kuys_EmployeeManagementService;Trusted_Connection=True", "AdministrationService": "Server=localhost,1434;Database=Kuys_Administration;Trusted_Connection=True", "SaasService": "Server=localhost,1434;Database=Kuys_Saas;Trusted_Connection=True" }, "StringEncryption": { "DefaultPassPhrase": ".." }, "Redis": { "Configuration": "localhost:6379" }, "RabbitMQ": { "Connections": { "Default": { "HostName": "localhost" } }, "EventBus": { "ClientName": "Kuys_EmployeeManagementService", "ExchangeName": "Kuys" } }, "ElasticSearch": { "Url": "http://localhost:9200" }, "AbpLicenseCode": ".." }
-
0
You don't need to replace DbContext since you are not merging dbcontexts etc.
Just using concrete implementation <br>
public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAbpDbContext<EmployeeManagementServiceDbContext>(options => { ... }); }
should be fine.
-
1
Yes but I wanted to approach the event like yours, in future i could seprate more little parts my modules and merge them one service like administration service.. I try to understand why its not worked
By the way what is reason of merge module dbcontexts in one service context?
Thank you
-
0
I guess problem is suite generated custom repositries with EmployeeManagementDbContext not used IEmployeeManagementDbContext
-
0
is this fixed? can I close it?
-
0
is this fixed? can I close it?
I have this problem too. Using cms-kit in adminService
---> Volo.Abp.AbpException: No configuration found for Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore, Version=5.0.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60! Use services.Configure<AbpDbContextOptions>(...) to configure it.
-
0
Some of entities uses ModuleDbContext instead of using IModuleDbContext https://github.com/abpframework/abp/blob/4495d7a3b1cb6a4aa816f29e2f8e5405ed68a6d5/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs#L19
-
0
And the interface ICmsKitProDbContext have not NewsletterRecords prop
-
0
I've the same problem and I read this thread to find the solution. In my case I've change my EF repository to use IDbContext instead DbContext.
I think the misconfiguration came from AbpSuite, so when you create a new entity you get custom repo based on concrete DbContext. It works fine if you don't need to move into a microservice but if you move later to microservice you need to change this.
For example the CmsKit has this issue in BlogFeature you get and in Blog you have
With this configuration it's impossible to Replace the DbContext.
I hope this example can be usefull.
-
0
Currently
ICmsKitDbContext
seems to be missing some of the DbSets. I have created an internal issue about this and it will be fixed in the next release.