Rhino.Commons + 流畅的NHibernate
有没有办法将 Rhino.Commons 与 Fluent Nhibernate 一起使用(特别是 AutoMapping)?
非常感
谢弗拉诺
Is there a way to use Rhino.Commons with Fluent Nhibernate, (in particular AutoMapping)?
Many thanks
fromano
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
# # # # # # # # # #
更新:
该答案是在 2009 年 2 月写的。按照 FluentNHibernate 项目变化的速度,该方法很可能已被重命名,或者更改约定的机制已被移动。
# # # # # # # # # #
我想使用来自 Rhino.Commons.ForTesting 的 DatabaseTextFixtureBase 和 FluentNHibernate。 我一直遇到的问题是 FluentNHibernate 将它的魔力添加到 PersistenceModel 类中的 NHibernate 配置中,并且一旦您调用 DatabaseTestFixtureBase.InitializeNHibernateAndIoC() Rhino.Commons 私下就可以掌握 NHibernate 配置。并且您不再有权访问 NHibernate 配置。
事实证明,我最后的假设是错误的。 如果您向容器注册 INHibernateInitializationAware 服务,则 NHibernateUnitOfWorkTestContext 在调用 CreatConfigs() 时将拾取该服务。
我正在使用的 INHibernateInitializationAware 实现如下所示:
当然,约定可以替换为您碰巧使用的任何约定。
享受!
如果您使用最新版本的 FluentNHibernate,您可能会使用 Fluently 类来配置映射。 这是 FluentNHibernateInitializationAwareConfigurator 的另一个版本:
# # # # # # # # # #
UPDATE:
That answer was written in Feb of 2009. With the rate that the FluentNHibernate project was changing, it's very likely that the method has been renamed, or the mechanism for changing Conventions has been moved.
# # # # # # # # # #
I wanted to use DatabaseTextFixtureBase from Rhino.Commons.ForTesting with FluentNHibernate. The problem that I kept coming up against was the fact that FluentNHibernate adds it's magic to the NHibernate configuration in the PersistenceModel class, and getting your hands on the NHibernate configuration once you call DatabaseTestFixtureBase.InitializeNHibernateAndIoC() Rhino.Commons does a bunch of stuff privately and you no longer have access to the NHibernate config.
As it turns out, my last assumption was wrong. If you register an INHibernateInitializationAware service with the container, it will be picked up by the NHibernateUnitOfWorkTestContext when it calls CreatConfigs().
The INHibernateInitializationAware implementation that I am using looks like this:
Of course the Conventions can be replaced by any that you happen to be using.
Enjoy!
If you are using the latest version of FluentNHibernate you may be using the Fluently class to configure your mappings. Here's another version of the FluentNHibernateInitializationAwareConfigurator: