Doubt about using Identity in layers

Asked

Viewed 361 times

2

I created an Aspnet MVC project with Identity to understand how the Identity part works. I made changes to the code, including roles and Claims. I switched this project to a company project, but the project is all done in layers (MVC, Business, Repository, DAL). The problem now is that I am not managing to pass the data to business layer - Repository - DAL. When I debug the code in the Login method, my Signinmanager method always returns "Null". Can anyone help me ? I’m new in the area and I can’t solve the problem.

//
    // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: true);
        switch (result)
        {
            case SignInStatus.Success:
                var user = await UserManager.FindAsync(model.UserName, model.Password);
                await SignInAsync(user, model.RememberMe);
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Login ou Senha incorretos.");
                return View(model);
        }
    }
  • Is there any important reason for this separation?

  • Standard structure of the company.

  • Well, this standard structure is not well served by ASP.NET Identity. The correct thing would be for you to implement the project without the separation and then separate if there is a better reason than the standard structure. Applying a non-VVC concept to an ASP.NET MVC project is subject to these things.

  • Got it. So what you advise is to work with Identity "working separately" from the standard project that?

  • 1

    No, this project should not be layered. Layering is an old practice of another type of project (three-Tier). MVC is not three-Tier. Such a separation is only recommended when you need a very peculiar service architecture (for example, Web API2 + MVC, with caveats). Other than that there’s no reason to separate.

  • The reason for separating Identiy from its presentation layer (MVC) is to promote decoupling so that it is easy in the future to replace it with another Membership system. Considering the history of Microsoft’s Membership systems you can consider that in less than 3 years Identity may already be outdated. If this is not a problem implement it next to the MVC project - if it is a problem, separate it.

  • Got it. But I still thank @Gypsy Morrison Mendez and rcompanhoni for your help.

  • @Raphaelgumm The only proper way to break down by layers is by using control inversion (Ioc). I confess that I still do not have enough knowledge to direct a good answer, but I can point out some links: http://www.c-sharpcorner.com/UploadFile/dacca2/implementioc-using-unity-in-mvc-5/

  • @Alissonsaggiorato already saw this tutorial, I managed to get a very good notion about Identity, however it is all in MVC.

  • No problem @Ciganomorrisonmendez, I’ll take a look at the tutorial and see if I can extract something. Thanks.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.