Skip to content

Instantly share code, notes, and snippets.

@maliming
Last active March 1, 2024 08:13
Show Gist options
  • Save maliming/6970c79b7bcd5223448bad7a850e0e87 to your computer and use it in GitHub Desktop.
Save maliming/6970c79b7bcd5223448bad7a850e0e87 to your computer and use it in GitHub Desktop.
public class SeedTestDataTestBaseModule : AbpModule
{
private static readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1, 1);
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (Semaphore.Lock())
{
AsyncHelper.RunSync(async () =>
{
using (var scope = context.ServiceProvider.CreateScope())
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment