0
我想在Stormpath註冊後將新用戶添加到我的本地數據庫。在文檔https://docs.stormpath.com/dotnet/aspnetcore/latest/registration.html#registration是關於註冊後處理程序的部分。我有問題,因爲我不能在StartUp文件中使用UserRepository。 我有錯誤:在Stormpath註冊後將用戶添加到本地數據庫
Unable to resolve service for type 'AppProject.Repositories.IUserRepository' while attempting to activate 'AppProject.Startup'
。
public void ConfigureServices(IServiceCollection services, IUserRepository userRepository)
{
services.AddStormpath(new StormpathOptions()
{
Configuration = new StormpathConfiguration()
{
Client = new ClientConfiguration()
{
ApiKey = new ClientApiKeyConfiguration()
{
Id = "xxxxxxxxxxx",
Secret = "xxxxxxxxx"
}
}
},
PostRegistrationHandler = (context, ct) =>
{
return MyPostRegistrationHandler(context, ct, userRepository);
}
});
}
private Task MyPostRegistrationHandler(PostRegistrationContext context, CancellationToken ct, IUserRepository userRepository)
{
userRepository.Add(new User(context.Account.Email, context.Account.FullName, context.Account.GivenName, context.Account.Surname, context.Account.Username));
userRepository.SaveChangesAsync();
return Task.FromResult(0);
}
重要提醒Stormpath將於2017年8月17日中午PST關閉。如果您還沒有,請開始遷移到另一項服務。我推薦Okta的開發者平臺。 – Alex