1 回答

TA貢獻1818條經驗 獲得超7個贊
這個特定問題的解決方案(盡管我希望找到一個更“通用”的解決方案)是改變實際的貢獻者。在您的域模塊(或您認為合適的任何地方:您的遷移器或其他),只需執行以下操作:
// Remove the contributor for the module
context.Services.RemoveAll(t => t.ImplementationType == typeof(IdentityDataSeedContributor));
// Add my custom constributor
context.Services.AddTransient<IDataSeedContributor, MyCustomConstributor>();
其中貢獻者的實現只是默認的副本:
public class MyCustomConstributor : IDataSeedContributor
{
private readonly IIdentityDataSeeder _identityDataSeeder;
public IdentityDataSeedContributor(IIdentityDataSeeder identityDataSeeder)
{
_identityDataSeeder = identityDataSeeder;
}
public Task SeedAsync(DataSeedContext context)
{
return _identityDataSeeder.SeedAsync(
context["AdminEmail"] as string ?? "my@admin-email",
context["AdminPassword"] as string ?? "my-admin-password",
context.TenantId
);
}
}
請注意,您仍然在這里獲得用戶名admin...如果您想更改它,您也可以替換實現IIdentityDataSeeder(使用相同的方法,或者更簡單的方法Services.Replace,您可以使用它,因為應該只有一種實現IIdentityDataSeeder)并復制您自己的默認用戶名,更改搜索到的用戶名。
目前,更換模塊上的服務似乎是可行的方法。也許在未來的版本中可能存在直接攔截其他模塊的初始化階段的可能性,但我現在還沒有看到如何實現。
- 1 回答
- 0 關注
- 111 瀏覽
添加回答
舉報