I need to start a new mvc project and as always I have issues about asp identity, never know where to put it!
I plan to organize solution like this:
- ProjectWebUI – mvc app with asp identity framework (made from internet template with authentication)
- ProjectDataAccessLayer – with repository classes that use
dapperas database access technology - ProjectWebAPI – web service
But I have a little confusion and before start coding I need advice from someone more experienced (as until now all my projects were just one project with data access in it):
- Is it good idea to have asp identity inside WebUI project that use standard Entity Framework for data access and use dapper for other data access in separate assembly?
- If asp identity is inside WebUI project will I have some issues to receive authenticated access to WebAPI project?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
That’s how I organized one of my recent projects:
-
Common— this is a core project in the solution. It contains all the domain entities along with theApplicationUserclass that inherits fromIdentityUserclass from ASP.NET Identity Framework. Normally this class is found in a new ASP.NET MVC project template; I decided to put it into the core library because it represents a common entity that may be required for higher layers and levels of abstraction. Because of this,CommonreferencesMicrosoft.AspNet.Identity.CoreandMicrosoft.AspNet.Identity.EntityFrameworkassemblies. -
DataAccess— this project referencesCommonlibrary and contains Entity FraneworkDatabaseContextas well as some repositories. I use Code First approach and myDatabaseContextis inherited fromIdentityDbContext<ApplicationUser>. So it gives me a nice database structure with tables forUsersandRolesand other ASP.NET Identity stuff as well as tables that represent my custom business entities from theCommonproject, so I can easily connect my custom entities with Identity objects. -
WebApi— this is aRESTservice that usesDataAccessandCommonlibraries. All the authorization and authentication job is done here using token authentication. -
Web— this is just a web client for myRESTservice.
So, to answer your question: you can keep your ASP.NET Identity classes and Entity Framework database context inside a single project if it is really small and easy to manage; otherwise, it would be better to step away from the default project template and introduce layers for each major application module.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0