Starts in:
2 DAYS
7 HRS
27 MIN
26 SEC
Starts in:
2 D
7 H
27 M
26 S
Open Closed

DbMigrator project - appsettings per environment #1734


User avatar
0
MichelZ created
  • ABP Framework version: v4.4.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace: None
  • Steps to reproduce the issue:" Create an appsettings.Development.json, override connection string "Default" in it, set Environment variable DOTNET_ENVIRONMENT to Development

Hi

We are trying to make the DbMigrator project aware of different environments by using an appsettings.json per environment. This is usually straight forward by just creating appsettings.<Environment>.json file.

Unfortunately in the DbMigrator project this does not seem to work. While troubleshooting I have injected IConfiguration into the DbMigratorHostedService, and I did a Console.WriteLIne(_configuration.GetConnectionString("Default")); in the StartAsync method. Surprisingly, THIS WORKS and it gives the correct connection string! However, strangely it executes the DbMigration on the connection string from the original appsettings.json, instead of the one from IConfiguration..... I can't explain why. I can change the appsettings.json, and it connects to a different database, so it's definitely using that one.

Any ideas?

Thanks Michel


2 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    DbMigrator also uses IConfiguration , see https://github.com/abpframework/abp/blob/dev/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs#L15

    But ConnectionString is a special config! DbMigrator designed to be worked in distributed environments. So if your tenants have its own database then it gets the ConnectionString from database.

    See https://github.com/abpframework/abp/blob/dev/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/Data/MyProjectNameDbMigrationService.cs#L66

    Try to read another appsettings.json value

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06