private static ISessionFactory CreateSessionFactoryFor(
            IEnumerable<string> mappingAssemblies, 
            AutoPersistenceModel autoPersistenceModel, 
            Configuration cfg, 
            IPersistenceConfigurer persistenceConfigurer)
        {
            var fluentConfiguration = Fluently.Configure(cfg);

            if (persistenceConfigurer != null)
            {
                fluentConfiguration.Database(persistenceConfigurer);
            }

            fluentConfiguration.Mappings(
                m =>
                    {
                        foreach (var mappingAssembly in mappingAssemblies)
                        {
                            var assembly = Assembly.LoadFrom(MakeLoadReadyAssemblyName(mappingAssembly));

                            m.HbmMappings.AddFromAssembly(assembly);
                            m.FluentMappings.AddFromAssembly(assembly).Conventions.AddAssembly(assembly);
                        }

                        if (autoPersistenceModel != null)
                        {
                            m.AutoMappings.Add(autoPersistenceModel);
                        }
                    });

            fluentConfiguration.ExposeConfiguration(
                e =>
                    {
                        e.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[]
                            {
                                new DataAnnotationsEventListener()
                            };
                        e.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[]
                            {
                                new DataAnnotationsEventListener()
                            };
                    });

            return fluentConfiguration.BuildSessionFactory();
        }
        private static Configuration ConfigureNHibernate(string cfgFile, IDictionary<string, string> cfgProperties)
        {
            var cfg = new Configuration();

            if (cfgProperties != null)
            {
                cfg.AddProperties(cfgProperties);
            }

            if (string.IsNullOrEmpty(cfgFile) == false)
            {
                return cfg.Configure(cfgFile);
            }

            if (File.Exists("Hibernate.cfg.xml"))
            {
                return cfg.Configure();
            }

            return cfg;
        }
        public static Configuration AddConfiguration(
            string factoryKey, ISessionFactory sessionFactory, Configuration cfg, string validatorCfgFile)
        {
            Check.Require(
                !SessionFactories.ContainsKey(factoryKey), 
                "A session factory has already been configured with the key of " + factoryKey);

            SessionFactories.Add(factoryKey, sessionFactory);

            return cfg;
        }
        public static Configuration AddConfiguration(
            string factoryKey, 
            string[] mappingAssemblies, 
            AutoPersistenceModel autoPersistenceModel, 
            Configuration cfg, 
            string validatorCfgFile, 
            IPersistenceConfigurer persistenceConfigurer)
        {
            var sessionFactory = CreateSessionFactoryFor(
                mappingAssemblies, autoPersistenceModel, cfg, persistenceConfigurer);

            return AddConfiguration(factoryKey, sessionFactory, cfg, validatorCfgFile);
        }
Ejemplo n.º 5
0
 public ConfigureUsingInstance(Configuration configuration, HelpXmlDocumentation helpXmlDocumentation)
 {
     _configuration = configuration;
     this.helpXmlDocumentation = helpXmlDocumentation;
 }
Ejemplo n.º 6
0
        private static void ConfigureNHibernateValidator(Configuration cfg, string validatorCfgFile)
        {
            var engine = new ValidatorEngine();

            if (string.IsNullOrEmpty(validatorCfgFile))
            {
                engine.Configure();
            }
            else
            {
                engine.Configure(validatorCfgFile);
            }

            // Register validation listeners with the current NHib configuration
            cfg.Initialize(engine);

            ValidatorEngine = engine;
        }