私は得ています
InvalidOperationException:「Microsoft.AspNetCore.Identity.SignInManager 1 [Authorization.IdentityModels.ApplicationUser]」タイプのサービスが登録されていません。
apsCore MVC Webサイトを実行するとき。
これは私のコードからのセグメントです:
ConfigureServices:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole<Guid>>()
.AddEntityFrameworkStores<ApplicationDbContext, Guid>()
.AddDefaultTokenProviders();
構成、設定:
app.UseIdentity();
ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>
ApplicationUser.cs
public class ApplicationUser : IdentityUser<Guid>
あなたが私を助けることができるならば、私はとても幸せです。
IdentityクラスをGuidに移動して解決策を見つけた後、同じ問題に直面しました here :
新しいユーザータイプIdentityUserを使用するには、おそらくログイン部分ビューを変更する必要があります。
Views/Shared/_LoginPartial.cshtml
、変更したばかり
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
に
@using Microsoft.AspNetCore.Identity
@inject SignInManager<MyUser> SignInManager
@inject UserManager<MyUser> UserManager
そしてそれは私のために働いた。
この問題がまだ表示されているかどうかはわかりませんが、他の人がこの問題に遭遇した場合の助けがあります。 (仕様はバージョン1のものですが、挿入された依存関係を利用できないようにする必要性は同じです。)
この問題は、コンストラクターでSignInManagerを必要とするアプリケーションのクラスから発生しますが、依存性注入のセットアップでは、それに関連付けられた実装はありません。
修正するには、StartupクラスのConfigureServicesメソッドで、SignInManagerクラスをサービスに登録します。例:services.AddScoped<SignInManager<ApplicationUser>, SignInManager<ApplicationUser>>();
元の質問でこれを追加するように求められたため、AddIdentity拡張メソッドが更新された可能性がありますが、IoCコンテナーで解決できないものには同じエラータイプが表示されます。