Я хочу добавить нового пользователя в свою локальную базу данных после регистрации в Stormpath. В документе https://docs.stormpath.com/dotnet/aspnetcore/latest/registration.html#registration — раздел об обработчике пострегистрации. У меня проблема, потому что я не могу использовать UserRepository в файле StartUp. у меня ошибка:
Не удалось разрешить службу для типа «AppProject.Repositories.IUserRepository» при попытке активировать «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);
}