Environment on IDataSeedContributor?
Is it possible to get the environment in a IDataSeedContributor? I want to be able to decide about seeding data or not or even the data to be seeded based on the environment.
It seems that I can't inject IHostingEnvironment from the DbMigrator. I created a solution to check the environment on the ConfigureServices and use different DataSeeders but it doesn't seem a nice solution so I was wondering if you have a better idea.
Thanks!
It seems that I can't inject IHostingEnvironment from the DbMigrator.
You can refer to this issue: https://github.com/abpframework/abp/issues/3429
DataSeedContext can pass parameters.
await DataSeeder.SeedAsync(
new DataSeedContext(tenant.Id)
.WithProperty("AdminEmail", input.AdminEmailAddress)
.WithProperty("AdminPassword", input.AdminPassword)
);
Thanks for replying. The issue that you mentioned doesn't say anything about passing the current environment to seeders unless I am missing something. I've already got the code down to load different environments on the DbMigrator, my problem is injecting this along to other classes like DataSeeders.
I also don't think passing parameters to the DataSeedContext will help because, in the migration context, it resides on the DbMigrationService which I will not be able to inject a IHostingEnvironment too since it apparently it doesn't exist in Console Apps.
I think what mailming is saying is that you can add new DataSeedContext().WithProperty("Environment", "Production")); to here:
https://github.com/abpframework/abp/blob/523bc071ad63104683e80e76aef0e68d6c90f101/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/Data/MyProjectNameDbMigrationService.cs#L68
Alternatively I think you could also use Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") anywhere you need it. Just pass "ASPNETCORE_ENVIRONMENT" as an argument when you start the console app.
You can also add IConfiguration to your DbMigrationService/IDataSeedContributor constructors to access your config via dependency injection.