/// <summary>
 /// NHibernate Session Factory 초기화 작업에 추가할 내용들을 정의한다.
 /// </summary>
 /// <param name="cfg"></param>
 /// <param name="sessionFactory"></param>
 public void Initialized(Configuration cfg, ISessionFactory sessionFactory)
 {
     NHIoC.Register(IoC.Container,
                    sessionFactory,
                    typeof(NHRepository <>),
                    _isCandidateForRepository);
 }
示例#2
0
        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;
            }
        }