首先,在外部模块的项目文件(.csproj)中添加以下NuGet软件包引用:
然后,在外部模块中创建SeedData类,详细说明要填充的数据。例如:
public class ExternalModuleSeedDataContributor : ISeedDataContributor
{
public Task SeedAsync(DataSeedContext context)
{
context.Services.GetRequiredService().InsertAsync(
new Human("Tom", 30),
new Human("Jerry", 24),
new Human("Lucas", 20)
);
return Task.FromResult(0);
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication();
services.Configure(options =>
{
options.ExternalSeedContributors.Add(new ExternalModuleSeedDataContributor());
});
}