Nhibernate 需要StructureMap帮助吗

Nhibernate 需要StructureMap帮助吗,nhibernate,fluent-nhibernate,structuremap,Nhibernate,Fluent Nhibernate,Structuremap,我如何重写以下内容,以便以后可以执行ObjectFactory.GetNamedInstance(“MyNHConfiguration”)。“配置”位于ExposeConfiguration lambda下的变量“cfg”中 ForRequestedType<ISessionFactory>() .CacheBy(InstanceScope.Singleton) .AddInstances(x => x.Co

我如何重写以下内容,以便以后可以执行ObjectFactory.GetNamedInstance(“MyNHConfiguration”)。“配置”位于ExposeConfiguration lambda下的变量“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"));
ForRequestedType()
.CacheBy(InstanceScope.Singleton)
.AddInstances(x=>x.ConstructedBy(()=>
fluent.Configure()
.数据库(MsSqlConfiguration.MsSql2005
.ADONbatchSize(10)
.Driver(“NHibernate.Driver.SqlClientDriver”)
.proxyFactory(“NHibernate.ByteCode.Castle.proxyFactory,NHibernate.ByteCode.Castle”)
.UseOuterJoin()
.ConnectionString(@“服务器=。\SQLEXPRESS;用户Id=xxcxcca;密码=Password;数据库=cccvddd;”)
.ShowSql()
.CurrentSessionContext(“thread\u static”)//为WEB更改此选项
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.曝光配置(
cfg=>{
cfg.SetProperty(
环境。交易策略,
typeof(AdoNetTransactionFactory).FullName);
cfg.SetProperty(Environment.GenerateStatistics,“true”);//为LIVE删除
})
.BuildSessionFactory())
.WithName(“MySessionFactory”);

以下是我是如何做到的。不知道这是否是最好的方法,但它是有效的

  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"));
ForRequestedType()
.CacheBy(InstanceScope.Singleton)
.TheDefault.Is.ConstructedBy(
()=>流利。配置()
.数据库(MsSqlConfiguration.MsSql2005
.ADONbatchSize(10)
.Driver(“NHibernate.Driver.SqlClientDriver”)
.proxyFactory(“NHibernate.ByteCode.Castle.proxyFactory,NHibernate.ByteCode.Castle”)
.UseOuterJoin()
.ConnectionString(@“服务器=。\SQLEXPRESS;用户Id=epitka;密码=Password;数据库=dnn49;”)
.ShowSql()
.CurrentSessionContext(“thread\u static”)//为WEB更改此选项
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.曝光配置(
cfg=>{
cfg.SetProperty(
环境。交易策略,
typeof(AdoNetTransactionFactory).FullName);
cfg.SetProperty(Environment.GenerateStatistics,“true”);//为LIVE删除
})
)
.带名称(“SharMod_FluentConfiguration”);
ForRequestedType()
.TheDefault.Is.ConstructedBy(
() =>
{
var fc=ObjectFactory.GetInstance();
返回fc.BuildConfiguration();
})
.带有名称(“SharpMod_配置”);
//SharpMod_会话工厂
ForRequestedType()
.CacheBy(InstanceScope.Singleton)
.AddInstances(x=>x.ConstructedBy(()=>
ObjectFactory.GetNamedInstance(“SharMod\u FluentConfiguration”)
.BuildSessionFactory())
.名称为(“SharpMod_SessionFactory”);