您好我正在使用MVC 5 + EF6并希望使用Unity 3注册MVC 5应用程序用户和其他特定类型,但我收到错误。
我的上下文类:
public class ProjectContext : IdentityDbContext<ApplicationUser>
{
public ProjectContext()
: base("ProjectContext")
{
}
public DbSet<User> Users { get; set; }
public DbSet<UserProfile> UserProfile { get; set; }
public virtual void Commit()
{
base.SaveChanges();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
控制器类:
public class AccountController : Controller
{
private UserManager<ApplicationUser> UserManager;
private IUserService userService;
private IUserProfileService userProfileService;
public AccountController(IUserService userService, IUserProfileService userProfileService, UserManager<ApplicationUser> userManager)
{
this.userService = userService;
this.userProfileService = userProfileService;
this.UserManager = userManager;
}
}
我在组合中使用了以下注册,但是我遇到了错误
- &GT; ProjectArchitecture.Web.Controllers.AccountController没有带参数()的构造函数。当所有1-4都在上面评论时
- &GT;类型DbConnection没有可访问的构造函数。
Unity注册码
container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>();
container.RegisterType<IRoleStore<IdentityRole>, RoleStore<IdentityRole>>();
container.RegisterType<AccountController>(new InjectionConstructor());
container.RegisterInstance(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ProjectEntities())));