NHibernate 需要代理工厂吗? [英] Is Proxy Factory necessary in NHibernate?

查看:28
本文介绍了NHibernate 需要代理工厂吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've this configuration in the 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 创建了一个集成测试.它失败.报告的一部分(我认为就足够了)放在这里:

I've just created a Class Library and I've created an integration test using MbUnit. It fails. A part of the report(the one which I think is enough) goes here:

** 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.

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

I have read many tutorials and haven't seen this proxy factory configuration. Is specifying it really necessary? If so, how can I do that? Do I've to reference some other library?

推荐答案

如果您使用的是最新的 NHibernate(2.1),您会注意到 NH 的主线不依赖于城堡来生成代理不再,所以你一直在看的所有教程可能都过时了.

If you're using the latest of NHibernate(2.1), you'll notice that mainline for NH doesn't have a dependency on castle for proxy generation anymore, so all those tutorials you've been looking at are probably out of date.

基本上,您现在可以选择如何创建动态代理,因此您需要明确配置要使用的代理生成器.示例可以在此 how 中找到- 在伪造上发帖.此处引用了完整的选项列表.

Basically, you now have a few choices of how you want your dynamic proxies created, so you'll need to explicitly configure which proxy generator you want to use. Examples can be found in this how-to post on forge. A full list of the options is referenced here.

附言如果您想保持简单,只需使用 Castle 作为旧版本的 NHibernate默认情况下.

P.S. if you want to keep things simple, just use Castle as the older versions of NHibernate all used it by default.

这篇关于NHibernate 需要代理工厂吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆