2009-11-21 5 views
0

Comment puis-je réécrire la suite afin que je puisse faire ObjectFactory.GetNamedInstance ("MyNHConfiguration") ultérieurement. "Configuration" est dans la variable "cfg" sous ExposeConfiguration lambdaAide de StructureMap requise

  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")); 

Répondre

0

Voici comment je l'ai fait. Je ne sais pas si c'est la meilleure façon, mais cela fonctionne

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"));