.NET Zone is brought to you in partnership with:

Imran is a DZone MVB and is not an employee of DZone and has posted 31 posts at DZone. View Full User Profile

A sample of Onion Architecture with ASP.NET Identity

05.29.2014
| 2669 views |
  • submit to reddit

I was working on a new ASP.NET web application. In this application, I was trying to use Onion Architecture. The application was also using ASP.NET Identity 2.0. Our goal was to create application that will easily replace(if required) the ASP.NET Identity system with any other Identity system or ASP.NET Identity Entity Framework store with any other Identity store without changing anything in our web application.  We were able to create a web application without ASP.NET Identity and OWIN dependency using Onion architecture. 

I have created ASPNETIdentityWithOnion solution using Onion Architecture, because I thought it might be helpful for me and community in future. The web application in this solution contains Microsoft ASP.NET Identity Samples controllers(plus a ProductController) and views but without ASP.NET Identity and OWIN dependency. It might be helpful for users creating a new application using Onion and ASP.NET Identity. 

Existing applications can also take benefit from this solution. Here are some of benefits of using this solution,

  1. The web application uses latest ASP.NET MVC 5.1 framework which include user, role and account management(everything that included in Microsoft ASP.NET Identity Samples) but without ASP.NET Identity and OWIN dependency.
  2. Since there is no dependency on ASP.NET Identity and OWIN, unit testing and mocking of controller become very easy.
  3. The ASP.NET Identity implementation in the solution uses int as Id(identity column) as key instead of string.
  4. If you are looking to replace the Identity store in future without changing anything in the web application.
  5. You might want the ASP.NET Identity system might be replaced in future with different Identity system without changing anything in the web application.
  6. If you are creating a new web application with Onion architecture.
  7. The solution include a generic repository, generic unit of work and generic service with async and pagination support.
  8. The solution also include NLog which log all the EF queries.
  9. The web application will be only depend upon core project.
  10. and more... 

  Please try/see/use the solution and let me know if you have any suggestion.

Published at DZone with permission of Imran Baloch, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)