/// <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);
 }
        /// <summary>
        /// Create new session in testing context
        /// </summary>
        /// <returns></returns>
        public virtual ISession CreateSession()
        {
            var interceptor = NHIoC.ResolveInterceptor();

            return(interceptor != null
                       ? TestContext.SessionFactory.OpenSession(interceptor)
                       : TestContext.SessionFactory.OpenSession());
        }
            /// <summary>
            /// Create new session in testing context
            /// </summary>
            /// <returns></returns>
            public override ISession CreateSession()
            {
                //need to get our own connection, because NH will try to close it as soon as possible, and we will lose the changes.
                var connection
                    = ((ISessionFactoryImplementor)TestContext.SessionFactory).ConnectionProvider.GetConnection();

                // IInterceptor interceptor = UnitOfWorkTestContext.ResolveInterceptor();
                var interceptor = NHIoC.ResolveInterceptor();

                if (interceptor != null)
                {
                    TestContext.SessionFactory.OpenSession(connection, interceptor);
                }

                return(TestContext.SessionFactory.OpenSession(connection));
            }
Пример #4
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;
            }
        }