移动mvc5帐户控制器code到单独的项目 [英] moving mvc5 account controller code to separate project

查看:219
本文介绍了移动mvc5帐户控制器code到单独的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含WebApi2,MVC5和放大器解决方案; DAL项目(所有RTM)。

I have a solution that contains a WebApi2,MVC5 & DAL project (all RTM).

我想使用正在烘烤的新成员位,但我不喜欢所有的东西帐户正在帐户控制所有。做的文件中的新项目的(asp.net)具有所有连接到该帐户控制器隶属的东西。

I am wanting to use the new membership bits that are now baked-in, but I don't like all the account stuff being all in the account controller. Doing a file new project (asp.net) has all of the membership stuff coupled to the account controller.

在我的DAL我使用EF6,因为我喜欢$ C $理想的C-第一,因为它适合什么,我试图做的。我试图把账户控制器code,并将其移动到我的单独的项目。

Within my DAL I am using EF6 as I like the ideal of code-first as it suits what I am trying to do. I am trying to take the account controller code and move it into my separate project.

在DAL中我的环境是不错的,简单的(从MVC网站所)

My context within the DAL is nice and simple (taken from the MVC site)

public class ApplicationUser : IdentityUser
{
    //a user can belong to multiple stores
    public virtual ICollection<StoreModel> Stores { get; set; }
}


public class DataContext : IdentityDbContext<ApplicationUser>
{
    public DataContext(): base("name=DefaultConnection")
    {
    }
    public DbSet<Business> Businesses { get; set; }
    public DbSet<ConsumerModel> Consumers { get; set; }
    public DbSet<StoreModel> Stores { get; set; }
}

从我内登录我的帐户控制器的ActionResult我尝试

From my account controller within my login actionresult I try

public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
  if (ModelState.IsValid)
     {
      var user = await UserManager.FindAsync(model.UserName, model.Password);
       if (user != null)
       {

这引发错误与 User.FindAsync

的实体类型ApplicationUser不是模型的一部分
  当前上下文。

The entity type ApplicationUser is not part of the model for the current context.

什么我需要做的,以便在当前的环境中使用ApplicationUser?

What do I need to do to allow ApplicationUser to be used in the current context?

推荐答案

我已经做了类似的事情。为了实现关注点分离,我从我的存储库中取出的UserManager,然后在presentation层使用它。存储库内部创建使用内部LoginDbContext从UserStore的的UserManager。这样,的DbContext和商店从控制器分开。

I have done something similar. In order to implement separation of concerns, I fetch the UserManager from my Repository and then use it in the Presentation layer. Repository internally creates the UserManager from UserStore using the internal LoginDbContext. That way, the DbContext and Store are separated from the controller.

这篇关于移动mvc5帐户控制器code到单独的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆