Best practice to join nhibernate and ASP.NET membership/role/profile services

Go To StackoverFlow.com

12

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:

  1. 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.

  2. 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.
  3. Forget about M/R/P and create a separate user management service based on NHibernate
  4. Forget about both and use J2EE/RoR/merb/DJango/etc. (please don't pick this option :) )
  5. other...
2009-06-16 08:34
by SztupY
What do you mean by "store user ID in NHibernate" - epitka 2009-06-16 13:03
I mean I store the guid of the user for example in the Topic/Post/Comment/etc class, and use GetUserName from the membershipprovider to get it's real name from the guid - SztupY 2009-06-16 13:11


6

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.

2009-06-16 15:40
by Michal


2

There is also a NHibernate based Membership provider at CodePlex

2010-10-18 21:13
by miguelv


1

4 guys from rolla have an excellent post if you want to buil your own provider on top of the asp.net membership API : http://www.4guysfromrolla.com/articles/110310-1.aspx

2010-11-25 13:23
by VinnyG
Ads