Esempio n. 1
0
        protected virtual ISessionFactory CreateFactory()
        {
            Logger.Info("Loading Configuration...");

            try
            {
                var config = new global::NHibernate.Cfg.Configuration();

                var strat = new EnhancedNamingStrategy
                {
                    TablePrefix = Settings.TablePrefix
                };
                config.SetNamingStrategy(strat);

                config.SetProperties(Settings.Properties);
                foreach (var directory in Settings.MappingDirectories)
                {
                    var dir = new DirectoryInfo(directory);
                    config.AddDirectory(dir);
                }
                foreach (var file in Settings.MappingFiles)
                {
                    config.AddFile(file);
                }
                foreach (var assembly in Settings.MappingAssemblies)
                {
                    config.AddAssembly(assembly);
                }

                return(config.BuildSessionFactory());
            }
            catch (Exception x)
            {
                Logger.Error(x, "Error while loading configuration.");
                throw;
            }
            finally
            {
                Logger.Info("Configuration successfully loaded.");
            }
        }