- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我必须将我们所有的 IdentityFramework 类和接口(interface)移动到单独的库中,这意味着新的 Common.Models.Interfaces
界面库只能引用其他界面库(或.net 库)。这意味着我所有的ApplicationUser
参数和变量变为 IApplicationUser
.
经过几个小时的更改,我完成了所有构建,但在运行时出现以下错误:
The current type, Microsoft.AspNet.Identity.IUserStore`1[Common.Models.Interfaces.Account.IApplicationUser], is an interface and cannot be constructed. Are you missing a type mapping?
所以我的问题是:我可能缺少什么类型的映射?
我之前已经解决了dbcontext
来自 http://tech.trailmax.info/2014/09/aspnet-identity-and-ioc-container-registration 的以下代码存在问题(具体使用InjectionConstructor
)
container.RegisterType<IApplicationUser, ApplicationUser>();
container.RegisterType<DbContext, ApplicationDbContext>();
container.RegisterType<IdentityDbContext<ApplicationUser>, ApplicationDbContext>();
container.RegisterType<IIdentityMessageService, EmailService>();
container.RegisterType<IApplicationSignInManager, ApplicationSignInManager>();
container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new InjectionConstructor(typeof(ApplicationDbContext)));
注意:此处提到的其他错误已删除,因为它具有误导性。看起来我需要额外的映射,但不知道是什么。
应用程序用户界面和类如下(已删减),以便您发现我哪里出错了:
public interface IApplicationUser : IUser, IUser<string>
{
...
}
public class ApplicationUser : IdentityUser, IApplicationUser
{
...
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
显然不可能包含所有相关代码来重现此代码,因为它运行到 1000 行,并且不需要重现,因此只有 IOC 专家应该申请。 :)
在来自 @guillaume31
的有用链接之后我尝试了以下方法:
container.RegisterType(typeof(IUserStore<>), typeof(UserStore<>), new InjectionConstructor(typeof(ApplicationDbContext)));
编译通过了,但是我得到了一个新的错误:
GenericArguments[0], 'Common.Models.Interfaces.Account.IApplicationUser', on 'Microsoft.AspNet.Identity.EntityFramework.UserStore`6[TUser,TRole,TKey,TUserLogin,TUserRole,TUserClaim]' violates the constraint of type parameter 'TUser'
container.RegisterType(typeof(IUserStore<>), typeof(UserStore<ApplicationUser>), new InjectionConstructor(typeof(ApplicationDbContext)));
导致此错误:
Unable to cast object of type 'Microsoft.AspNet.Identity.EntityFramework.UserStore
1[Vero.Common.Verofy.Models.Account.ApplicationUser]' to type 'Microsoft.AspNet.Identity.IUserStore
1[Vero.Common.Verofy.Models.Interfaces.Account.IApplicationUser]'.
container.RegisterType(typeof(IUserStore<IApplicationUser>), typeof(UserStore<ApplicationUser>), new InjectionConstructor(typeof(ApplicationDbContext)));
这可以编译,但我得到这个错误(与之前的测试相同):
Unable to cast object of type 'Microsoft.AspNet.Identity.EntityFramework.UserStore
1[Common.Models.Account.ApplicationUser]' to type 'Microsoft.AspNet.Identity.IUserStore
1[Common.Models.Interfaces.Account.IApplicationUser]'.
var applicationDbContext = new ApplicationDbContext();
container.RegisterInstance<DbContext>(applicationDbContext);
var userStore = new UserStore<ApplicationUser>(applicationDbContext);
container.RegisterInstance(typeof(IUserStore<IApplicationUser>), userStore);
新的错误是:
The type Microsoft.AspNet.Identity.EntityFramework.UserStore
1[[Vero.Common.Verofy.Models.Account.ApplicationUser, Vero.Common.Verofy.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] cannot be assigned to variables of type Microsoft.AspNet.Identity.IUserStore
1[Vero.Common.Verofy.Models.Interfaces.Account.IApplicationUser]. Parameter name: instance
以下简单行在运行时也会失败:
IUserStore<IApplicationUser> test = (IUserStore<IApplicationUser>)new UserStore<ApplicationUser>(applicationDbContext);
错误是:
无法转换类型的对象 > 'Microsoft.AspNet.Identity.EntityFramework.UserStore 1[Common.Models.Account.ApplicationUser]' to type 'Microsoft.AspNet.Identity.IUserStore
1[Common.Models.Interfaces.Account.IApplicationUser]'。
所有这些问题都表明我的 IUserStore<IApplicationUser>
之间不兼容。和我的 UserStore<ApplicationUser>
类实现。询问您认为可能有帮助的任何类(class)的更多详细信息。
ApplicationUser
类需要暴露 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, string> manager)
UserManager
属于 IApplicationUser 类型而不是应用程序用户,并导致发生大量级联依赖关系。最佳答案
这是我用过的
container.RegisterType<IUserStore<IdentityUser>, UserStoreRepository>(new PerRequestLifetimeManager());
container.RegisterType<IRoleStore<IdentityRole, string>, RoleStoreRepository>(new PerRequestLifetimeManager());
container.RegisterType<ApplicationUserManager>(new PerRequestLifetimeManager());
container.RegisterType<ApplicationRoleManager>(new PerRequestLifetimeManager());
UserStoreRepository 就是
public class UserStoreRepository : UserStore<IdentityUser>
{
public UserStoreRepository(AuthContext context)
: base(context)
{
}
}
同样
public class RoleStoreRepository : RoleStore<IdentityRole>
{
public RoleStoreRepository(AuthContext context)
: base(context)
{
}
}
当然你需要注册上下文
public class AuthContext: IdentityDbContext<IdentityUser>
{
public AuthContext()
: base("AuthContext")
{
}
}
对于其他事情:
public class ApplicationUserManager : UserManager<IdentityUser>
public class ApplicationRoleManager : RoleManager<IdentityRole>
我认为您的第一次尝试几乎是正确的,我会尝试将您的 UserStore 包装到另一个包装您的 ApplicationUser 的对象
关于c# - 带有 IOC : "The current type is an interface and cannot be constructed" 的身份框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34202416/
按照此页面上的教程:https://cdkworkshop.com/20-typescript/40-hit-counter/300-resources.html 我相信this ,传递给 Table
据我所知std::allocator::construct在旧版本的 C++ 上仅需要两个参数;第一个是指向原始的、未构造的内存的指针,我们要在其中构造 T 类型的对象。第二个是用于初始化该对象的元素
我正在阅读 CanJS API 文档并遇到 can.Construct.extend http://canjs.com/docs/can.Construct.extend.html .我知道 can.
考虑 struct C { C() { printf("C::C()\n" ); } C(int) { printf("C::C(i
阅读 git repo 中截取的以下代码时遇到一些问题。链接到存储库和问题: https://github.com/paolo-sz/fatty/blob/master/src/winmain.c#L
除了将一种高级语言转换为另一种高级语言的编译器之外,任何编译为机器代码的编译器都需要用汇编编写吗? 最佳答案 编译器的源代码不需要用汇编语言编写。例如,CPython 编译器(好吧,技术上解释器)的(
我正在努力计算 worklist算法,我不想实现迭代算法,因为它需要很多冗余步骤。 我用来计算实时变量工作列表的算法如下 任何人都可以为下面给出的示例向我解释一下,初始工作列表是什么以及工作列表算法将
我有这部分语法 S ‐> S a | S b a | a | S b c S | S b c b | c S | c b 我需要使用它来创建一些 SD 集,然后在解析表上使用它。 但是,在此之前,我应
是否有人引用了有关着色器编译器/图形驱动程序编译器内部工作原理的文档和研究? 最佳答案 编写一个普通的 C 编译器和编写一个着色器编译器没有太大的区别。编写编译器的标准书是所谓的“龙书”: http:
请问有没有人能给我解释一下句法导向的切线线性码和伴随码的区别。 它与使用编译器推导代码有关。 我知道它们是在程序中推导数学方程式的不同方法,但是,我不知道如何解释它们。 提前致谢。 问候。 最佳答案
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 7年前关闭。 Improve this questi
在编译器数据流分析中,变量的有效范围与其达到定义之间有什么区别?两者似乎都指的是同一件事... 最佳答案 它们是完全不同的东西,我建议您回过头来重新阅读那些使您感到困惑的定义。除其他事项外,对于使用给
我目前正在为一种非常有限的面向对象语言开发编译器。我想将所有值视为对象,这些值上的运算符将作为方法实现。编译器将程序转换为基于堆栈的虚拟机的汇编程序。 在编译期间,我将整数文字转换为特殊“整数”类的对
给定抽象语法树,我被要求编写一个程序来构建输入程序代码的数据流图。我在网上搜索数据流图的定义,发现一个代码段的数据流分析有很多事情要做。我想知道为给定代码构建数据流图到底需要绘制什么。很感谢任何形式的
一些随机的想法捕获了我,我就是无法摆脱它。我在想,既然现代处理器只是不同种类汇编语言的解释器,那么有没有办法创建一些直接在硬件中实现的高级语言解释器,使用一些 HDL 甚至直接使用逻辑门设计? 同时我
出现在代码生成的寄存器分配阶段的寄存器溢出或溢出代码是什么意思,编译器后端必须将变量分配到内存或寄存器? 最佳答案 Hardware registers是昂贵的(在芯片面积和寻址它们所需的指令位数方面
如果您的 bootstrap 语言编译器运行良好且可维护,为什么要更改它?例如,Go 在 1.5 版本中将其编译器重新编写为自托管,导致 compile times to become much sl
我在 Python Lisp 编译器和一些 C 链接器的源代码中看到了这个术语。 我的猜测是,修复只是 assembly 例程的一些包装,可确保对齐正确,但我对这里的任何事情都不确定。 最佳答案 “修
我对 VM 在运行时和编译时的优化感兴趣。我认为优化在编译时是最有效和最简单的。 然而,我的想法在某些情况下似乎是错误的。这在 Steve Yeggie's statement quoted by D
如果您正在构建一个编译器,那么在 AST 级别进行哪种优化是最好的? 最佳答案 大多数情况下,您无法在 AST 级别进行有趣的优化,因为您需要有关数据如何从程序的一个部分流向另一部分的信息。虽然数据流
我是一名优秀的程序员,十分优秀!