private ISessionFactory CreateSessionFactory(NHUnitOfWorkFacilityConfig config) { config.ShouldNotBeNull("config"); if (IsDebugEnabled) { log.Debug("SessionFactory를 생성합니다. NHibernate Configuration Filename:" + config.NHibernateConfigurationFilename); } try { var cfg = config.NHibernateConfigurationFilename.BuildConfiguration(); if (config.FactoryAlias.IsNotWhiteSpace()) { cfg.SetProperty(NHibernate.Cfg.Environment.SessionFactoryName, config.FactoryAlias); } foreach (Type mappedEntity in config.Entities) { if (cfg.GetClassMapping(mappedEntity) == null) { cfg.AddClass(mappedEntity); } } var sessionFactory = cfg.BuildSessionFactory(); NHIoC.Register(Kernel, sessionFactory, typeof(NHRepository <>), config.IsCandidateForRepository); if (IsDebugEnabled) { log.Debug("새로운 SessionFactory를 생성하고, Entity들을 등록하고, NHRepository<TEntity> 를 IoC에 등록했습니다."); } return(sessionFactory); } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error(ex); } throw; } }
/// <summary> /// Constructor /// </summary> /// <param name="config"></param> public NHUnitOfWorkFacility(NHUnitOfWorkFacilityConfig config) { config.ShouldNotBeNull("config"); _config = config; }