asp.net-mvc-5 – 依赖注入结构图ASP.NET Identity MVC 5

我正在使用新的ASP.NET MVC 5身份验证框架进行身份验证.传统上我使用StructureMap进行依赖注入,但是我在连接新的AccountController时遇到了问题.

我的AccountController构造函数如下所示:

public AccountController()
        : this(new UserManager<Ompuser>(new UserStore<Ompuser>(new OmpDbContext())))
    {    

    }

    public AccountController(UserManager<Ompuser> userManager)
    {
        UserManager = userManager;
    }

我的StructureMap配置如下所示:

public static class IoC {
    public static IContainer Initialize() {
        ObjectFactory.Initialize(x =>
                    {
                        x.Scan(scan =>
                                {
                                    scan.TheCallingAssembly();
                                    scan.WithDefaultConventions();
                                });

                        //x.Register<IUserStore<Ompuser>>(() =>
                        //    new UserStore<Ompuser>(new OmpDbContext()));

                        x.For<OMPEntities>().HttpContextScoped();

                    });
        return ObjectFactory.Container;
    }
}

当我运行该项目我得到以下错误

Activation error occured while trying to get instance of type
AccountController,key “”

任何关于如何新建UserManager对象进行构建注入的想法?我试过搜索,但在那里找不到太多的指导.

解决方法

将以下代码添加到容器初始化方法中.
x.For<Microsoft.AspNet.Identity.IUserStore<ApplicationUser>>()
.Use<Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>>();

x.For<System.Data.Entity.DbContext>().Use(() => new ApplicationDbContext());

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....