ASP.NET 2.0 Custom membership provider using NHibernate
-
I am attempting to write a custom membership provider using NHibernate but come across a problem. With hibernate you need to instantiate and set up a Configuration object to get at an ISessionFactory interface, the problem is configuration is expensive to do for every database request so the usual thing to do is to configure it once then keep a static reference to the ISessionFactory. Whilst debugging my MembershipProvider using the website admin tool I noticed that Initialize() was called every time a new page loaded after the add user and update users features, considering I use the Initialize() method to configure hibernate and store a reference to an ISessionFactory interface I noticed that it was always re-creating the ISessionFactory. It states in the provider toolkit pages: Providers are loaded when the application using them first accesses a feature of the corresponding service, and they're instanced just once per application (that is, per application domain). The lifetime of a provider roughly equals the lifetime of the application, so one can safely write "stateful" providers that store state in fields. This one-instance-per-application model is convenient for persisting data across requests, but it has a downside. That downside is described in the next section. If this is the case then Initialize() is the perfect place to setup my NHibernate session factory. I was wondering if this is just the nature of the web admin tool considering it runs in as a different web application on a different port (in the visual studio development server). anyway, if anyone could shed some light on this I would be very happy to hear about it. regards Fluxtah