使用 Nhibernate 工具配置 Castle Windsor 容器和 Nhibernate
我正在尝试使用 Nhibernate 设施通过 Castle Windsor Container 配置 Nhibernate。但我有
这是我的 web.config
<castle>
<facilities>
<facility id="nhibernate"
type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration"
isWeb="true">
<factory id="nhibernate.factory">
<settings>
<item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item>
<item key="connection.driver_class">NHibernate.Driver.SqlClientDriver</item>
<item key="connection.connection_string">Data Source=184.106.114.146\calyx;Initial Catalog=ClaimBook;User ID=system;Password=Manager1!;Persist Security Info=True;Max Pool Size=120;Connection Lifetime=120;</item>
<item key="dialect">NHibernate.Dialect.MsSql2000Dialect</item>
<item key="show_sql">true</item>
<item key="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</item>
</settings>
<resources>
<resource assembly="Astute.Framework.Data" />
</resources>
</factory>
</facility>
</facilities>
</castle>
并在我的 global.asax 中添加到以下行
container.Kernel.Register(Component.For<ISessionManager>().ImplementedBy<DefaultSessionManager>().Named("nhfacility.sessionmanager"));
container.Kernel.Register(Component.For<ISessionFactoryResolver>().ImplementedBy<SessionFactoryResolver>().Named("nhfacility.sessionfactory.resolver"));
container.Kernel.Register(Component.For<ISessionStore>().ImplementedBy<WebSessionStore>().Named("nhfacility.sessionstore"));
container.Kernel.Register(Component.For<ITransactionManager>().ImplementedBy<DefaultTransactionManager>().Named("nhibernate.transaction.manager"));
但我收到以下错误
*ISessionFactory 组件未映射到指定的别名:nh.facility .default 堆栈跟踪: [FacilityException:未为指定别名映射 ISessionFactory 组件:nh.facility.default] Castle.Facilities.NHibernateIntegration.Internal.SessionFactoryResolver.GetSessionFactory(字符串别名)+147 Castle.Facilities.NHibernateIntegration.DefaultSessionManager.CreateSession(字符串别名)+65 Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession(字符串别名)+150 Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession() +37 Castle.Facilities.NHibernateIntegration.Components.Web.SessionWebModule.OnBeginRequest(对象发送者,EventArgs e)+124 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& CompletedSynchronously) +75*
我不知道配置中缺少什么。有什么想法吗?
谢谢伊姆兰
I'm trying to configure Nhibernate with Castle Windsor Container using Nhibernate Facility. But i'm having
Here is my web.config
<castle>
<facilities>
<facility id="nhibernate"
type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration"
isWeb="true">
<factory id="nhibernate.factory">
<settings>
<item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item>
<item key="connection.driver_class">NHibernate.Driver.SqlClientDriver</item>
<item key="connection.connection_string">Data Source=184.106.114.146\calyx;Initial Catalog=ClaimBook;User ID=system;Password=Manager1!;Persist Security Info=True;Max Pool Size=120;Connection Lifetime=120;</item>
<item key="dialect">NHibernate.Dialect.MsSql2000Dialect</item>
<item key="show_sql">true</item>
<item key="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</item>
</settings>
<resources>
<resource assembly="Astute.Framework.Data" />
</resources>
</factory>
</facility>
</facilities>
</castle>
and in my global.asax I added to following lines
container.Kernel.Register(Component.For<ISessionManager>().ImplementedBy<DefaultSessionManager>().Named("nhfacility.sessionmanager"));
container.Kernel.Register(Component.For<ISessionFactoryResolver>().ImplementedBy<SessionFactoryResolver>().Named("nhfacility.sessionfactory.resolver"));
container.Kernel.Register(Component.For<ISessionStore>().ImplementedBy<WebSessionStore>().Named("nhfacility.sessionstore"));
container.Kernel.Register(Component.For<ITransactionManager>().ImplementedBy<DefaultTransactionManager>().Named("nhibernate.transaction.manager"));
But i'm getting following error
*An ISessionFactory component was not mapped for the specified alias: nh.facility.default
Stack Trace:
[FacilityException: An ISessionFactory component was not mapped for the specified alias: nh.facility.default]
Castle.Facilities.NHibernateIntegration.Internal.SessionFactoryResolver.GetSessionFactory(String alias) +147
Castle.Facilities.NHibernateIntegration.DefaultSessionManager.CreateSession(String alias) +65
Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession(String alias) +150
Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession() +37
Castle.Facilities.NHibernateIntegration.Components.Web.SessionWebModule.OnBeginRequest(Object sender, EventArgs e) +124
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75*
I don't know what i'm missing in configuration. Any thoughts?
Thanks
Imran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ISessionManager
、ISessionFactoryResolver
等是由 NHibernate 工具管理的组件。您不应该手动注册它们。您可以通过执行以下操作从该 web.config 安装该工具:
有关详细信息,请参阅 参考文档关于配置安装程序。
ISessionManager
,ISessionFactoryResolver
, etc are components managed by the NHibernate facility. You're not supposed to register them manually.You can install the facility from that web.config by doing:
For more information, see the reference docs about Configuration installers.