I have developed a new project based on ASP.Net core. I have moved all my EF code (Models,mappings, DbContext) into a dedicated DAL class library in order to follow the Single responsibility principle of the SOLID rules.
However, I need now to add authentication into my project and would need to add the following into my Startup.cs of my Web project as shown in different tutorials:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
It would involve adding the Microsoft.AspNetCore.Identity.EntityFrameworkCore package and it seems to me that I start breaking the SRP rule by having this package included into my Web project.
Would it possible to move all the identity code (Services, models) as an external class library as I did for the DAL.
ASP.NET Core Identity: Is an API that supports user interface (UI) login functionality. Manages users, passwords, profile data, roles, claims, tokens, email confirmation, and more.
The ASP.NET Identity UserManager class is used to manage users e.g. registering new users, validating credentials and loading user information. It is not concerned with how user information is stored. For this it relies on a UserStore (which in our case uses Entity Framework).
Since identity code has both logic and UI (login/logout, register etc), it needs to be an web app.
There are two options IMO:
The first option makes better option if SRP is important to you. If redirecting to a different URL seems like a bad user experience for you, then the second option may be better.
I'm having my own research about the exact same question, found this thread you can read about the implementation here, although it is not related to .NET Core class library in particular. I believe the principal is similar and you can find your way through it. I also assume that it is not has to be implemented via a web app application as mentioned here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With