Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SessionFactory - one factory for multiple databases

We have a situation where we have multiple databases with identical schema, but different data in each. We're creating a single session factory to handle this.

The problem is that we don't know which database we'll connect to until runtime, when we can provide that. But on startup to get the factory build, we need to connect to a database with that schema. We currently do this by creating the schema in an known location and using that, but we'd like to remove that requirement.

I haven't been able to find a way to create the session factory without specifying a connection. We don't expect to be able to use the OpenSession method with no parameters, and that's ok.

Any ideas? Thanks Andy

like image 752
Andy Avatar asked Nov 06 '22 09:11

Andy


1 Answers

Either implement your own IConnectionProvider or pass your own connection to ISessionFactory.OpenSession(IDbConnection) (but read the method's comments about connection tracking)

like image 147
Mauricio Scheffer Avatar answered Nov 15 '22 08:11

Mauricio Scheffer