Open Closed

Tenant Seeder #422


User avatar
0
ishaq.alzidi created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v3.1.2
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Hi,

I am trying to seed some tenants by writing some code inside Tenant SaasDataSeedContributor class found under Domain. I was able to seed those tenants but I was not able to create an admin user for each tenant allthough I called SeedAsync().WithProperty() . Here is the code snippet that I did :

            await _editionDataSeeder.CreateStandardEditionsAsync();

            await _unitOfWorkManager.Current.SaveChangesAsync();


            var standardEdition = (await _editionRepository.GetListAsync())
                .FirstOrDefault(ed => ed.DisplayName == "Standard");

            if (standardEdition != null)
            {
                var tenant1 = _tenantRepository.FindByName("Tenant1", false);

                if (tenant1 == null)
                {
                    tenant1 = await _tenantManager.CreateAsync("Tenant1", standardEdition.Id);
                    tenant1.SetProperty("EnglishDescription", "Tenant1");
                    tenant1.SetProperty("ArabicDescription", "جهة 1");

                    tenant1Result = await _tenantRepository.InsertAsync(tenant1, true);

                    await DataSeeder.SeedAsync(new DataSeedContext(tenant1.Id)
                        .WithProperty("AdminEmail", "info@abp.io")
                        .WithProperty("AdminPassword", "1q2w3E*"));

                }
             }
             

Your help is most appreciated


2 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    hi @ishaq.alzidi

    Is there hava any error message in logs?

    You can try Change Tenant:

    using (CurrentTenant.Change(tenant.Id))
    {
    	await DataSeeder.SeedAsync(
    		new DataSeedContext(tenant.Id)
    			.WithProperty("AdminEmail", "info@abp.io")
    			.WithProperty("AdminPassword", "1q2w3E*")
    		);
    }
    
    
  • User Avatar
    0
    ishaq.alzidi created

    Thanks that's work be use change tenant

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 v9.3.0-preview. Updated on June 13, 2025, 11:37