Search code examples
.net-coreasp.net-identity

.NET Core Identity. Use one context or two?


I am struggling with a basic problem. Keep my ASP.NET Core Identity context separate from my business context or combine the two.

Philosophically, it seems good to keep them separate. If I want to upgrade .NET Core at some point in the future, I have fewer issues if my identity context is separate.

Practically, it seems like a good idea to combine them. Otherwise, I am creating another user table or doing some weird workarounds to get user information from navigation properties.

How do you handle Identity contexts in .NET Core?


Solution

  • In my experience, its a good idea to keep identity context, separate from your business logic.

    • You will probably have to do some expensive encryption and other things on your identity database. There may be no need to apply such encryption to your business data
    • You might choose to replace, have separate backup plans and recovery plans for your identity database. non-identity database may have its own plan.
    • More importantly, one fine day, you might decide and go with a 3rd party auth provider and forget about managing identity yourself. At which point, you may do some migration, throw away the identity database as it is no longer needed.

    So, yes, best to use different context/database.

    note : I am assuming, each context is linked to a different database. This is a given, but, for the sake of clarity, putting it here.