Update data-seeding document

pull/5624/head
liangshiwei 5 years ago
parent f044d94a19
commit 235109e471

@ -38,16 +38,21 @@ namespace Acme.BookStore
{
private readonly IRepository<Book, Guid> _bookRepository;
private readonly IGuidGenerator _guidGenerator;
private readonly ICurrentTenant _currentTenant;
public BookStoreDataSeedContributor(
IRepository<Book, Guid> bookRepository,
IGuidGenerator guidGenerator)
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant)
{
_bookRepository = bookRepository;
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
}
public async Task SeedAsync(DataSeedContext context)
{
using (_currentTenant.Change(context?.TenantId))
{
if (await _bookRepository.GetCountAsync() > 0)
{
@ -66,6 +71,7 @@ namespace Acme.BookStore
}
}
}
}
````
* `IDataSeedContributor` defines the `SeedAsync` method to execute the **data seed logic**.

@ -38,16 +38,21 @@ namespace Acme.BookStore
{
private readonly IRepository<Book, Guid> _bookRepository;
private readonly IGuidGenerator _guidGenerator;
private readonly ICurrentTenant _currentTenant;
public BookStoreDataSeedContributor(
IRepository<Book, Guid> bookRepository,
IGuidGenerator guidGenerator)
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant)
{
_bookRepository = bookRepository;
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
}
public async Task SeedAsync(DataSeedContext context)
{
using (_currentTenant.Change(context?.TenantId))
{
if (await _bookRepository.GetCountAsync() > 0)
{
@ -66,6 +71,7 @@ namespace Acme.BookStore
}
}
}
}
````
* `IDataSeedContributor` 定义了 `SeedAsync` 方法用于执行 **数据种子逻辑**.

@ -2,17 +2,20 @@
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
namespace MyCompanyName.MyProjectName
{
public class MyProjectNameDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly IGuidGenerator _guidGenerator;
private readonly ICurrentTenant _currentTenant;
public MyProjectNameDataSeedContributor(
IGuidGenerator guidGenerator)
IGuidGenerator guidGenerator, ICurrentTenant currentTenant)
{
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
}
public Task SeedAsync(DataSeedContext context)
@ -21,7 +24,10 @@ namespace MyCompanyName.MyProjectName
* at this point!
*/
using (_currentTenant.Change(context?.TenantId))
{
return Task.CompletedTask;
}
}
}
}

Loading…
Cancel
Save