问题描述
我有一个通用的ASP.NET(MVC)应用程序,使用的NHibernate作为模型持久层,和ASP.NET成员资格/角色/用户信息服务为用户管理层。
的问题是什么可以认为是创建域数据和用户之间联反应的最佳做法。 (例如是我想创建一个论坛系统我想每个主题/帖子链接到一个特定的用户,并希望显示在每个请求的用户)。
这是我一直在思考的posiibilites:
-
在存放NHibernate的用户ID(就像在所有的领域类(帖子,主题等GUID列)需要引用一个用户),并使用各自的getUser你所需要的用户名时的GUID(这可能会导致在n + 1个查询)
乙变种:或者存储的用户名过于
- 使用同一个数据库,并创建一个只读的NHibernate maintaned域对象的用户,映射到相同的数据M / R / P服务做的。
- 忘了M / R / P和创建基于NHibernate的一个独立的用户管理服务
- 忘掉都和使用J2EE /回报率/ Merb的/ Django的/等。 (请不要挑这个选项:))
- 等...
我会去的第2步(差不多,因为它并不一定需要是只读),并创建了NHibernate的一个自定义的成员提供。
要节省时间,你可以使用现有的像的。
使用您保持NHibernate的(延迟加载等)的全部功能,并享受M / R / P服务了。
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...
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和ASP.NET成员资格/角色/配置文件服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!