Testing asp.net mvc id from user interface level

I am creating a new MVC application. Usually I always have a project structure that looks like this:

  • DAL level (objects and repositories
  • Service Level (business oriented service calls that coordinate between api / Frontend and DAL)
  • Frontend, it can be a web API or an MVC application.

My problem is that I always get a dirty implementation for user management. I used membership providers and thus made this part not as enjoyable as it should be. Now I saw a new implementation of Identity, and I really liked it. I did some hot searches to distract him to the backend, but with no result.

I found this post on project structuring, but it didn’t give a real answer: ASP.NET MVC 5 decoupling Identification, allowing to implement a multi-level application

I was hoping that someone could provide me with some hints or a white paper on how to abstract all input and authentication into a backend slot.

+8
c # asp.net-mvc asp.net-identity
source share
2 answers

You can create a fairly simple interface in the business layer. It will look something like this:

public interface IAuthenticationService { bool VerifyPassword(User user, string password); bool SignIn(User user); void SignOut(); } 

You can implement this interface using ASP.NET Identity in the business layer, at the user interface level or at a separate infrastructure level.

This interface can be implemented by various technologies that can be registered at runtime by the IoC container, and you can simply use the interface in your AccountController , for example. Since the scope of authentication often changes (every year or so), this allows you to switch more easily.

+4
source share

Technically, this is already abstracted. The UserManager class, central to ASP.NET Identity, is a wrapper around the database context. Now, if you talk about abstracting it further, so that references to ASP.NET Identity are not contained in your code at all, I would say that this is unnecessary, but still possible. You can simply transfer all this code to your service level, and then make calls to your service to use the appropriate methods on the UserManager . However, you still need to convey your context so that you do not create multiple instances, which will surely bite you.

+4
source share

All Articles