Open Closed

Abp v8.3 Microservice template Data seeding #8111


User avatar
0
ahmednfwela@bdaya-dev.com created

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:
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

6 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    You can check the document to understand it better https://abp.io/docs/latest/solution-templates/microservice/database-configurations#database-migrations

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    ahmednfwela@bdaya-dev.com created

    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();
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    It,

    This seems to be a problem in the documentation, we will update the documentation

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    ahmednfwela@bdaya-dev.com created

    So which one is correct, OnPreApplicationInitializationAsync or OnPostApplicationInitializationAsync ? because the generated files contains a templates/service_nolayers template that uses OnPostApplicationInitializationAsync

    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~}}
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    I will confirm it and get back to you.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    1
    liangshiwei created
    Fullstack Developer

    Please use OnPreApplicationInitializationAsync as a best practice. We will update them all

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.