【问题标题】:AspNetCore.Identity UserManager in Repository Pattern存储库模式中的 AspNetCore.Identity UserManager
【发布时间】:2017-08-30 16:34:28
【问题描述】:

我想将 Repository 与 AspNetCore.Identity UserManager 一起使用。但是在 Controller 中定义时出现错误。

存储库

public class TestRepository
{
    private readonly UserManager<tblApplicationUser> _userManager;

    public TestRepository(UserManager<tblApplicationUser> userManager)
    {
        this._userManager = userManager;
    }
}

控制器:

    private TestRepository _testRepository;

    public TestController()
    {
        this._testRepository = new TestRepository(new UserManager<tblApplicationUser>);
    }

我在 new UserManager

的控制器中遇到错误

【问题讨论】:

  • 在控制器中包含 usermanager 命名空间
  • Microsoft.AspNetCore.Identity 命名空间已添加。
  • 你的意思是编译错误?请将错误添加到问题中。

标签: asp.net-core asp.net-identity repository-pattern


【解决方案1】:

您似乎在最后一个大括号之前缺少大括号(对于 UserManager 构造函数)?

this._testRepository = new TestRepository(new UserManager<tblApplicationUser>()); 

您应该让 DI 处理 UserManager 和 Repository 的实例化。您可以查看 this article on official docs 的 ASP.NET Core。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多