Question

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...
Was it helpful?

Solution

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.

OTHER TIPS

There is also a NHibernate based Membership provider at CodePlex

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top