Browse Source

Update DataSeeder.cs

pull/13940/head
maliming 4 years ago
parent
commit
e5f4f40d25
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 27
      framework/src/Volo.Abp.Data/Volo/Abp/Data/DataSeeder.cs

27
framework/src/Volo.Abp.Data/Volo/Abp/Data/DataSeeder.cs

@ -25,20 +25,25 @@ public class DataSeeder : IDataSeeder, ITransientDependency
{ {
using (var scope = ServiceScopeFactory.CreateScope()) using (var scope = ServiceScopeFactory.CreateScope())
{ {
var manager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); if (context.Properties.ContainsKey(nameof(DataSeederExtensions.SeedInSeparateUowAsync)))
foreach (var contributorType in Options.Contributors)
{ {
using (var uow = manager.Begin( var manager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
requiresNew: context.Properties.ContainsKey(nameof(DataSeederExtensions.SeedInSeparateUowAsync)), foreach (var contributorType in Options.Contributors)
isTransactional: true))
{ {
var contributor = (IDataSeedContributor)scope using (var uow = manager.Begin(requiresNew: true, isTransactional: true))
.ServiceProvider {
.GetRequiredService(contributorType); var contributor = (IDataSeedContributor)scope.ServiceProvider.GetRequiredService(contributorType);
await contributor.SeedAsync(context);
await uow.CompleteAsync();
}
}
}
else
{
foreach (var contributorType in Options.Contributors)
{
var contributor = (IDataSeedContributor)scope.ServiceProvider.GetRequiredService(contributorType);
await contributor.SeedAsync(context); await contributor.SeedAsync(context);
await uow.CompleteAsync();
} }
} }
} }

Loading…
Cancel
Save