A sample of Onion Architecture with ASP.NET Identity

 


                     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.


7 Comments

  • Nice Imran.
    Looks like quite a effort require to understand it. Weekend seems to be dedicated for this one :)

  • I was looking into the Onion Architecture myself to use for my projects. Please keep us updated on this one.

  • Gгeеtings! Very helpful advice in this particular article!
    It is the little changes which will make the most important changes.
    Thanks fοr sharing!

  • Sir, this post is pure quality, I downloaded the solution and I was extremely impressed the way you implemented the Onion Architecture using the latest technologies from the .NET realm, you made me realize how much of a noob I still am but at the same time motivate me to learn more, I recently found out about the Onion Architecture and I've been downloading code samples so I can figure out how can I implement it, yours will definitely help me get started, although there a lot of things I don't fully understand, it helps get a better picture of how does this architecture works, I can't thank you enough for sharing this valuable masterpiece.

    I will be paying close attention to your future post, but for now, I just wanna say a BIG THANK YOU for unleashing this fine craftsmanship of code.

    Sincerely, your new biggest fan, Rene from Mexico :)

  • @Rene,
    Thanks

  • This is a great tutorial. I have been a fan of this architecture for a long time now. I did alot of researching, watch videos and read some blog posts to sink it down. But your demo app concretize everything i've read. I appreciate this accompanying demo app and the efforts you put into it. Weldone.

  • @IbrahimShaib

    Thanks

Comments have been disabled for this content.