asp.net - 结构图 x Asp.net 标识

标签 asp.net structuremap identity

我在注册一些像这样的依赖项时遇到问题。

No default Instance is registered and cannot be automatically determined for type 'IUserStore<ApplicationIdentityUser, Int32>'

There is no configuration specified for IUserStore<ApplicationIdentityUser, Int32>


1.) new UserManager`2(*Default of IUserStore<ApplicationIdentityUser, Int32>*)
2.) UserManager<ApplicationIdentityUser, Int32>
3.) Instance of UserManager<ApplicationIdentityUser, Int32>
4.) new ApplicationUserManager(*Default of UserManager<ApplicationIdentityUser, Int32>*, *Default of IAuthenticationManager*)
5.) MyClinic.Infra.Data.Identity.ApplicationUserManager
6.) Instance of MyClinic.Core.Identity.IApplicationUserManager (MyClinic.Infra.Data.Identity.ApplicationUserManager)
7.) new AccountController(*Default of IApplicationUserManager*)
8.) MyClinic.Web.Controllers.AccountController
9.) Instance of MyClinic.Web.Controllers.AccountController
10.) Container.GetInstance(MyClinic.Web.Controllers.AccountController)

有人可以帮我吗?

我的账户控制人是:

public class AccountController : Controller
{
    private IApplicationUserManager _userManager;
    public AccountController(IApplicationUserManager userManager)
    {
        _userManager = userManager;
    }
}

我的应用程序用户管理器:

public class ApplicationUserManager : IApplicationUserManager
{
    private readonly UserManager<ApplicationIdentityUser, int> _userManager;
    private readonly IAuthenticationManager _authenticationManager;
    private bool _disposed;

    public ApplicationUserManager(UserManager<ApplicationIdentityUser, int> userManager, IAuthenticationManager authenticationManager)
    {
        _userManager = userManager;
        _authenticationManager = authenticationManager;
    }
}

最佳答案

您需要将以下内容添加到结构图容器中才能使用 Asp.net Identity。

For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
For<DbContext>().Use(() => new ApplicationDbContext());
For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);

另外,你还需要安装包

Microsoft.Owin.Host.SystemWeb

让扩展方法 GetOwinContext() 出现在 HttpContext.Current 上

关于asp.net - 结构图 x Asp.net 标识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26707450/

相关文章:

asp.net - 子目录中的 robots.txt

c# - Azure Web 表单和 HTML 到 PDF 转换器

c# - 使用 StructureMap 的 Autowiring 器

c# - 在结构图中为 DecorateAllWith() 方法定义过滤器 3

使用 "identity"生成器时出现 Hibernate 异常 - 如何使用

sql-server - sql server 导入导出向导 - 启用身份插入不起作用

c# - 如何在 CSS 中传递参数,然后如何在 ASP.NET 中对该参数应用 if..else?

c# - StructureMap 通用 Ctor 命名实例

database - 插入时 DB2 覆盖自动生成的键

c# - 在生产 Web 应用程序中给出解析错误