Best practices for integrating ASP.NET Identity - do they exist?

.net asp.net asp.net-identity entity-framework entity-framework-6

Question

There don't seem to be many (any?) examples of how to achieve this in a decoupled manner, and I'm using ASP.NET Identity with a new website. Not having my domain modelDomainUser class from which you must inheritMicrosoft.AspNet.Identity.EntityFramework.User , thus I developed a class that appears as follows:

public class IdentityUser : User
{
    public virtual DomainUser DomainUser { get; private set; }
}

I relocated theDbSet into the same derived as requested by ASP.NETDbContext class as my as demonstrated in this response domain models. I've provided theIdentityUser single-direction to theDomainUser Through Fluent API as follows:

modelBuilder.Entity<IdentityUser>().HasRequired(iu => iu.DomainUser).WithRequiredPrincipal();

Since I can largely distinguish the issues of authorization and authentication from the behaviors listed in theDomainUser class. Even if it is preferable to classifying them together, this still feels unattractive. In my Domain project, I still have references to the necessary ASP.NET Identity assemblies. To support the navigation attribute, I could make another another project that had simply my IdentityUser class and a reference to my Domain assembly, but that feels cumbersome.

I believe that connecting Identity to the domain should be done in a better, simpler, more modular fashion that avoids tight coupling.

Has anyone thought of a better solution for this? To help with this, I'm hoping to get the attention of folks working on the ASP.NET Identity project (Io Kung et al).

1
12
5/23/2017 10:32:58 AM

Accepted Answer

The truth is that ASP.NET Identity-related assemblies will go with you if you decide to inherit from IdentityUser. Identity cannot be separated from ASP.NET. The original examples in the query don't really help much; in most circumstances, it would probably be best to just inherit fromIdentityUser If you intend to utilizeIdentityUser in the project for your domain.

You can leave the Identity-related classes in your web project and make a separate domain project if you really need to keep your domain project free of ASP.NET-related assemblies.User model in your Domain project and programmatically connect the two, as advised by here.

1
5/23/2017 12:03:09 PM

Popular Answer

A debate about ASP.NET Identity decoupling here is present. Additionally, the open source undertaking SimpleSecurity has instances of how it was put into practice.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow