2009-11-21 8 views
0

나중에 ObjectFactory.GetNamedInstance ("MyNHConfiguration")를 할 수 있도록 다음을 다시 작성할 수 있습니까? "구성"은 ExposeConfiguration 아래의 "cfg"변수에 있습니다.구조체의 도움이 필요합니다

  ForRequestedType<ISessionFactory>() 
      .CacheBy(InstanceScope.Singleton) 
      .AddInstances(x => x.ConstructedBy(() => 
         Fluently.Configure() 
           .Database(MsSqlConfiguration.MsSql2005 
            .AdoNetBatchSize(10) 
            .Driver("NHibernate.Driver.SqlClientDriver") 
            .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle") 
            .UseOuterJoin() 
            .ConnectionString(@"Server=.\SQLEXPRESS;User Id=xxcxcca;Password=password;Database=cccvddd;") 
            .ShowSql() 
            .CurrentSessionContext("thread_static")) // CHANGE THIS FOR WEB 
           .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MetaProject>()) 
           .ExposeConfiguration(
                cfg =>{ 
                                  cfg.SetProperty(
                   Environment.TransactionStrategy, 
                   typeof (AdoNetTransactionFactory).FullName); 
                  cfg.SetProperty(Environment.GenerateStatistics, "true"); //REMOVE FOR LIVE 
                }) 

           .BuildSessionFactory()) 
           .WithName("MySessionFactory")); 

답변

0

다음은 내가 한 방법입니다. 그것이 최선의 방법인지 모른다. 그러나 그것이 효과적 일까.

ForRequestedType<FluentConfiguration>() 
      .CacheBy(InstanceScope.Singleton) 
      .TheDefault.Is.ConstructedBy(
      ()=>Fluently.Configure() 
           .Database(MsSqlConfiguration.MsSql2005 
            .AdoNetBatchSize(10) 
            .Driver("NHibernate.Driver.SqlClientDriver") 
            .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle") 
            .UseOuterJoin() 
            .ConnectionString(@"Server=.\SQLEXPRESS;User Id=epitka;Password=password;Database=dnn49;") 
            .ShowSql() 
            .CurrentSessionContext("thread_static")) // CHANGE THIS FOR WEB 
           .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MetaProject>()) 
           .ExposeConfiguration(
                cfg =>{ 
                  cfg.SetProperty(
                   Environment.TransactionStrategy, 
                   typeof (AdoNetTransactionFactory).FullName); 
                  cfg.SetProperty(Environment.GenerateStatistics, "true"); //REMOVE FOR LIVE 
                }) 
      ) 
      .WithName("SharMod_FluentConfiguration"); 

     ForRequestedType<Configuration>() 
      .TheDefault.Is.ConstructedBy(
      () => 
       { 
        var fc =ObjectFactory.GetInstance<FluentConfiguration>(); 
        return fc.BuildConfiguration(); 
       }) 
      .WithName("SharpMod_Configuration"); 

     //SharpMod_SessionFactory 
     ForRequestedType<ISessionFactory>() 
      .CacheBy(InstanceScope.Singleton) 
      .AddInstances(x => x.ConstructedBy(() => 
           ObjectFactory.GetNamedInstance<FluentConfiguration>("SharMod_FluentConfiguration") 
           .BuildSessionFactory()) 
           .WithName("SharpMod_SessionFactory"));