【问题标题】:Is Proxy Factory necessary in NHibernate?NHibernate 中是否需要代理工厂?
【发布时间】:2009-07-11 02:34:22
【问题描述】:

我在 hibernate.cfg.xml 中有这个配置:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=SSPI;</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

我刚刚创建了一个类库,并使用 MbUnit 创建了一个集成测试。它失败。报告的一部分(我认为就足够了)在这里:

** NO TESTS WERE RUN (No tests found) **
TestCase 'M:IntegrationTests.RepositoryTests.ListAllPostsReturnsAListOfPost'
failed: The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.

我看了很多教程,还没有看到这个代理工厂配置。指定它真的有必要吗?如果是这样,我该怎么做?我必须参考其他图书馆吗?

【问题讨论】:

    标签: nhibernate nhibernate-configuration


    【解决方案1】:

    如果您使用的是最新的 NHibernate(2.1),您会注意到 mainline for NH doesn't have a dependency on castle 不再用于代理生成,因此您一直在查看的所有教程可能已经过时了。

    基本上,您现在可以选择如何创建动态代理,因此您需要明确配置要使用的代理生成器。示例可以在此how-to post on forge 中找到。完整的选项列表参考here

    附:如果你想让事情变得简单,只需使用Castle,因为旧版本的 NHibernate 都默认使用它。

    【讨论】:

    • 根据this answer,你甚至不需要再配置代理了。
    猜你喜欢
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 2016-09-06
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多