.NET核心身份.使用一个或两个上下文? [英] .NET Core Identity. Use one context or two?

查看:42
本文介绍了.NET核心身份.使用一个或两个上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个基本问题而苦苦挣扎.将我的ASP.NET Core Identity上下文与业务上下文分开,或将两者结合在一起.

从哲学上讲,将它们分开似乎很好.如果我想在将来的某个时候升级.NET Core,那么如果我的身份上下文是单独的,那么我遇到的问题就更少了.

实际上,将它们组合起来似乎是一个好主意.否则,我将创建另一个用户表或执行一些怪异的变通办法,以从导航属性中获取用户信息.

您如何在.NET Core中处理身份上下文?

解决方案

以我的经验,保持身份上下文独立于业务逻辑是一个好主意.

  • 您可能必须对身份数据库进行一些昂贵的加密和其他操作.可能无需对您的业务数据进行这种加密
  • 您可能会选择替换,并为您的身份数据库设置单独的备份计划和恢复计划.非身份数据库可能有自己的计划.
  • 更重要的是,在晴朗的一天,您可能会决定并与第三方身份验证提供商一起去,而不必亲自管理身份.此时,您可以进行一些迁移,丢弃不再需要的身份数据库.

所以,是的,最好使用不同的上下文/数据库.

注意:我假设,每个上下文都链接到不同的数据库.这是给定的,但是为了清楚起见,将其放在此处.

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?

解决方案

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.

这篇关于.NET核心身份.使用一个或两个上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆