加入 nhibernate 和 ASP.NET 成员/角色/配置文件服务的最佳实践
我有一个通用的 ASP.NET (MVC) 应用程序,它使用 NHibernate 作为模型持久层,并使用 ASP.NET 成员/角色/配置文件服务作为用户管理层。
问题是什么可以被视为在域数据和用户之间创建链接的最佳实践。 (例如,我想创建一个论坛系统,我想将每个主题/帖子链接到特定用户,并希望在每个请求时显示该用户)。
这些是我一直在考虑的可能性:
将用户 ID 存储在 NHibernate 中(就像在需要引用用户的所有域类(帖子、主题等)中拥有 Guid 列)并每次使用 GetUser您需要 guid 中的用户名(这可能会导致 n+1 次查询)
B 变体:或者也存储用户名。
使用相同的数据库,并创建一个只读的 NHibernate 维护的域对象 User,它映射到与 M/R/P 服务相同的数据。
忘记 M/R/P,创建一个基于 NHibernate 的单独的用户管理服务
忘记两者并使用 J2EE/RoR/merb/DJango/etc。 (请不要选择此选项:))
其他...
I've got a generic ASP.NET (MVC) application, that uses NHibernate as the model persistence layer, and ASP.NET Membership/role/profile services as the user management layer.
The question is what can be considered as the best practice to create linkings between the domain data and the users. (For example is I want to create a forum system I want to link each topics/posts to a specific user, and want to display the user at each request).
These are the posiibilites I've been thinking of:
Store the user ID in NHibernate (like having a Guid column in all your domain classes (Posts, Topics etc.) that needs to reference a User) and use GetUser each time you need the name of the user from the guid (which might result in n+1 queries)
B variant: Alternatively store the user name too.
Use the same database, and create a read-only NHibernate maintaned domain object User, that maps to the same data as the M/R/P services do.
Forget about M/R/P and create a separate user management service based on NHibernate
Forget about both and use J2EE/RoR/merb/DJango/etc. (please don't pick this option :) )
other...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会执行第 2 步(几乎是这样,因为它不一定需要只读)并为 NHibernate 创建一个自定义成员资格提供程序。
为了节省时间,您可以使用现有的一个,例如 曼努埃尔·阿巴迪亚。
这样您就可以保留 NHibernate 的全部功能(延迟加载等)并享受 M/R/P 服务。
I would go for step 2 (almost, as it does not necessarily needs to be readonly) and create a custom membership provider for NHibernate.
To save time you can use an existing one like the one from Manuel Abadia.
With that you keep the full power of NHibernate (lazy loading, etc.) and enjoy M/R/P services too.
还有一个基于 NHibernate 的会员提供程序,位于 CodePlex
There is also a NHibernate based Membership provider at CodePlex
如果您想在 asp.net 会员 API 之上构建自己的提供程序,来自 rolla 的 4 个人有一篇很棒的文章:https://web.archive.org/web/20211020114106/https://www.4guysfromrolla.com/articles/110310-1.aspx
4 guys from rolla have an excellent post if you want to buil your own provider on top of the asp.net membership API : https://web.archive.org/web/20211020114106/https://www.4guysfromrolla.com/articles/110310-1.aspx