Yes, you can prefix the cache-region at run-time. On Mon, Oct 18, 2010 at 12:07 PM, Maorino <[email protected]> wrote:
> Hi, thanks for the reply. > I found a different solution, i will describe it next. I wanted to > state that the reason i didn't use the IConnectionProvider is because > i also need to change the cache region, is there a similar solution > for that also? > > In my solution, after configuring the NHibernateConfiguration class in > my initializing class, i serizlized it and saved it to cache in > memory. > When a different factory decleration with the same settings arrives, i > load the serialized data and only change the connection string and > save the factory. > > It's important to know, that i have a factory ready in each time to > each database. > > Thanks, > > Maorino. > > On Oct 14, 5:35 pm, Fabio Maulo <[email protected]> wrote: > > If alls DBs has the same set of domain-entities what you need is a > > IConnectionProvider to dinamically change the connection to a specific > > DB. > > Have a look to the "how to" wiki on nhforge.org and you will find the > > implementation > > > > -- > > Fabio Maulo > > > > El 14/10/2010, a las 10:57,Maorino<[email protected]> escribió: > > > > > > > > > Hi, > > > > > As part of my system initialization i have to connect to a large > > > number of databases (over 20). > > > I created a class, factory of session factory, that according to a > > > unique key will return a session factory. > > > > > I use a default NHibernate config file, load it, and change all the > > > things according to each key in that collection (change the connection > > > string, change the mapping assemblies, cache region name etc.) > > > > > This initialization takes a huge amount of time (about 3.5 minutes to > > > connect to 10 databases). > > > After a small research, i found out that what's taking so long, is > > > when i add the mapping assemblies to the configuration (i have about > > > 10 asseblies to each database, but they are the same for each > > > database... so maybe there's something i can do in here?!), and the > > > cfg.BuildSessionFactory() takes only 2-3 seconds. > > > > > Is there a way i can significantly reduce the time for adding the > > > assemblies to the configuration (cfg.AddAssembly(assembly.Name)) ? > > > > > BTW, > > > > > It doesn't matter if i dynamicly add the assemblies or add them as > > > part of the default configuration. > > > > > Thanks in advance, > > > > > Here is the code that creates one unit of work factory according to > > > the configuration it recieves as a parameter: > > > > > private ISessionFactory createUnitOfWorkFactory(UnitOfWorkKey > > > sessionFactoryKey, UnitOfWorkFactoryElement factoryElement, bool > > > isFromConfigurationFile) > > > { > > > try > > > { > > > ISessionFactory sessionFactory; > > > > > NHibernateConfiguration cfg = new > > > NHibernateConfiguration(); > > > > > // Add the connection string according to the database > > > type specified in the key > > > Dictionary<string, string> properties = new > > > Dictionary<string, string>(); > > > > > if (!File.Exists(factoryElement.FactoryConfigPath)) > > > { > > > throw new FileNotFoundException( > > > formatException("The config file at '" + > > > factoryElement.FactoryConfigPath + "' could not be found", > > > sessionFactoryKey)); > > > } > > > > > string connectionString = > > > factoryElement.ConnectionString; > > > > > // The configuration file doesn't contain concrete > > > connection but a connection name that need to be fetched > > > // from configuration > > > if (isFromConfigurationFile) > > > { > > > // Fetch the connection string according to it's > > > name from the configuration settings > > > ConnectionStringSettings connectionSettings = > > > > > > ConfigurationManager.ConnectionStrings[factoryElement.ConnectionString]; > > > > > if (connectionSettings == null) > > > { > > > throw new HibernateException(formatException > > > (string.Format("Could not find named > > > connection string {0}", factoryElement.ConnectionString), > > > sessionFactoryKey)); > > > } > > > > > connectionString = > > > connectionSettings.ConnectionString; > > > } > > > properties.Add(NHibernateEnvironment.ConnectionString, > > > connectionString); > > > > > properties.Add(NHibernateEnvironment.CacheRegionPrefix, > > > factoryElement.CacheRegionName); > > > > > cfg.AddProperties(properties); > > > > > // Add the assemblies of the entities according to the > > > configuration file > > > cfg.Configure(factoryElement.FactoryConfigPath); > > > addMappingAssemblies(ref cfg); > > > // Now that we have our key object, create a new > > > SessionFactory > > > sessionFactory = cfg.BuildSessionFactory(); > > > > > if (sessionFactory == null) > > > { > > > throw new > > > InvalidOperationException(formatException("cfg.BuildSessionFactory() > > > returned null.", sessionFactoryKey)); > > > } > > > > > return sessionFactory; > > > } > > > catch (Exception exp) > > > { > > > Logger.Logger.WriteLog(Severity.Fatal, this, "Error > > > while trying to build unit of work factory", exp); > > > return null; > > > } > > > } > > > > >Maorino. > > > > > -- > > > 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]<nhusers%[email protected]> > . > > > For more options, visit this group athttp:// > groups.google.com/group/nhusers?hl=en.- Hide quoted text - > > > > - Show quoted text - > > -- > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- 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.
