Autofacを使用する既存のプロジェクトにIdentityServer3を実装しようとしています。Autofacを使用したIdentityServer3
"An error occurred when trying to create a controller of type 'TokenEndpointController'. Make sure that the controller has a parameterless public constructor."
は、今私は、サービスがある場合、これは、一般的なautofacエラーです知っている:私が遭遇した問題は、私は私のカスタムサービスを設定するとき、私は私のプロジェクトを実行し、認証しようとした場合、私はこのエラーを取得するということです正しく設定されていません。 エラーが実際に知らせる私のカスタムUserServiceのについてうめき声:私はIdentityServer3を使用し始め、それがこのようautofacに設立された前に、今、私はすでにUserProviderを持っていた
None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Business.IdentityServer.IdentityServerUserService' can be invoked with the available services and parameters: Cannot resolve parameter 'Business.Providers.IUserProvider userProvider' of constructor 'Void .ctor(Business.Providers.IUserProvider)'.
を:
builder.RegisterType<DatabaseContext>().As<DbContext>().InstancePerDependency();
builder.RegisterType<UserProvider>().As<IUserProvider>().InstancePerDependency();
これは前に働いていたので、のUserProviderには実際にすべての依存関係があることがわかりました。
私UserServiceのは、次のようになります。
public class IdentityServerUserService : UserServiceBase
{
private readonly IUserProvider _userProvider;
public IdentityServerUserService(IUserProvider userProvider)
{
_userProvider = userProvider;
}
public override async Task AuthenticateLocalAsync(LocalAuthenticationContext context)
{
var user = await _userProvider.FindAsync(context.UserName, context.Password);
if (user != null && !user.Disabled)
{
// Get the UserClaims
// Add the user to our context
context.AuthenticateResult = new AuthenticateResult(user.Id, user.UserName, new List<Claim>());
}
}
}
は、誰もが、私はこの問題を解決する方法を知っていますか?