I generated a new microservice solution on the latest version of the CLI, but I noticed some patterns have changed from the old template (e.g. removal of DbMigrator project), mainly what I am asking about here is the per-service data seeder, e.g.:
public class MicroserviceNameDataSeeder : ITransientDependency
{
private readonly ILogger<MicroserviceNameDataSeeder> _logger;
public MicroserviceNameDataSeeder(
ILogger<MicroserviceNameDataSeeder> logger)
{
_logger = logger;
}
public async Task SeedAsync(Guid? tenantId = null)
{
_logger.LogInformation("Seeding data...");
//...
}
}
As you can see, it does not use IDataSeeder
anymore, is it a bad practice to use it here ? do we need to inject + call each data seed contributor manually from all the dependent modules ?
- ABP Framework version: v8.3.0
- ABP CLI: v0.9.1 (Beta)
- UI Type: Angular
- Database System: EF Core PostgreSQL
- Tiered (for MVC) or Auth Server Separated (for Angular): Microservice solution
- Exception message and full stack trace:
- Steps to reproduce the issue:
6 Answer(s)
-
0
Hi,
You can check the document to understand it better https://abp.io/docs/latest/solution-templates/microservice/database-configurations#database-migrations
-
0
I see, but I noticed that the given example in the identity service is different from the docs
Generated from template, uses
OnPreApplicationInitializationAsync
public override async Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context) { using var scope = context.ServiceProvider.CreateScope(); await scope.ServiceProvider .GetRequiredService<IdentityServiceRuntimeDatabaseMigrator>() .CheckAndApplyDatabaseMigrationsAsync(); }
Referenced in docs uses
OnPostApplicationInitializationAsync
:public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context) { using var scope = context.ServiceProvider.CreateScope(); await scope.ServiceProvider .GetRequiredService<IdentityServiceRuntimeDatabaseMigrator>() .CheckAndApplyDatabaseMigrationsAsync(); }
-
0
It,
This seems to be a problem in the documentation, we will update the documentation
-
0
So which one is correct,
OnPreApplicationInitializationAsync
orOnPostApplicationInitializationAsync
? because the generated files contains atemplates/service_nolayers
template that usesOnPostApplicationInitializationAsync
public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context) { using var scope = context.ServiceProvider.CreateScope(); {{~ if config.database_provider == "ef" ~}} await scope.ServiceProvider .GetRequiredService<MicroserviceNameRuntimeDatabaseMigrator>() .CheckAndApplyDatabaseMigrationsAsync(); {{~ else if config.database_provider == "mongodb" ~}} await scope.ServiceProvider .GetRequiredService<MicroserviceNameDataSeeder>() .SeedAsync(); {{~ end~}} }
-
0
Hi,
I will confirm it and get back to you.
-
1
Please use OnPreApplicationInitializationAsync as a best practice. We will update them all