You can serialize the NHibernate.Configuration and save it, then, in prod.,
you can deserialize de conf.This operation give you more power but
BuildSessionFactory is a little bit time-consumig.

What you are really looking for is something else IMO.
If all tenats has the same mapping and what is changing is only and NOTHING
MORE than the connection string the solution is
IConnectionProvider
<property name="connection.provider"> Blah.YourConnectionProvider, Blah
</property>

To make your work easy you can inherit from DriverConnectionProvider
The property to override is ConnectionString

If you need to inject something (to your IConnectionProvider) follow this:
http://fabiomaulo.blogspot.com/2009/05/nhibernate-ioc-integration.html

2009/10/8 Mick Delaney <[email protected]>

>
> thanks, i've been looking at unhaddins project and taking ideas from
> that.
> the reason i asked about the Connection per tenant vs Factory per
> tenant was that i saw
> on the fluent nhibernate list that someone was doing the connection
> per tenant style.
> i'm going to go with a factory per tenant for now.
> regards.
>
>
>
> On Oct 8, 2:11 pm, Valeriu Caraulean <[email protected]> wrote:
> > First, of course, a separate ISessionFactory per
> database/tenant/connection.
> >
> > Creating ISessionFactory is time consuming operation, so I would not
> > build factories for all tenants at startup in one round/cycle, but
> > build them "on demand" combined with some kind of "cleanup" service
> > that will dispose factories if they weren't used for some time.
> >
> > To see how you can manage multiple ISessionFactories, take a look at
> > NHibernateIntegration facility from Castle stack. That's of course if
> > you're using Castle & Windsor container. NHibernateIntegration will
> > give you next API:
> >      ISessionManager.OpenSession(factoryId);
> > where "factoryId" can be very well your "tenant/tenantId".
> > To use it for building factories dynamically you'll have to override
> > how the facility is initialized to avoid reading of configuration from
> > the XML.
> > NHibernateIntegration also will "help" you manage transactions and
> > will keep your sessions in Web context.
> >
> > Also, for a sample how you can manage multiple ISessionFactories you
> > can look to this post about session factory providers:
> http://fabiomaulo.blogspot.com/2009/09/configure-sessionfactory-provi...
> >
> > Feel free to ask if you have questions. We have pretty same design in our
> app...
> >
> > Cheers,
> >
> > On Thu, Oct 8, 2009 at 2:27 PM, Michael  Delaney <[email protected]>
> wrote:
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > I have a multi-tenant web app using NH. Tenants are added and removed
> > > at runtime and i'm going with the database per tenant approach.
> >
> > > Basically a request comes in like this:
> http://tenant1.host.com/whatever
> >
> > > I have a HttpModule which takes the "tenant1" part and looks up the
> > > Tenant specific config in the Host database. The Host db will contain
> > > a table of Tenants.
> > > This will then validate that the Tenant exists etc.
> >
> > > At this point i need to access the Tenant database. So i need a
> > > SessionFactory to create a Session.
> >
> > > My question is, how should i approach this.
> > > At startup:
> > > I could access the Host db and list out all the Tenants,
> > > Create a session factory for each one and then put them in a
> > > dictionary (to keep the example simple).
> >
> > > Then access like:
> > > ISession session = sessionFactories[TenantName].CurrentSession();
> >
> > > But if I end up with 1000's of Tenants would that be inefficient.
> >
> > > Would I instead:
> > > Use one SessionFactory for the Tenants (they are all using the same
> > > schema after all),
> > > Create a Tenant specific connection and pass it to the SessionFactory,
> > > i.e. Factory.OpenSession(TenantSpecificConnection, ......)
> >
> > > But this complicates the 2nd level cache management.
> >
> > > Any advice???
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to